From: Bruno Sinou Date: Tue, 14 Jun 2011 16:16:35 +0000 (+0000) Subject: Fix some small bugs and add some comments on LDAP/JCR session synchronizing process. X-Git-Tag: argeo-commons-2.1.30~1230 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=2b8f41b43cc598398a4bb66dd46d7d87ac000134;p=lgpl%2Fargeo-commons.git Fix some small bugs and add some comments on LDAP/JCR session synchronizing process. git-svn-id: https://svn.argeo.org/commons/trunk@4572 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java b/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java index ec4255af9..5c6a88585 100644 --- a/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java +++ b/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java @@ -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()) diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java index 1cecd7100..b03be7396 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrUtils.java @@ -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