james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1241457 - /james/server/trunk/data-jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java
Date Tue, 07 Feb 2012 13:08:41 GMT
Author: eric
Date: Tue Feb  7 13:08:41 2012
New Revision: 1241457

URL: http://svn.apache.org/viewvc?rev=1241457&view=rev
Log:
Lower cases and check if existing before JCR user creation (JAMES-1369)

Modified:
    james/server/trunk/data-jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java

Modified: james/server/trunk/data-jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data-jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java?rev=1241457&r1=1241456&r2=1241457&view=diff
==============================================================================
--- james/server/trunk/data-jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java
(original)
+++ james/server/trunk/data-jcr/src/main/java/org/apache/james/user/jcr/JCRUsersRepository.java
Tue Feb  7 13:08:41 2012
@@ -364,16 +364,20 @@ public class JCRUsersRepository extends 
 
     @Override
     protected void doAddUser(String username, String password) throws UsersRepositoryException
{
+        String lowerCasedUsername = username.toLowerCase();
+        if (contains(lowerCasedUsername)) {
+            throw new UsersRepositoryException(lowerCasedUsername + " already exists.");
+        }
         try {
             final Session session = login();
             try {
-                final String name = toSafeName(username);
+                final String name = toSafeName(lowerCasedUsername);
                 final String path = USERS_PATH + "/" + name;
                 final Node rootNode = session.getRootNode();
                 try {
                     rootNode.getNode(path);
                     getLogger().info("User already exists");
-                    throw new UsersRepositoryException("User " + username + " already exists");
+                    throw new UsersRepositoryException("User " + lowerCasedUsername + " already
exists");
                 } catch (PathNotFoundException e) {
                     // user does not exist
                 }
@@ -387,13 +391,13 @@ public class JCRUsersRepository extends 
                 }
 
                 Node node = parent.addNode(name);
-                node.setProperty(USERNAME_PROPERTY, username);
+                node.setProperty(USERNAME_PROPERTY, lowerCasedUsername);
                 final String hashedPassword;
                 if (password == null) {
                     // Support easy password reset
                     hashedPassword = "";
                 } else {
-                    hashedPassword = JCRUser.hashPassword(username, password);
+                    hashedPassword = JCRUser.hashPassword(lowerCasedUsername, password);
                 }
                 node.setProperty(PASSWD_PROPERTY, hashedPassword);
                 session.save();
@@ -403,9 +407,9 @@ public class JCRUsersRepository extends 
 
         } catch (RepositoryException e) {
             if (getLogger().isInfoEnabled()) {
-                getLogger().info("Failed to add user: " + username, e);
+                getLogger().info("Failed to add user: " + lowerCasedUsername, e);
             }
-            throw new UsersRepositoryException("Failed to add user: " + username, e);
+            throw new UsersRepositoryException("Failed to add user: " + lowerCasedUsername,
e);
 
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message