Fix some small bugs and add some comments on LDAP/JCR session synchronizing process.
authorBruno Sinou <bsinou@argeo.org>
Tue, 14 Jun 2011 16:16:35 +0000 (16:16 +0000)
committerBruno Sinou <bsinou@argeo.org>
Tue, 14 Jun 2011 16:16:35 +0000 (16:16 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4572 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java
server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java

index ec4255af9a6a1777583f058fda55cae186e2e902..5c6a88585ab4c4403fd251eff6edd72b3fa15cbe 100644 (file)
@@ -13,7 +13,6 @@ import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -115,14 +114,15 @@ public class JcrUserDetailsContextMapper implements UserDetailsContextMapper,
                                userHome = JcrUtils.createUserHome(session, homeBasePath,
                                                username);
                        String userHomePath = userHome.getPath();
-                       Node userProfile = userHome.getNode(ARGEO_PROFILE);
+                       Node userProfile;  // = userHome.getNode(ARGEO_PROFILE);
                        if (userHome.hasNode(ARGEO_PROFILE)) {
                                userProfile = userHome.getNode(ARGEO_PROFILE);
                        } else {
-                               userProfile = userHome.addNode(ARGEO_PROFILE);
-                               userProfile.addMixin(NodeType.MIX_TITLE);
-                               userProfile.addMixin(NodeType.MIX_CREATED);
-                               userProfile.addMixin(NodeType.MIX_LAST_MODIFIED);
+                               throw new ArgeoException("We should never reach this point");
+                               // userProfile = userHome.addNode(ARGEO_PROFILE);
+                               // userProfile.addMixin(NodeType.MIX_TITLE);
+                               // userProfile.addMixin(NodeType.MIX_CREATED);
+                               // userProfile.addMixin(NodeType.MIX_LAST_MODIFIED);
                        }
 
                        for (String jcrProperty : propertyToAttributes.keySet())
index 1cecd7100611744524da8e08296dbc49f00b935a..b03be7396bdce3cd4b17733bd73058d5692d60d7 100644 (file)
@@ -847,15 +847,34 @@ public class JcrUtils implements ArgeoJcrConstants {
                        if (session.hasPendingChanges())
                                throw new ArgeoException(
                                                "Session has pending changes, save them first");
+
                        String homePath = homeBasePath + '/'
                                        + firstCharsToPath(username, 2) + '/' + username;
-                       Node userHome = JcrUtils.mkdirs(session, homePath);
 
-                       Node userProfile = userHome.addNode(ArgeoNames.ARGEO_PROFILE);
-                       userProfile.addMixin(ArgeoTypes.ARGEO_USER_PROFILE);
-                       userProfile.setProperty(ArgeoNames.ARGEO_USER_ID, username);
-                       session.save();
-                       // we need to save the profile before adding the user home type
+                       if (session.itemExists(homePath)) {
+                               try {
+                                       throw new ArgeoException(
+                                                       "Trying to create a user home that already exists");
+                               } catch (Exception e) {
+                                       // we use this workaround to be sure to get the stack trace
+                                       // to identify the sink of the bug.
+                                       log.warn("trying to create an already existing userHome. Stack trace : ");
+                                       e.printStackTrace();
+                               }
+                       }
+
+                       Node userHome = JcrUtils.mkdirs(session, homePath);
+                       Node userProfile;
+                       if (userHome.hasNode(ArgeoNames.ARGEO_PROFILE)) {
+                               log.warn("User profile node already exists. We do not add a new one");
+
+                       } else {
+                               userProfile = userHome.addNode(ArgeoNames.ARGEO_PROFILE);
+                               userProfile.addMixin(ArgeoTypes.ARGEO_USER_PROFILE);
+                               userProfile.setProperty(ArgeoNames.ARGEO_USER_ID, username);
+                               session.save();
+                               // we need to save the profile before adding the user home type
+                       }
                        userHome.addMixin(ArgeoTypes.ARGEO_USER_HOME);
                        // see
                        // http://jackrabbit.510166.n4.nabble.com/Jackrabbit-2-0-beta-6-Problem-adding-a-Mixin-type-with-mandatory-properties-after-setting-propertiesn-td1290332.html