anchela commented on code in PR #2868:
URL: https://github.com/apache/jackrabbit-oak/pull/2868#discussion_r3115723391


##########
oak-jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java:
##########
@@ -213,6 +213,34 @@ User createUser(@NotNull String userID, @Nullable String 
password, @NotNull Prin
                     @Nullable String intermediatePath) throws 
AuthorizableExistsException, RepositoryException;
 
 
+    /**
+     * Creates a user for the given parameters at the specified absolute Oak 
path.
+     * Unlike {@link #createUser(String, String, Principal, String)} where the
+     * {@code intermediatePath} is a relative hint, this method accepts an 
absolute
+     * repository path that precisely determines the location of the new user 
node.
+     * <p>
+     * Implementations that do not support placement at an arbitrary absolute 
path
+     * should throw {@link UnsupportedRepositoryOperationException}.
+     *
+     * @param userID         The ID of the new user.
+     * @param password       The initial password of the new user, may be 
{@code null}.
+     * @param principal      The principal of the new user.
+     * @param absoluteOakPath The absolute Oak repository path at which the 
user node
+     *                        must be created. Must not be {@code null}.
+     * @return The new {@code User}.
+     * @throws AuthorizableExistsException              if an authorizable 
with the given
+     *                                                  userID or principal 
already exists.
+     * @throws UnsupportedRepositoryOperationException  if the implementation 
does not
+     *                                                  support creation at an 
absolute path.
+     * @throws RepositoryException                      If another error 
occurs.
+     */
+    @NotNull
+    default User createUserWithAbsolutePath(@NotNull String userID, @Nullable 
String password,
+                                            @NotNull Principal principal, 
@NotNull String absoluteOakPath)
+            throws AuthorizableExistsException, 
UnsupportedRepositoryOperationException, RepositoryException {

Review Comment:
   this should be an absolute JCR path that is then converted to an oak path 
(there are utilities for that). the reason: user management API is on the same 
level and an extension to JCR API. oak API is one layer below.
   see JCR specification for the namespace remapping and the various 
representations of a JCR path. while i doubt that namespace remappings and the 
different variants of paths are widely use, it's still important to be aware of 
the distictions to keep the API contract consistent.
   
   paramName: absolutePath... not mentioning oak



##########
oak-jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java:
##########
@@ -305,6 +333,36 @@ User createUser(@NotNull String userID, @Nullable String 
password, @NotNull Prin
     @NotNull
     Group createGroup(@NotNull String groupID, @NotNull Principal principal, 
@Nullable String intermediatePath) throws AuthorizableExistsException, 
RepositoryException;
 
+    /**
+     * Creates a new {@code Group} at the specified absolute Oak repository 
path.
+     * <p>
+     * Unlike {@link #createGroup(String, Principal, String)} where the
+     * {@code intermediatePath} is a relative hint that implementations may 
ignore,
+     * this method requires the caller to supply the exact absolute path at 
which
+     * the group node must be created. The path must start with {@code /} and 
must
+     * not already exist.
+     * <p>
+     * Implementations that cannot honour an arbitrary absolute path must throw
+     * {@link UnsupportedRepositoryOperationException}.
+     *
+     * @param groupID   The ID of the new group.
+     * @param principal The principal of the new group.
+     * @param oakPath   The absolute Oak repository path at which the group 
node
+     *                  must be created. Must not be {@code null}.
+     * @return The new {@code Group}.
+     * @throws AuthorizableExistsException             if an authorizable with 
the given
+     *                                                 groupID or principal 
already exists.
+     * @throws UnsupportedRepositoryOperationException if the implementation 
does not
+     *                                                 support creation at an 
absolute path.
+     * @throws RepositoryException                     If another error occurs.
+     */
+    @NotNull
+    default Group createGroupWithAbsolutePath(@NotNull String groupID, 
@NotNull Principal principal,
+                                              @NotNull String oakPath)
+            throws AuthorizableExistsException, 
UnsupportedRepositoryOperationException, RepositoryException {
+        throw new 
UnsupportedRepositoryOperationException("createGroupWithAbsolutePath is not 
supported by this implementation");

Review Comment:
   see above. ideally we have a default implementation
   



##########
oak-jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java:
##########
@@ -213,6 +213,34 @@ User createUser(@NotNull String userID, @Nullable String 
password, @NotNull Prin
                     @Nullable String intermediatePath) throws 
AuthorizableExistsException, RepositoryException;
 
 
+    /**
+     * Creates a user for the given parameters at the specified absolute Oak 
path.
+     * Unlike {@link #createUser(String, String, Principal, String)} where the
+     * {@code intermediatePath} is a relative hint, this method accepts an 
absolute
+     * repository path that precisely determines the location of the new user 
node.
+     * <p>
+     * Implementations that do not support placement at an arbitrary absolute 
path
+     * should throw {@link UnsupportedRepositoryOperationException}.
+     *
+     * @param userID         The ID of the new user.
+     * @param password       The initial password of the new user, may be 
{@code null}.
+     * @param principal      The principal of the new user.
+     * @param absoluteOakPath The absolute Oak repository path at which the 
user node
+     *                        must be created. Must not be {@code null}.
+     * @return The new {@code User}.
+     * @throws AuthorizableExistsException              if an authorizable 
with the given
+     *                                                  userID or principal 
already exists.
+     * @throws UnsupportedRepositoryOperationException  if the implementation 
does not
+     *                                                  support creation at an 
absolute path.
+     * @throws RepositoryException                      If another error 
occurs.
+     */
+    @NotNull
+    default User createUserWithAbsolutePath(@NotNull String userID, @Nullable 
String password,
+                                            @NotNull Principal principal, 
@NotNull String absoluteOakPath)
+            throws AuthorizableExistsException, 
UnsupportedRepositoryOperationException, RepositoryException {
+        throw new 
UnsupportedRepositoryOperationException("createUserWithAbsolutePath is not 
supported by this implementation");

Review Comment:
   ideally we would have a default implementation that avoids having to touch 
the old jackrabbit code.



##########
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java:
##########
@@ -168,6 +168,21 @@ public User perform() throws RepositoryException {
         });
     }
 
+    @NotNull
+    @Override
+    public User createUserWithAbsolutePath(@NotNull final String userID, 
@Nullable final String password,
+                                           @NotNull final Principal principal, 
@NotNull final String absoluteOakPath)

Review Comment:
   rename param here as well



##########
oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java:
##########
@@ -251,6 +251,45 @@ public Group createGroup(@NotNull String groupID, @NotNull 
Principal principal,
         return group;
     }
 
+    @NotNull
+    @Override
+    public User createUserWithAbsolutePath(@NotNull String userID, @Nullable 
String password,
+                                           @NotNull Principal principal, 
@NotNull String oakPath)
+            throws AuthorizableExistsException, 
UnsupportedRepositoryOperationException, RepositoryException {
+        checkValidId(userID);
+        checkValidPrincipal(principal, false);
+
+        Tree userTree = userProvider.createUser(userID, oakPath);
+        setPrincipal(userTree, principal);
+        if (password != null) {
+            setPassword(userTree, userID, password, false);
+        }
+
+        User user = new UserImpl(userID, userTree, this);
+        onCreate(user, password);
+
+        log.debug("User created: {}", userID);
+        return user;
+    }
+
+    @NotNull
+    @Override
+    public Group createGroupWithAbsolutePath(@NotNull String groupID, @NotNull 
Principal principal,
+                                             @NotNull String oakPath)
+            throws AuthorizableExistsException, 
UnsupportedRepositoryOperationException, RepositoryException {
+        checkValidId(groupID);
+        checkValidPrincipal(principal, true);
+
+        Tree groupTree = userProvider.createGroup(groupID, oakPath);

Review Comment:
   before calling createGroup the path needs to be converted from jcr path to 
oak path



##########
oak-jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java:
##########
@@ -305,6 +333,36 @@ User createUser(@NotNull String userID, @Nullable String 
password, @NotNull Prin
     @NotNull
     Group createGroup(@NotNull String groupID, @NotNull Principal principal, 
@Nullable String intermediatePath) throws AuthorizableExistsException, 
RepositoryException;
 
+    /**
+     * Creates a new {@code Group} at the specified absolute Oak repository 
path.
+     * <p>
+     * Unlike {@link #createGroup(String, Principal, String)} where the
+     * {@code intermediatePath} is a relative hint that implementations may 
ignore,
+     * this method requires the caller to supply the exact absolute path at 
which
+     * the group node must be created. The path must start with {@code /} and 
must
+     * not already exist.
+     * <p>
+     * Implementations that cannot honour an arbitrary absolute path must throw
+     * {@link UnsupportedRepositoryOperationException}.
+     *
+     * @param groupID   The ID of the new group.
+     * @param principal The principal of the new group.
+     * @param oakPath   The absolute Oak repository path at which the group 
node
+     *                  must be created. Must not be {@code null}.
+     * @return The new {@code Group}.
+     * @throws AuthorizableExistsException             if an authorizable with 
the given
+     *                                                 groupID or principal 
already exists.
+     * @throws UnsupportedRepositoryOperationException if the implementation 
does not
+     *                                                 support creation at an 
absolute path.
+     * @throws RepositoryException                     If another error occurs.
+     */
+    @NotNull
+    default Group createGroupWithAbsolutePath(@NotNull String groupID, 
@NotNull Principal principal,
+                                              @NotNull String oakPath)

Review Comment:
   see above it should be 'absolutePath' and the description should make it 
clear that this is a JCR path not an oak path.
   naming should be consistent with the user method.



##########
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java:
##########
@@ -233,6 +248,21 @@ public Group perform() throws RepositoryException {
         });
     }
 
+    @NotNull
+    @Override
+    public Group createGroupWithAbsolutePath(@NotNull final String groupID, 
@NotNull final Principal principal,
+                                             @NotNull final String oakPath)

Review Comment:
   rename param here as well



##########
oak-jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/UserManager.java:
##########
@@ -305,6 +333,36 @@ User createUser(@NotNull String userID, @Nullable String 
password, @NotNull Prin
     @NotNull
     Group createGroup(@NotNull String groupID, @NotNull Principal principal, 
@Nullable String intermediatePath) throws AuthorizableExistsException, 
RepositoryException;
 
+    /**
+     * Creates a new {@code Group} at the specified absolute Oak repository 
path.

Review Comment:
   the javadoc should describe what happens in the following cases:
   - the path collides with an existing node
   - the last segment (name) violates the contract of the configured 
authorizableNodeName
   



##########
oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserManagerImpl.java:
##########
@@ -251,6 +251,45 @@ public Group createGroup(@NotNull String groupID, @NotNull 
Principal principal,
         return group;
     }
 
+    @NotNull
+    @Override
+    public User createUserWithAbsolutePath(@NotNull String userID, @Nullable 
String password,
+                                           @NotNull Principal principal, 
@NotNull String oakPath)
+            throws AuthorizableExistsException, 
UnsupportedRepositoryOperationException, RepositoryException {
+        checkValidId(userID);
+        checkValidPrincipal(principal, false);
+
+        Tree userTree = userProvider.createUser(userID, oakPath);

Review Comment:
   before this call the jcr path needs to be converted to an oak path



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to