This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.jcr.jackrabbit.usermanager-2.2.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-jackrabbit-usermanager.git
commit a8e4735fdaa9c6786239951100481aca76ddfe20 Author: Justin Edelson <jus...@apache.org> AuthorDate: Thu Nov 10 21:21:44 2011 +0000 tabs -> spaces git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/jackrabbit-usermanager@1200559 13f79535-47bb-0310-9956-ffa450edef68 --- .../usermanager/AuthorizablePrivilegesInfo.java | 96 +++--- .../jackrabbit/usermanager/ChangeUserPassword.java | 38 +- .../sling/jackrabbit/usermanager/CreateGroup.java | 28 +- .../sling/jackrabbit/usermanager/CreateUser.java | 38 +- .../usermanager/DeleteAuthorizables.java | 28 +- .../sling/jackrabbit/usermanager/DeleteGroup.java | 24 +- .../sling/jackrabbit/usermanager/DeleteUser.java | 24 +- .../sling/jackrabbit/usermanager/UpdateGroup.java | 30 +- .../sling/jackrabbit/usermanager/UpdateUser.java | 28 +- .../impl/AuthorizablePrivilegesInfoImpl.java | 384 ++++++++++----------- .../impl/post/AbstractAuthorizablePostServlet.java | 362 +++++++++---------- .../impl/post/AbstractGroupPostServlet.java | 42 +-- .../usermanager/impl/post/AbstractPostServlet.java | 14 +- .../impl/post/ChangeUserPasswordServlet.java | 74 ++-- .../usermanager/impl/post/CreateGroupServlet.java | 38 +- .../usermanager/impl/post/CreateUserServlet.java | 84 ++--- .../impl/post/DeleteAuthorizableServlet.java | 96 +++--- .../usermanager/impl/post/UpdateGroupServlet.java | 44 +-- .../usermanager/impl/post/UpdateUserServlet.java | 44 +-- 19 files changed, 758 insertions(+), 758 deletions(-) diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/AuthorizablePrivilegesInfo.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/AuthorizablePrivilegesInfo.java index 39a0af3..c500dd8 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/AuthorizablePrivilegesInfo.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/AuthorizablePrivilegesInfo.java @@ -20,55 +20,55 @@ import javax.jcr.Session; public interface AuthorizablePrivilegesInfo { - /** - * Checks whether the current user has been granted privileges - * to add a new user. - * - * @param jcrSession the JCR session of the current user - * @return true if the current user has the privileges, false otherwise - */ - boolean canAddUser(Session jcrSession); + /** + * Checks whether the current user has been granted privileges + * to add a new user. + * + * @param jcrSession the JCR session of the current user + * @return true if the current user has the privileges, false otherwise + */ + boolean canAddUser(Session jcrSession); - /** - * Checks whether the current user has been granted privileges - * to add a new group. - * - * @param jcrSession the JCR session of the current user - * @return true if the current user has the privileges, false otherwise - */ - boolean canAddGroup(Session jcrSession); - - /** - * Checks whether the current user has been granted privileges - * to update the properties of the specified user or group. - * - * @param jcrSession the JCR session of the current user - * @param principalId the user or group id to check - * @return true if the current user has the privileges, false otherwise - */ - boolean canUpdateProperties(Session jcrSession, - String principalId); + /** + * Checks whether the current user has been granted privileges + * to add a new group. + * + * @param jcrSession the JCR session of the current user + * @return true if the current user has the privileges, false otherwise + */ + boolean canAddGroup(Session jcrSession); + + /** + * Checks whether the current user has been granted privileges + * to update the properties of the specified user or group. + * + * @param jcrSession the JCR session of the current user + * @param principalId the user or group id to check + * @return true if the current user has the privileges, false otherwise + */ + boolean canUpdateProperties(Session jcrSession, + String principalId); - /** - * Checks whether the current user has been granted privileges - * to remove the specified user or group. - * - * @param jcrSession the JCR session of the current user - * @param principalId the user or group id to check - * @return true if the current user has the privileges, false otherwise - */ - boolean canRemove(Session jcrSession, - String principalId); - - /** - * Checks whether the current user has been granted privileges - * to update the membership of the specified group. - * - * @param jcrSession the JCR session of the current user - * @param groupId the group id to check - * @return true if the current user has the privileges, false otherwise - */ - boolean canUpdateGroupMembers(Session jcrSession, - String groupId); + /** + * Checks whether the current user has been granted privileges + * to remove the specified user or group. + * + * @param jcrSession the JCR session of the current user + * @param principalId the user or group id to check + * @return true if the current user has the privileges, false otherwise + */ + boolean canRemove(Session jcrSession, + String principalId); + + /** + * Checks whether the current user has been granted privileges + * to update the membership of the specified group. + * + * @param jcrSession the JCR session of the current user + * @param groupId the group id to check + * @return true if the current user has the privileges, false otherwise + */ + boolean canUpdateGroupMembers(Session jcrSession, + String groupId); } \ No newline at end of file diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/ChangeUserPassword.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/ChangeUserPassword.java index d98f676..16d1513 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/ChangeUserPassword.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/ChangeUserPassword.java @@ -35,24 +35,24 @@ import org.apache.sling.servlets.post.Modification; */ public interface ChangeUserPassword { - /** - * Update the password of a user in the repository - * - * @param jcrSession the JCR session of the user updating the user - * @param name The name of the user to update (required) - * @param oldPassword The current password of the user (required for non-admin users) - * @param newPassword The password value to apply (required) - * @param newPasswordConfirm The password value to apply again (required) + /** + * Update the password of a user in the repository + * + * @param jcrSession the JCR session of the user updating the user + * @param name The name of the user to update (required) + * @param oldPassword The current password of the user (required for non-admin users) + * @param newPassword The password value to apply (required) + * @param newPasswordConfirm The password value to apply again (required) * @param changes The list of changes for this operation (optional) - * @return the user whose password was changed - * @throws RepositoryException - */ - public User changePassword(Session jcrSession, - String name, - String oldPassword, - String newPassword, - String newPasswordConfirm, - List<Modification> changes - ) throws RepositoryException; - + * @return the user whose password was changed + * @throws RepositoryException + */ + public User changePassword(Session jcrSession, + String name, + String oldPassword, + String newPassword, + String newPasswordConfirm, + List<Modification> changes + ) throws RepositoryException; + } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/CreateGroup.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/CreateGroup.java index 934e502..56ddf46 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/CreateGroup.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/CreateGroup.java @@ -36,20 +36,20 @@ import org.apache.sling.servlets.post.Modification; */ public interface CreateGroup { - /** - * Create a new group for the repository - * - * @param jcrSession the JCR session of the user creating the group - * @param name The name of the new group (required) - * @param properties Extra properties to update on the group. The entry values should be either a String or String[] (optional) + /** + * Create a new group for the repository + * + * @param jcrSession the JCR session of the user creating the group + * @param name The name of the new group (required) + * @param properties Extra properties to update on the group. The entry values should be either a String or String[] (optional) * @param changes The list of changes for this operation (optional) * @return the group that was created - * @throws RepositoryException - */ - public Group createGroup(Session jcrSession, - String name, - Map<String, ?> properties, - List<Modification> changes - ) throws RepositoryException; - + * @throws RepositoryException + */ + public Group createGroup(Session jcrSession, + String name, + Map<String, ?> properties, + List<Modification> changes + ) throws RepositoryException; + } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/CreateUser.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/CreateUser.java index 51c7b02..a0de69a 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/CreateUser.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/CreateUser.java @@ -36,24 +36,24 @@ import org.apache.sling.servlets.post.Modification; */ public interface CreateUser { - /** - * Create a new user for the repository - * - * @param jcrSession the JCR session of the user creating the user - * @param name The name of the new user (required) - * @param password The password of the new user (required) - * @param password The password of the new user again (required) - * @param properties Extra properties to update on the user. The entry values should be either a String or String[] (optional) + /** + * Create a new user for the repository + * + * @param jcrSession the JCR session of the user creating the user + * @param name The name of the new user (required) + * @param password The password of the new user (required) + * @param password The password of the new user again (required) + * @param properties Extra properties to update on the user. The entry values should be either a String or String[] (optional) * @param changes The list of changes for this operation (optional) - * @return the user that was created - * @throws RepositoryException - */ - public User createUser(Session jcrSession, - String name, - String password, - String passwordConfirm, - Map<String, ?> properties, - List<Modification> changes - ) throws RepositoryException; - + * @return the user that was created + * @throws RepositoryException + */ + public User createUser(Session jcrSession, + String name, + String password, + String passwordConfirm, + Map<String, ?> properties, + List<Modification> changes + ) throws RepositoryException; + } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteAuthorizables.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteAuthorizables.java index 98f93bf..d6f3e0c 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteAuthorizables.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteAuthorizables.java @@ -35,19 +35,19 @@ import org.apache.sling.servlets.post.Modification; */ public interface DeleteAuthorizables { - /** - * Deletes one or more users or groups from the repository - * - * @param jcrSession the JCR session of the user creating the user - * @param baseResource the base resource to calculate the relative paths from (required) - * @param paths An array of relative resource paths to Authorizables to be deleted (required) + /** + * Deletes one or more users or groups from the repository + * + * @param jcrSession the JCR session of the user creating the user + * @param baseResource the base resource to calculate the relative paths from (required) + * @param paths An array of relative resource paths to Authorizables to be deleted (required) * @param changes The list of changes for this operation (optional) - * @throws RepositoryException - */ - public void deleteAuthorizables(Session jcrSession, - Resource baseResource, - String [] paths, - List<Modification> changes - ) throws RepositoryException; - + * @throws RepositoryException + */ + public void deleteAuthorizables(Session jcrSession, + Resource baseResource, + String [] paths, + List<Modification> changes + ) throws RepositoryException; + } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteGroup.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteGroup.java index 3c9f9b1..be3b30a 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteGroup.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteGroup.java @@ -34,17 +34,17 @@ import org.apache.sling.servlets.post.Modification; */ public interface DeleteGroup { - /** - * Deletes a group from the repository - * - * @param jcrSession the JCR session of the user creating the user - * @param name The name of the group to delete (required) + /** + * Deletes a group from the repository + * + * @param jcrSession the JCR session of the user creating the user + * @param name The name of the group to delete (required) * @param changes The list of changes for this operation (optional) - * @throws RepositoryException - */ - public void deleteGroup(Session jcrSession, - String name, - List<Modification> changes - ) throws RepositoryException; - + * @throws RepositoryException + */ + public void deleteGroup(Session jcrSession, + String name, + List<Modification> changes + ) throws RepositoryException; + } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteUser.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteUser.java index 506ae79..177c64f 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteUser.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/DeleteUser.java @@ -34,17 +34,17 @@ import org.apache.sling.servlets.post.Modification; */ public interface DeleteUser { - /** - * Deletes a user from the repository - * - * @param jcrSession the JCR session of the user creating the user - * @param name The name of the user to delete (required) + /** + * Deletes a user from the repository + * + * @param jcrSession the JCR session of the user creating the user + * @param name The name of the user to delete (required) * @param changes The list of changes for this operation (optional) - * @throws RepositoryException - */ - public void deleteUser(Session jcrSession, - String name, - List<Modification> changes - ) throws RepositoryException; - + * @throws RepositoryException + */ + public void deleteUser(Session jcrSession, + String name, + List<Modification> changes + ) throws RepositoryException; + } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/UpdateGroup.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/UpdateGroup.java index 64bdacd..ccc019c 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/UpdateGroup.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/UpdateGroup.java @@ -36,20 +36,20 @@ import org.apache.sling.servlets.post.Modification; */ public interface UpdateGroup { - /** - * Update a group in the repository - * - * @param jcrSession the JCR session of the user creating the group - * @param name The name of the group to update (required) - * @param properties Extra properties to update on the group. The entry values should be either a String or String[] (optional) + /** + * Update a group in the repository + * + * @param jcrSession the JCR session of the user creating the group + * @param name The name of the group to update (required) + * @param properties Extra properties to update on the group. The entry values should be either a String or String[] (optional) * @param changes The list of changes for this operation (optional) - * @return the group that was updated or null if not found - * @throws RepositoryException - */ - public Group updateGroup(Session jcrSession, - String name, - Map<String, ?> properties, - List<Modification> changes - ) throws RepositoryException; - + * @return the group that was updated or null if not found + * @throws RepositoryException + */ + public Group updateGroup(Session jcrSession, + String name, + Map<String, ?> properties, + List<Modification> changes + ) throws RepositoryException; + } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/UpdateUser.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/UpdateUser.java index aac6a0a..5b19f89 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/UpdateUser.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/UpdateUser.java @@ -36,20 +36,20 @@ import org.apache.sling.servlets.post.Modification; */ public interface UpdateUser { - /** - * Update a user in the repository - * - * @param jcrSession the JCR session of the user updating the user - * @param name The name of the user to update (required) - * @param properties Extra properties to update on the user. The entry values should be either a String or String[] (optional) + /** + * Update a user in the repository + * + * @param jcrSession the JCR session of the user updating the user + * @param name The name of the user to update (required) + * @param properties Extra properties to update on the user. The entry values should be either a String or String[] (optional) * @param changes The list of changes for this operation (optional) * @return the user that was updated or null if not found - * @throws RepositoryException - */ - public User updateUser(Session jcrSession, - String name, - Map<String, ?> properties, - List<Modification> changes - ) throws RepositoryException; - + * @throws RepositoryException + */ + public User updateUser(Session jcrSession, + String name, + Map<String, ?> properties, + List<Modification> changes + ) throws RepositoryException; + } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/AuthorizablePrivilegesInfoImpl.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/AuthorizablePrivilegesInfoImpl.java index f3fc51a..435563c 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/AuthorizablePrivilegesInfoImpl.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/AuthorizablePrivilegesInfoImpl.java @@ -106,207 +106,207 @@ public class AuthorizablePrivilegesInfoImpl implements AuthorizablePrivilegesInf private String groupAdminGroupName = DEFAULT_GROUP_ADMIN_GROUP_NAME; - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canAddGroup(javax.jcr.Session) - */ - public boolean canAddGroup(Session jcrSession) { - try { - UserManager userManager = AccessControlUtil.getUserManager(jcrSession); - Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canAddGroup(javax.jcr.Session) + */ + public boolean canAddGroup(Session jcrSession) { + try { + UserManager userManager = AccessControlUtil.getUserManager(jcrSession); + Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); - if (currentUser != null) { - if (((User)currentUser).isAdmin()) { - return true; //admin user has full control - } - - //check if the user is a member of the 'Group administrator' group - Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName); - if (groupAdmin instanceof Group) { - boolean isMember = ((Group)groupAdmin).isMember(currentUser); - if (isMember) { - return true; - } - } - } - } catch (RepositoryException e) { - log.warn("Failed to determine if {} can add a new group", jcrSession.getUserID()); - } - return false; - } + if (currentUser != null) { + if (((User)currentUser).isAdmin()) { + return true; //admin user has full control + } + + //check if the user is a member of the 'Group administrator' group + Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName); + if (groupAdmin instanceof Group) { + boolean isMember = ((Group)groupAdmin).isMember(currentUser); + if (isMember) { + return true; + } + } + } + } catch (RepositoryException e) { + log.warn("Failed to determine if {} can add a new group", jcrSession.getUserID()); + } + return false; + } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canAddUser(javax.jcr.Session) - */ - public boolean canAddUser(Session jcrSession) { - try { - //if self-registration is enabled, then anyone can create a user - if (componentContext != null) { - String filter = "(&(sling.servlet.resourceTypes=sling/users)(|(sling.servlet.methods=POST)(sling.servlet.selectors=create)))"; - BundleContext bundleContext = componentContext.getBundleContext(); - ServiceReference[] serviceReferences = bundleContext.getServiceReferences(Servlet.class.getName(), filter); - if (serviceReferences != null) { - String propName = "self.registration.enabled"; - for (ServiceReference serviceReference : serviceReferences) { - Object propValue = serviceReference.getProperty(propName); - if (propValue != null) { - boolean selfRegEnabled = Boolean.TRUE.equals(propValue); - if (selfRegEnabled) { - return true; - } - break; - } - } - } - } + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canAddUser(javax.jcr.Session) + */ + public boolean canAddUser(Session jcrSession) { + try { + //if self-registration is enabled, then anyone can create a user + if (componentContext != null) { + String filter = "(&(sling.servlet.resourceTypes=sling/users)(|(sling.servlet.methods=POST)(sling.servlet.selectors=create)))"; + BundleContext bundleContext = componentContext.getBundleContext(); + ServiceReference[] serviceReferences = bundleContext.getServiceReferences(Servlet.class.getName(), filter); + if (serviceReferences != null) { + String propName = "self.registration.enabled"; + for (ServiceReference serviceReference : serviceReferences) { + Object propValue = serviceReference.getProperty(propName); + if (propValue != null) { + boolean selfRegEnabled = Boolean.TRUE.equals(propValue); + if (selfRegEnabled) { + return true; + } + break; + } + } + } + } - UserManager userManager = AccessControlUtil.getUserManager(jcrSession); - Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); - if (currentUser != null) { - if (((User)currentUser).isAdmin()) { - return true; //admin user has full control - } - - //check if the user is a member of the 'User administrator' group - Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName); - if (userAdmin instanceof Group) { - boolean isMember = ((Group)userAdmin).isMember(currentUser); - if (isMember) { - return true; - } - } - } - } catch (RepositoryException e) { - log.warn("Failed to determine if {} can add a new user", jcrSession.getUserID()); - } catch (InvalidSyntaxException e) { - log.warn("Failed to determine if {} can add a new user", jcrSession.getUserID()); - } - return false; - } + UserManager userManager = AccessControlUtil.getUserManager(jcrSession); + Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); + if (currentUser != null) { + if (((User)currentUser).isAdmin()) { + return true; //admin user has full control + } + + //check if the user is a member of the 'User administrator' group + Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName); + if (userAdmin instanceof Group) { + boolean isMember = ((Group)userAdmin).isMember(currentUser); + if (isMember) { + return true; + } + } + } + } catch (RepositoryException e) { + log.warn("Failed to determine if {} can add a new user", jcrSession.getUserID()); + } catch (InvalidSyntaxException e) { + log.warn("Failed to determine if {} can add a new user", jcrSession.getUserID()); + } + return false; + } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canRemove(javax.jcr.Session, java.lang.String) - */ - public boolean canRemove(Session jcrSession, String principalId) { - try { - UserManager userManager = AccessControlUtil.getUserManager(jcrSession); - Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canRemove(javax.jcr.Session, java.lang.String) + */ + public boolean canRemove(Session jcrSession, String principalId) { + try { + UserManager userManager = AccessControlUtil.getUserManager(jcrSession); + Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); - if (((User)currentUser).isAdmin()) { - return true; //admin user has full control - } + if (((User)currentUser).isAdmin()) { + return true; //admin user has full control + } - Authorizable authorizable = userManager.getAuthorizable(principalId); - if (authorizable instanceof User) { - //check if the user is a member of the 'User administrator' group - Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName); - if (userAdmin instanceof Group) { - boolean isMember = ((Group)userAdmin).isMember(currentUser); - if (isMember) { - return true; - } - } - } else if (authorizable instanceof Group) { - //check if the user is a member of the 'Group administrator' group - Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName); - if (groupAdmin instanceof Group) { - boolean isMember = ((Group)groupAdmin).isMember(currentUser); - if (isMember) { - return true; - } - } - } - } catch (RepositoryException e) { - log.warn("Failed to determine if {} can remove authorizable {}", jcrSession.getUserID(), principalId); - } - return false; - } + Authorizable authorizable = userManager.getAuthorizable(principalId); + if (authorizable instanceof User) { + //check if the user is a member of the 'User administrator' group + Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName); + if (userAdmin instanceof Group) { + boolean isMember = ((Group)userAdmin).isMember(currentUser); + if (isMember) { + return true; + } + } + } else if (authorizable instanceof Group) { + //check if the user is a member of the 'Group administrator' group + Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName); + if (groupAdmin instanceof Group) { + boolean isMember = ((Group)groupAdmin).isMember(currentUser); + if (isMember) { + return true; + } + } + } + } catch (RepositoryException e) { + log.warn("Failed to determine if {} can remove authorizable {}", jcrSession.getUserID(), principalId); + } + return false; + } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canUpdateGroupMembers(javax.jcr.Session, java.lang.String) - */ - public boolean canUpdateGroupMembers(Session jcrSession, String groupId) { - try { - UserManager userManager = AccessControlUtil.getUserManager(jcrSession); - Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canUpdateGroupMembers(javax.jcr.Session, java.lang.String) + */ + public boolean canUpdateGroupMembers(Session jcrSession, String groupId) { + try { + UserManager userManager = AccessControlUtil.getUserManager(jcrSession); + Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); - if (((User)currentUser).isAdmin()) { - return true; //admin user has full control - } + if (((User)currentUser).isAdmin()) { + return true; //admin user has full control + } - Authorizable authorizable = userManager.getAuthorizable(groupId); - if (authorizable instanceof Group) { - //check if the user is a member of the 'Group administrator' group - Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName); - if (groupAdmin instanceof Group) { - boolean isMember = ((Group)groupAdmin).isMember(currentUser); - if (isMember) { - return true; - } - } - - //check if the user is a member of the 'User administrator' group - Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName); - if (userAdmin instanceof Group) { - boolean isMember = ((Group)userAdmin).isMember(currentUser); - if (isMember) { - return true; - } - } - } - } catch (RepositoryException e) { - log.warn("Failed to determine if {} can remove authorizable {}", jcrSession.getUserID(), groupId); - } - return false; - } + Authorizable authorizable = userManager.getAuthorizable(groupId); + if (authorizable instanceof Group) { + //check if the user is a member of the 'Group administrator' group + Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName); + if (groupAdmin instanceof Group) { + boolean isMember = ((Group)groupAdmin).isMember(currentUser); + if (isMember) { + return true; + } + } + + //check if the user is a member of the 'User administrator' group + Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName); + if (userAdmin instanceof Group) { + boolean isMember = ((Group)userAdmin).isMember(currentUser); + if (isMember) { + return true; + } + } + } + } catch (RepositoryException e) { + log.warn("Failed to determine if {} can remove authorizable {}", jcrSession.getUserID(), groupId); + } + return false; + } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canUpdateProperties(javax.jcr.Session, java.lang.String) - */ - public boolean canUpdateProperties(Session jcrSession, String principalId) { - try { - if (jcrSession.getUserID().equals(principalId)) { - //user is allowed to update it's own properties - return true; - } - - UserManager userManager = AccessControlUtil.getUserManager(jcrSession); - Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.AuthorizablePrivilegesInfo#canUpdateProperties(javax.jcr.Session, java.lang.String) + */ + public boolean canUpdateProperties(Session jcrSession, String principalId) { + try { + if (jcrSession.getUserID().equals(principalId)) { + //user is allowed to update it's own properties + return true; + } + + UserManager userManager = AccessControlUtil.getUserManager(jcrSession); + Authorizable currentUser = userManager.getAuthorizable(jcrSession.getUserID()); - if (((User)currentUser).isAdmin()) { - return true; //admin user has full control - } + if (((User)currentUser).isAdmin()) { + return true; //admin user has full control + } - Authorizable authorizable = userManager.getAuthorizable(principalId); - if (authorizable instanceof User) { - //check if the user is a member of the 'User administrator' group - Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName); - if (userAdmin instanceof Group) { - boolean isMember = ((Group)userAdmin).isMember(currentUser); - if (isMember) { - return true; - } - } - } else if (authorizable instanceof Group) { - //check if the user is a member of the 'Group administrator' group - Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName); - if (groupAdmin instanceof Group) { - boolean isMember = ((Group)groupAdmin).isMember(currentUser); - if (isMember) { - return true; - } - } - } - } catch (RepositoryException e) { - log.warn("Failed to determine if {} can remove authorizable {}", jcrSession.getUserID(), principalId); - } - return false; - } + Authorizable authorizable = userManager.getAuthorizable(principalId); + if (authorizable instanceof User) { + //check if the user is a member of the 'User administrator' group + Authorizable userAdmin = userManager.getAuthorizable(this.userAdminGroupName); + if (userAdmin instanceof Group) { + boolean isMember = ((Group)userAdmin).isMember(currentUser); + if (isMember) { + return true; + } + } + } else if (authorizable instanceof Group) { + //check if the user is a member of the 'Group administrator' group + Authorizable groupAdmin = userManager.getAuthorizable(this.groupAdminGroupName); + if (groupAdmin instanceof Group) { + boolean isMember = ((Group)groupAdmin).isMember(currentUser); + if (isMember) { + return true; + } + } + } + } catch (RepositoryException e) { + log.warn("Failed to determine if {} can remove authorizable {}", jcrSession.getUserID(), principalId); + } + return false; + } - // ---------- SCR Integration ---------------------------------------------- + // ---------- SCR Integration ---------------------------------------------- - //keep track of the bundle context - private ComponentContext componentContext; + //keep track of the bundle context + private ComponentContext componentContext; /** * Called by SCR to activate the component. @@ -320,21 +320,21 @@ public class AuthorizablePrivilegesInfoImpl implements AuthorizablePrivilegesInf throws InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, UnsupportedEncodingException { - this.componentContext = componentContext; - + this.componentContext = componentContext; + Dictionary<?, ?> properties = componentContext.getProperties(); this.userAdminGroupName = OsgiUtil.toString(properties.get(PAR_USER_ADMIN_GROUP_NAME), - DEFAULT_USER_ADMIN_GROUP_NAME); + DEFAULT_USER_ADMIN_GROUP_NAME); log.info("User Admin Group Name {}", this.userAdminGroupName); this.groupAdminGroupName = OsgiUtil.toString(properties.get(PAR_GROUP_ADMIN_GROUP_NAME), - DEFAULT_GROUP_ADMIN_GROUP_NAME); + DEFAULT_GROUP_ADMIN_GROUP_NAME); log.info("Group Admin Group Name {}", this.groupAdminGroupName); } protected void deactivate(ComponentContext componentContext) { - this.userAdminGroupName = DEFAULT_USER_ADMIN_GROUP_NAME; - this.groupAdminGroupName = DEFAULT_GROUP_ADMIN_GROUP_NAME; + this.userAdminGroupName = DEFAULT_USER_ADMIN_GROUP_NAME; + this.groupAdminGroupName = DEFAULT_GROUP_ADMIN_GROUP_NAME; } } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java index 40f6a96..08c97b4 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java @@ -138,7 +138,7 @@ public abstract class AbstractAuthorizablePostServlet extends String typeHintValue = convertToString(e.getValue()); if (typeHintValue != null) { - prop.setTypeHintValue(typeHintValue); + prop.setTypeHintValue(typeHintValue); } continue; @@ -508,186 +508,186 @@ public abstract class AbstractAuthorizablePostServlet extends } - protected String convertToString(Object obj) { - if (obj == null) { - return null; - } - - if (obj instanceof String) { - return (String)obj; - } else if (obj instanceof String[]) { - String [] values = (String[])obj; - if (values.length > 0) { - return values[0]; - } - return null; - } else if (obj instanceof RequestParameter) { - ((RequestParameter)obj).getString(); - } else if (obj instanceof RequestParameter[]) { - RequestParameter[] values = (RequestParameter[])obj; - if (values.length > 0) { - return values[0].getString(); - } - return null; - } - return null; - } + protected String convertToString(Object obj) { + if (obj == null) { + return null; + } + + if (obj instanceof String) { + return (String)obj; + } else if (obj instanceof String[]) { + String [] values = (String[])obj; + if (values.length > 0) { + return values[0]; + } + return null; + } else if (obj instanceof RequestParameter) { + ((RequestParameter)obj).getString(); + } else if (obj instanceof RequestParameter[]) { + RequestParameter[] values = (RequestParameter[])obj; + if (values.length > 0) { + return values[0].getString(); + } + return null; + } + return null; + } + + protected String[] convertToStringArray(Object obj) { + if (obj == null) { + return null; + } + + if (obj instanceof String) { + return new String[] {(String)obj}; + } else if (obj instanceof String[]) { + return (String[])obj; + } else if (obj instanceof RequestParameter) { + return new String[] {((RequestParameter)obj).getString()}; + } else if (obj instanceof RequestParameter[]) { + RequestParameter[] values = (RequestParameter[])obj; + String [] strValues = new String[values.length]; + for (int i=0; i < values.length; i++) { + strValues[i] = values[i].getString(); + } + return strValues; + } + return null; + } + + protected RequestParameter[] convertToRequestParameterArray(Object obj) { + if (obj == null) { + return null; + } + + if (obj instanceof String) { + return new RequestParameter[] { + new RequestParameterImpl((String)obj, null) + }; + } else if (obj instanceof String[]) { + String [] strValues = (String[])obj; + RequestParameter [] values = new RequestParameter[strValues.length]; + for (int i=0; i < strValues.length; i++) { + values[i] = new RequestParameterImpl(strValues[i], null); + } + return values; + } else if (obj instanceof RequestParameter) { + return new RequestParameter[] {(RequestParameter)obj}; + } else if (obj instanceof RequestParameter[]) { + return (RequestParameter[])obj; + } + return null; + } + + static class RequestParameterImpl implements RequestParameter { + + private String value; + private String encoding; + + private byte[] content; + + RequestParameterImpl(String value, String encoding) { + this.encoding = encoding; + this.value = value; + this.content = null; + } + + String getEncoding() { + return this.encoding; + } + + void setEncoding(String encoding) { + // recode this parameter by encoding the string with the current + // encoding and decode the bytes with the encoding + try { + this.value = getString(encoding); + } catch (UnsupportedEncodingException uee) { + throw new SlingUnsupportedEncodingException(uee); + } + this.encoding = encoding; + } + + /** + * @see org.apache.sling.api.request.RequestParameter#get() + */ + public byte[] get() { + if (content == null) { + try { + content = getString().getBytes(getEncoding()); + } catch (Exception e) { + // UnsupportedEncodingException, IllegalArgumentException + content = getString().getBytes(); + } + } + return content; + } + + /** + * @see org.apache.sling.api.request.RequestParameter#getContentType() + */ + public String getContentType() { + // none known for www-form-encoded parameters + return null; + } + + /** + * @see org.apache.sling.api.request.RequestParameter#getInputStream() + */ + public InputStream getInputStream() { + return new ByteArrayInputStream(this.get()); + } + + /** + * @see org.apache.sling.api.request.RequestParameter#getFileName() + */ + public String getFileName() { + // no original file name + return null; + } + + /** + * @see org.apache.sling.api.request.RequestParameter#getSize() + */ + public long getSize() { + return this.get().length; + } + + /** + * @see org.apache.sling.api.request.RequestParameter#getString() + */ + public String getString() { + return value; + } + + /** + * @see org.apache.sling.api.request.RequestParameter#getString(java.lang.String) + */ + public String getString(String encoding) + throws UnsupportedEncodingException { + return new String(this.get(), encoding); + } + + /** + * @see org.apache.sling.api.request.RequestParameter#isFormField() + */ + public boolean isFormField() { + // www-form-encoded are always form fields + return true; + } + + public String toString() { + return this.getString(); + } + } - protected String[] convertToStringArray(Object obj) { - if (obj == null) { - return null; - } - - if (obj instanceof String) { - return new String[] {(String)obj}; - } else if (obj instanceof String[]) { - return (String[])obj; - } else if (obj instanceof RequestParameter) { - return new String[] {((RequestParameter)obj).getString()}; - } else if (obj instanceof RequestParameter[]) { - RequestParameter[] values = (RequestParameter[])obj; - String [] strValues = new String[values.length]; - for (int i=0; i < values.length; i++) { - strValues[i] = values[i].getString(); - } - return strValues; - } - return null; - } - - protected RequestParameter[] convertToRequestParameterArray(Object obj) { - if (obj == null) { - return null; - } - - if (obj instanceof String) { - return new RequestParameter[] { - new RequestParameterImpl((String)obj, null) - }; - } else if (obj instanceof String[]) { - String [] strValues = (String[])obj; - RequestParameter [] values = new RequestParameter[strValues.length]; - for (int i=0; i < strValues.length; i++) { - values[i] = new RequestParameterImpl(strValues[i], null); - } - return values; - } else if (obj instanceof RequestParameter) { - return new RequestParameter[] {(RequestParameter)obj}; - } else if (obj instanceof RequestParameter[]) { - return (RequestParameter[])obj; - } - return null; - } - - static class RequestParameterImpl implements RequestParameter { - - private String value; - private String encoding; - - private byte[] content; - - RequestParameterImpl(String value, String encoding) { - this.encoding = encoding; - this.value = value; - this.content = null; - } - - String getEncoding() { - return this.encoding; - } - - void setEncoding(String encoding) { - // recode this parameter by encoding the string with the current - // encoding and decode the bytes with the encoding - try { - this.value = getString(encoding); - } catch (UnsupportedEncodingException uee) { - throw new SlingUnsupportedEncodingException(uee); - } - this.encoding = encoding; - } - - /** - * @see org.apache.sling.api.request.RequestParameter#get() - */ - public byte[] get() { - if (content == null) { - try { - content = getString().getBytes(getEncoding()); - } catch (Exception e) { - // UnsupportedEncodingException, IllegalArgumentException - content = getString().getBytes(); - } - } - return content; - } - - /** - * @see org.apache.sling.api.request.RequestParameter#getContentType() - */ - public String getContentType() { - // none known for www-form-encoded parameters - return null; - } - - /** - * @see org.apache.sling.api.request.RequestParameter#getInputStream() - */ - public InputStream getInputStream() { - return new ByteArrayInputStream(this.get()); - } - - /** - * @see org.apache.sling.api.request.RequestParameter#getFileName() - */ - public String getFileName() { - // no original file name - return null; - } - - /** - * @see org.apache.sling.api.request.RequestParameter#getSize() - */ - public long getSize() { - return this.get().length; - } - - /** - * @see org.apache.sling.api.request.RequestParameter#getString() - */ - public String getString() { - return value; - } - - /** - * @see org.apache.sling.api.request.RequestParameter#getString(java.lang.String) - */ - public String getString(String encoding) - throws UnsupportedEncodingException { - return new String(this.get(), encoding); - } - - /** - * @see org.apache.sling.api.request.RequestParameter#isFormField() - */ - public boolean isFormField() { - // www-form-encoded are always form fields - return true; - } - - public String toString() { - return this.getString(); - } - } - - static class SlingUnsupportedEncodingException extends SlingIOException { - - private static final long serialVersionUID = -4482276105859280247L; - - SlingUnsupportedEncodingException(UnsupportedEncodingException uee) { - super(uee); - } - - } + static class SlingUnsupportedEncodingException extends SlingIOException { + + private static final long serialVersionUID = -4482276105859280247L; + + SlingUnsupportedEncodingException(UnsupportedEncodingException uee) { + super(uee); + } + + } } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractGroupPostServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractGroupPostServlet.java index 5d10d6c..8da122c 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractGroupPostServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractGroupPostServlet.java @@ -49,9 +49,9 @@ public abstract class AbstractGroupPostServlet extends * @throws RepositoryException */ protected void updateGroupMembership(Resource baseResource, - Map<String, ?> properties, - Authorizable authorizable, - List<Modification> changes) + Map<String, ?> properties, + Authorizable authorizable, + List<Modification> changes) throws RepositoryException { if (authorizable.isGroup()) { Group group = ((Group) authorizable); @@ -106,23 +106,23 @@ public abstract class AbstractGroupPostServlet extends * @param resolver the resource resolver for this request. * @return the authorizable, or null if no authorizable was found. */ - private Authorizable getAuthorizable(Resource baseResource, - String member, - UserManager userManager, - ResourceResolver resolver) { - Authorizable memberAuthorizable = null; - try { - memberAuthorizable = userManager.getAuthorizable(member); - } catch (RepositoryException e) { - // if we can't find the members then it may be resolvable as a resource. - } - if ( memberAuthorizable == null ) { - Resource res = resolver.getResource(baseResource, member); - if (res != null) { - memberAuthorizable = res.adaptTo(Authorizable.class); - } - } - return memberAuthorizable; - } + private Authorizable getAuthorizable(Resource baseResource, + String member, + UserManager userManager, + ResourceResolver resolver) { + Authorizable memberAuthorizable = null; + try { + memberAuthorizable = userManager.getAuthorizable(member); + } catch (RepositoryException e) { + // if we can't find the members then it may be resolvable as a resource. + } + if ( memberAuthorizable == null ) { + Resource res = resolver.getResource(baseResource, member); + if (res != null) { + memberAuthorizable = res.adaptTo(Authorizable.class); + } + } + return memberAuthorizable; + } } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java index e6e0311..fec6cae 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java @@ -45,9 +45,9 @@ import org.slf4j.LoggerFactory; public abstract class AbstractPostServlet extends SlingAllMethodsServlet { - private static final long serialVersionUID = 7408267654653472120L; - - /** + private static final long serialVersionUID = 7408267654653472120L; + + /** * default log */ private final Logger log = LoggerFactory.getLogger(getClass()); @@ -161,11 +161,11 @@ public abstract class AbstractPostServlet extends * or a {@link org.apache.sling.api.servlets.HtmlResponse} otherwise */ protected HtmlResponse createHtmlResponse(SlingHttpServletRequest req) { - if (JSONResponse.RESPONSE_CONTENT_TYPE.equals(req.getResponseContentType())) { - return new JSONResponse(); - } else { + if (JSONResponse.RESPONSE_CONTENT_TYPE.equals(req.getResponseContentType())) { + return new JSONResponse(); + } else { return new HtmlResponse(); - } + } } /** diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java index b5d5dd5..1f6fdfd 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java @@ -126,7 +126,7 @@ public class ChangeUserPasswordServlet extends AbstractUserPostServlet implement Dictionary<?, ?> props = componentContext.getProperties(); this.userAdminGroupName = OsgiUtil.toString(props.get(PAR_USER_ADMIN_GROUP_NAME), - DEFAULT_USER_ADMIN_GROUP_NAME); + DEFAULT_USER_ADMIN_GROUP_NAME); log.info("User Admin Group Name {}", this.userAdminGroupName); } @@ -141,45 +141,45 @@ public class ChangeUserPasswordServlet extends AbstractUserPostServlet implement protected void handleOperation(SlingHttpServletRequest request, HtmlResponse htmlResponse, List<Modification> changes) throws RepositoryException { - + Resource resource = request.getResource(); Session session = request.getResourceResolver().adaptTo(Session.class); - changePassword(session, - resource.getName(), - request.getParameter("oldPwd"), - request.getParameter("newPwd"), - request.getParameter("newPwdConfirm"), - changes); + changePassword(session, + resource.getName(), + request.getParameter("oldPwd"), + request.getParameter("newPwd"), + request.getParameter("newPwdConfirm"), + changes); } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.ChangeUserPassword#changePassword(javax.jcr.Session, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.List) - */ - public User changePassword(Session jcrSession, - String name, - String oldPassword, - String newPassword, - String newPasswordConfirm, - List<Modification> changes) - throws RepositoryException { - + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.ChangeUserPassword#changePassword(javax.jcr.Session, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.util.List) + */ + public User changePassword(Session jcrSession, + String name, + String oldPassword, + String newPassword, + String newPasswordConfirm, + List<Modification> changes) + throws RepositoryException { + if ("anonymous".equals(name)) { throw new RepositoryException( "Can not change the password of the anonymous user."); } - - User user; + + User user; UserManager userManager = AccessControlUtil.getUserManager(jcrSession); Authorizable authorizable = userManager.getAuthorizable(name); if (authorizable instanceof User) { - user = (User)authorizable; + user = (User)authorizable; } else { throw new ResourceNotFoundException( - "User to update could not be determined"); + "User to update could not be determined"); } - //SLING-2069: if the current user is an administrator, then a missing oldPwd is ok, - // otherwise the oldPwd must be supplied. + //SLING-2069: if the current user is an administrator, then a missing oldPwd is ok, + // otherwise the oldPwd must be supplied. boolean administrator = false; // check that the submitted parameter values have valid values. @@ -190,22 +190,22 @@ public class ChangeUserPasswordServlet extends AbstractUserPostServlet implement administrator = currentUser.isAdmin(); if (!administrator) { - //check if the user is a member of the 'User administrator' group - Authorizable userAdmin = um.getAuthorizable(this.userAdminGroupName); - if (userAdmin instanceof Group) { - boolean isMember = ((Group)userAdmin).isMember(currentUser); - if (isMember) { - administrator = true; - } - } - + //check if the user is a member of the 'User administrator' group + Authorizable userAdmin = um.getAuthorizable(this.userAdminGroupName); + if (userAdmin instanceof Group) { + boolean isMember = ((Group)userAdmin).isMember(currentUser); + if (isMember) { + administrator = true; + } + } + } } catch ( Exception ex ) { log.warn("Failed to determine if the user is an admin, assuming not. Cause: "+ex.getMessage()); administrator = false; } if (!administrator) { - throw new RepositoryException("Old Password was not submitted"); + throw new RepositoryException("Old Password was not submitted"); } } if (newPassword == null || newPassword.length() == 0) { @@ -225,7 +225,7 @@ public class ChangeUserPasswordServlet extends AbstractUserPostServlet implement ((User) authorizable).changePassword(digestPassword(newPassword)); String userPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX - + user.getID(); + + user.getID(); changes.add(Modification.onModified(userPath + "/rep:password")); @@ -234,7 +234,7 @@ public class ChangeUserPasswordServlet extends AbstractUserPostServlet implement } return user; - } + } private void checkPassword(Authorizable authorizable, String oldPassword) diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java index 88721e1..a2e5c47 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java @@ -88,7 +88,7 @@ public class CreateGroupServlet extends AbstractGroupPostServlet implements Crea private static final long serialVersionUID = -1084915263933901466L; /** @scr.reference */ - private JcrResourceResolverFactory resourceResolverFactory; + private JcrResourceResolverFactory resourceResolverFactory; /* * (non-Javadoc) @@ -105,28 +105,28 @@ public class CreateGroupServlet extends AbstractGroupPostServlet implements Crea Session session = request.getResourceResolver().adaptTo(Session.class); String principalName = request.getParameter(SlingPostConstants.RP_NODE_NAME); Group group = createGroup(session, - principalName, - request.getRequestParameterMap(), - changes); + principalName, + request.getRequestParameterMap(), + changes); String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX - + group.getID(); + + group.getID(); response.setPath(groupPath); response.setLocation(externalizePath(request, groupPath)); response.setParentLocation(externalizePath(request, AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PATH)); } - - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.CreateGroup#createGroup(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List) - */ - public Group createGroup(Session jcrSession, final String name, - Map<String, ?> properties, List<Modification> changes) - throws RepositoryException { + + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.CreateGroup#createGroup(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List) + */ + public Group createGroup(Session jcrSession, final String name, + Map<String, ?> properties, List<Modification> changes) + throws RepositoryException { // check that the parameter values have valid values. - if (jcrSession == null) { - throw new IllegalArgumentException("JCR Session not found"); + if (jcrSession == null) { + throw new IllegalArgumentException("JCR Session not found"); } if (name == null || name.length() == 0) { @@ -162,18 +162,18 @@ public class CreateGroupServlet extends AbstractGroupPostServlet implements Crea // update the group memberships ResourceResolver resourceResolver = null; try { - //create a resource resolver to resolve the relative paths used for group membership values + //create a resource resolver to resolve the relative paths used for group membership values resourceResolver = resourceResolverFactory.getResourceResolver(jcrSession); Resource baseResource = resourceResolver.getResource(AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PATH); updateGroupMembership(baseResource, properties, group, changes); } finally { - if (resourceResolver != null) { - resourceResolver.close(); - } + if (resourceResolver != null) { + resourceResolver.close(); + } } } return group; - } + } } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateUserServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateUserServlet.java index ec95910..23c622e 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateUserServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateUserServlet.java @@ -170,7 +170,7 @@ public class CreateUserServlet extends AbstractUserPostServlet implements Create Dictionary<?, ?> props = componentContext.getProperties(); Object propValue = props.get(PROP_SELF_REGISTRATION_ENABLED); if (propValue instanceof Boolean) { - selfRegistrationEnabled = (Boolean)propValue; + selfRegistrationEnabled = (Boolean)propValue; } else if (propValue instanceof String) { selfRegistrationEnabled = Boolean.parseBoolean((String) propValue); } else { @@ -178,7 +178,7 @@ public class CreateUserServlet extends AbstractUserPostServlet implements Create } this.userAdminGroupName = OsgiUtil.toString(props.get(PAR_USER_ADMIN_GROUP_NAME), - DEFAULT_USER_ADMIN_GROUP_NAME); + DEFAULT_USER_ADMIN_GROUP_NAME); log.info("User Admin Group Name {}", this.userAdminGroupName); } @@ -197,32 +197,32 @@ public class CreateUserServlet extends AbstractUserPostServlet implements Create Session session = request.getResourceResolver().adaptTo(Session.class); String principalName = request.getParameter(SlingPostConstants.RP_NODE_NAME); - User user = createUser(session, - principalName, - request.getParameter("pwd"), - request.getParameter("pwdConfirm"), - request.getRequestParameterMap(), - changes); - + User user = createUser(session, + principalName, + request.getParameter("pwd"), + request.getParameter("pwdConfirm"), + request.getRequestParameterMap(), + changes); + String userPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_USER_PREFIX - + user.getID(); + + user.getID(); response.setPath(userPath); response.setLocation(externalizePath(request, userPath)); response.setParentLocation(externalizePath(request, AuthorizableResourceProvider.SYSTEM_USER_MANAGER_USER_PATH)); } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.CreateUser#createUser(javax.jcr.Session, java.lang.String, java.lang.String, java.lang.String, java.util.Map, java.util.List) - */ - public User createUser(Session jcrSession, - String name, - String password, - String passwordConfirm, - Map<String, ?> properties, - List<Modification> changes) - throws RepositoryException { - + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.CreateUser#createUser(javax.jcr.Session, java.lang.String, java.lang.String, java.lang.String, java.util.Map, java.util.List) + */ + public User createUser(Session jcrSession, + String name, + String password, + String passwordConfirm, + Map<String, ?> properties, + List<Modification> changes) + throws RepositoryException { + if (jcrSession == null) { throw new RepositoryException("JCR Session not found"); } @@ -235,15 +235,15 @@ public class CreateUserServlet extends AbstractUserPostServlet implements Create administrator = currentUser.isAdmin(); if (!administrator) { - //check if the user is a member of the 'User administrator' group - Authorizable userAdmin = um.getAuthorizable(this.userAdminGroupName); - if (userAdmin instanceof Group) { - boolean isMember = ((Group)userAdmin).isMember(currentUser); - if (isMember) { - administrator = true; - } - } - + //check if the user is a member of the 'User administrator' group + Authorizable userAdmin = um.getAuthorizable(this.userAdminGroupName); + if (userAdmin instanceof Group) { + boolean isMember = ((Group)userAdmin).isMember(currentUser); + if (isMember) { + administrator = true; + } + } + } } catch ( Exception ex ) { log.warn("Failed to determine if the user is an admin, assuming not. Cause: "+ex.getMessage()); @@ -275,11 +275,11 @@ public class CreateUserServlet extends AbstractUserPostServlet implements Create boolean useAdminSession = !administrator && selfRegistrationEnabled; try { if (useAdminSession) { - //the current user doesn't have permission to create the user, - // but self-registration is enabled, so use an admin session - // to do the work. + //the current user doesn't have permission to create the user, + // but self-registration is enabled, so use an admin session + // to do the work. selfRegSession = getSession(); - } + } UserManager userManager = AccessControlUtil.getUserManager(selfRegSession); Authorizable authorizable = userManager.getAuthorizable(name); @@ -307,24 +307,24 @@ public class CreateUserServlet extends AbstractUserPostServlet implements Create } if (useAdminSession) { - //lookup the user from the user session so we can return a live object + //lookup the user from the user session so we can return a live object UserManager userManager2 = AccessControlUtil.getUserManager(jcrSession); Authorizable authorizable2 = userManager2.getAuthorizable(user.getID()); if (authorizable2 instanceof User) { - user = (User)authorizable2; + user = (User)authorizable2; } else { - user = null; + user = null; } } } } finally { if (useAdminSession) { - //done with the self-reg admin session, so clean it up + //done with the self-reg admin session, so clean it up ungetSession(selfRegSession); - } + } } - - return user; - } + + return user; + } } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java index 088197a..171bf4e 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java @@ -88,7 +88,7 @@ import org.apache.sling.servlets.post.SlingPostConstants; * @scr.property name="sling.servlet.selectors" value="delete" */ public class DeleteAuthorizableServlet extends AbstractPostServlet - implements DeleteUser, DeleteGroup, DeleteAuthorizables { + implements DeleteUser, DeleteGroup, DeleteAuthorizables { private static final long serialVersionUID = 5874621724096106496L; /* @@ -107,10 +107,10 @@ public class DeleteAuthorizableServlet extends AbstractPostServlet Resource resource = request.getResource(); String[] applyTo = request.getParameterValues(SlingPostConstants.RP_APPLY_TO); if (applyTo != null) { - deleteAuthorizables(session, - resource, - applyTo, - changes); + deleteAuthorizables(session, + resource, + applyTo, + changes); } else { Authorizable item = resource.adaptTo(Authorizable.class); if (item == null) { @@ -119,70 +119,70 @@ public class DeleteAuthorizableServlet extends AbstractPostServlet htmlResponse.setStatus(HttpServletResponse.SC_NOT_FOUND, msg); throw new ResourceNotFoundException(msg); } else { - if (item instanceof User) { - deleteUser(session, item.getID(), changes); - } else if (item instanceof Group) { - deleteGroup(session, item.getID(), changes); - } + if (item instanceof User) { + deleteUser(session, item.getID(), changes); + } else if (item instanceof Group) { + deleteGroup(session, item.getID(), changes); + } } } } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.DeleteUser#deleteUser(javax.jcr.Session, java.lang.String, java.util.List) - */ - public void deleteUser(Session jcrSession, String name, - List<Modification> changes) throws RepositoryException { - - User user; - UserManager userManager = AccessControlUtil.getUserManager(jcrSession); + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.DeleteUser#deleteUser(javax.jcr.Session, java.lang.String, java.util.List) + */ + public void deleteUser(Session jcrSession, String name, + List<Modification> changes) throws RepositoryException { + + User user; + UserManager userManager = AccessControlUtil.getUserManager(jcrSession); Authorizable authorizable = userManager.getAuthorizable(name); if (authorizable instanceof User) { - user = (User)authorizable; + user = (User)authorizable; } else { throw new ResourceNotFoundException( - "User to delete could not be determined"); + "User to delete could not be determined"); } String userPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_USER_PREFIX - + user.getID(); + + user.getID(); user.remove(); changes.add(Modification.onDeleted(userPath)); - } - - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.DeleteGroup#deleteGroup(javax.jcr.Session, java.lang.String, java.util.List) - */ - public void deleteGroup(Session jcrSession, - String name, - List<Modification> changes) throws RepositoryException { - - Group group; - UserManager userManager = AccessControlUtil.getUserManager(jcrSession); + } + + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.DeleteGroup#deleteGroup(javax.jcr.Session, java.lang.String, java.util.List) + */ + public void deleteGroup(Session jcrSession, + String name, + List<Modification> changes) throws RepositoryException { + + Group group; + UserManager userManager = AccessControlUtil.getUserManager(jcrSession); Authorizable authorizable = userManager.getAuthorizable(name); if (authorizable instanceof Group) { - group = (Group)authorizable; + group = (Group)authorizable; } else { throw new ResourceNotFoundException( - "Group to delete could not be determined"); + "Group to delete could not be determined"); } String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX - + group.getID(); + + group.getID(); group.remove(); changes.add(Modification.onDeleted(groupPath)); - } - - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.DeleteAuthorizables#deleteAuthorizables(javax.jcr.Session, org.apache.sling.api.resource.Resource, java.lang.String[], java.util.List) - */ - public void deleteAuthorizables(Session jcrSession, - Resource baseResource, - String[] paths, - List<Modification> changes) - throws RepositoryException { - - ApplyToIterator iterator = new ApplyToIterator(baseResource, paths); + } + + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.DeleteAuthorizables#deleteAuthorizables(javax.jcr.Session, org.apache.sling.api.resource.Resource, java.lang.String[], java.util.List) + */ + public void deleteAuthorizables(Session jcrSession, + Resource baseResource, + String[] paths, + List<Modification> changes) + throws RepositoryException { + + ApplyToIterator iterator = new ApplyToIterator(baseResource, paths); while (iterator.hasNext()) { Resource resource = iterator.next(); Authorizable item = resource.adaptTo(Authorizable.class); @@ -191,7 +191,7 @@ public class DeleteAuthorizableServlet extends AbstractPostServlet changes.add(Modification.onDeleted(resource.getPath())); } } - } + } private static class ApplyToIterator implements Iterator<Resource> { diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java index 6f36439..eefa36c 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java @@ -85,11 +85,11 @@ import org.apache.sling.servlets.post.impl.helper.RequestProperty; * @scr.property name="sling.servlet.selectors" value="update" */ public class UpdateGroupServlet extends AbstractGroupPostServlet - implements UpdateGroup { + implements UpdateGroup { private static final long serialVersionUID = -8292054361992488797L; /** @scr.reference */ - private JcrResourceResolverFactory resourceResolverFactory; + private JcrResourceResolverFactory resourceResolverFactory; /* * (non-Javadoc) @@ -105,30 +105,30 @@ public class UpdateGroupServlet extends AbstractGroupPostServlet Resource resource = request.getResource(); Session session = request.getResourceResolver().adaptTo(Session.class); updateGroup(session, - resource.getName(), - request.getRequestParameterMap(), - changes); + resource.getName(), + request.getRequestParameterMap(), + changes); } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.UpdateGroup#updateGroup(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List) - */ - public Group updateGroup(Session jcrSession, - String name, - Map<String, ?> properties, - List<Modification> changes) - throws RepositoryException { + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.UpdateGroup#updateGroup(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List) + */ + public Group updateGroup(Session jcrSession, + String name, + Map<String, ?> properties, + List<Modification> changes) + throws RepositoryException { - Group group = null; + Group group = null; UserManager userManager = AccessControlUtil.getUserManager(jcrSession); Authorizable authorizable = userManager.getAuthorizable(name); if (authorizable instanceof Group) { - group = (Group)authorizable; + group = (Group)authorizable; } else { throw new ResourceNotFoundException( - "Group to update could not be determined"); + "Group to update could not be determined"); } - + String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX + group.getID(); @@ -143,19 +143,19 @@ public class UpdateGroupServlet extends AbstractGroupPostServlet // update the group memberships ResourceResolver resourceResolver = null; try { - //create a resource resolver to resolve the relative paths used for group membership values + //create a resource resolver to resolve the relative paths used for group membership values resourceResolver = resourceResolverFactory.getResourceResolver(jcrSession); Resource baseResource = resourceResolver.getResource(groupPath); updateGroupMembership(baseResource, properties, group, changes); } finally { - if (resourceResolver != null) { - resourceResolver.close(); - } + if (resourceResolver != null) { + resourceResolver.close(); + } } } catch (RepositoryException re) { throw new RepositoryException("Failed to update group.", re); } return group; - } + } } diff --git a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java index 2142a4f..cd9ac31 100644 --- a/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java +++ b/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java @@ -84,7 +84,7 @@ import org.apache.sling.servlets.post.impl.helper.RequestProperty; * @scr.property name="sling.servlet.selectors" value="update" */ public class UpdateUserServlet extends AbstractUserPostServlet - implements UpdateUser { + implements UpdateUser { private static final long serialVersionUID = 5874621724096106496L; /* @@ -101,26 +101,26 @@ public class UpdateUserServlet extends AbstractUserPostServlet Resource resource = request.getResource(); Session session = request.getResourceResolver().adaptTo(Session.class); updateUser(session, - resource.getName(), - request.getRequestParameterMap(), - changes); + resource.getName(), + request.getRequestParameterMap(), + changes); } - /* (non-Javadoc) - * @see org.apache.sling.jackrabbit.usermanager.UpdateUser#updateUser(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List) - */ - public User updateUser(Session jcrSession, String name, - Map<String, ?> properties, List<Modification> changes) - throws RepositoryException { + /* (non-Javadoc) + * @see org.apache.sling.jackrabbit.usermanager.UpdateUser#updateUser(javax.jcr.Session, java.lang.String, java.util.Map, java.util.List) + */ + public User updateUser(Session jcrSession, String name, + Map<String, ?> properties, List<Modification> changes) + throws RepositoryException { - User user; + User user; UserManager userManager = AccessControlUtil.getUserManager(jcrSession); Authorizable authorizable = userManager.getAuthorizable(name); if (authorizable instanceof User) { - user = (User)authorizable; + user = (User)authorizable; } else { throw new ResourceNotFoundException( - "User to update could not be determined"); + "User to update could not be determined"); } String userPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX @@ -138,19 +138,19 @@ public class UpdateUserServlet extends AbstractUserPostServlet // has supplied the relevant properties String disabledParam = convertToString(properties.get(":disabled")); if ("true".equalsIgnoreCase(disabledParam)) { - //set the user as disabled - String disabledReason = convertToString(properties.get(":disabledReason")); - if (disabledReason == null) { - disabledReason = ""; - } - user.disable(disabledReason); + //set the user as disabled + String disabledReason = convertToString(properties.get(":disabledReason")); + if (disabledReason == null) { + disabledReason = ""; + } + user.disable(disabledReason); } else if ("false".equalsIgnoreCase(disabledParam)) { - //re-enable a disabled user - user.disable(null); + //re-enable a disabled user + user.disable(null); } } catch (RepositoryException re) { throw new RepositoryException("Failed to update user.", re); } return user; - } + } } -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.