X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=security%2Fruntime%2Forg.argeo.security.ldap%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsecurity%2Fldap%2Fjcr%2FJcrLdapSynchronizer.java;h=9e6271262daf32c883d1b6788c0dc84f3ccd040a;hb=4d665b0700136573b05879aa19897d8f448d8ca4;hp=0f59f1ee528c11561e8d9a67b6d4a3c13bb4b1d0;hpb=f763d5bc49fa5cae85e85ca8ae69f51d10a86060;p=lgpl%2Fargeo-commons.git diff --git a/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrLdapSynchronizer.java b/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrLdapSynchronizer.java index 0f59f1ee5..9e6271262 100644 --- a/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrLdapSynchronizer.java +++ b/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrLdapSynchronizer.java @@ -20,6 +20,7 @@ import javax.jcr.observation.Event; import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; import javax.jcr.query.Query; +import javax.jcr.version.VersionManager; import javax.naming.Binding; import javax.naming.Name; import javax.naming.NamingException; @@ -185,10 +186,21 @@ public class JcrLdapSynchronizer implements UserDetailsContextMapper, Node userProfile = it.nextNode(); String path = userProfile.getPath(); if (!userPaths.contains(path)) { + log.warn("Path " + + path + + " not found in LDAP, disabling user " + + userProfile.getProperty(ArgeoNames.ARGEO_USER_ID) + .getString()); + VersionManager versionManager = securitySession + .getWorkspace().getVersionManager(); + versionManager.checkout(userProfile.getPath()); userProfile.setProperty(ArgeoNames.ARGEO_ENABLED, false); + securitySession.save(); + versionManager.checkin(userProfile.getPath()); } } } catch (Exception e) { + JcrUtils.discardQuietly(securitySession); throw new ArgeoException("Cannot synchronized LDAP and JCR", e); } } @@ -198,9 +210,9 @@ public class JcrLdapSynchronizer implements UserDetailsContextMapper, final String username, GrantedAuthority[] authorities) { if (ctx == null) throw new ArgeoException("No LDAP information for user " + username); - Node userHome = JcrUtils.getUserHome(securitySession, username); - if (userHome == null) - throw new ArgeoException("No JCR information for user " + username); + Node userProfile = JcrUtils.createUserProfileIfNeeded(securitySession, + username); + JcrUserDetails.checkAccountStatus(userProfile); // password SortedSet passwordAttributes = ctx @@ -216,8 +228,7 @@ public class JcrLdapSynchronizer implements UserDetailsContextMapper, } try { - return new JcrUserDetails(userHome.getNode(ARGEO_PROFILE), - password, authorities); + return new JcrUserDetails(userProfile, password, authorities); } catch (RepositoryException e) { throw new ArgeoException("Cannot retrieve user details for " + username, e); @@ -229,7 +240,7 @@ public class JcrLdapSynchronizer implements UserDetailsContextMapper, * * @return path to user profile */ - protected String mapLdapToJcr(DirContextAdapter ctx) { + protected synchronized String mapLdapToJcr(DirContextAdapter ctx) { Session session = securitySession; try { // process @@ -238,6 +249,20 @@ public class JcrLdapSynchronizer implements UserDetailsContextMapper, Node userProfile; // = userHome.getNode(ARGEO_PROFILE); if (userHome.hasNode(ARGEO_PROFILE)) { userProfile = userHome.getNode(ARGEO_PROFILE); + + // compatibility with legacy, will be removed + if (!userProfile.hasProperty(ARGEO_ENABLED)) { + session.getWorkspace().getVersionManager() + .checkout(userProfile.getPath()); + userProfile.setProperty(ARGEO_ENABLED, true); + userProfile.setProperty(ARGEO_ACCOUNT_NON_EXPIRED, true); + userProfile.setProperty(ARGEO_ACCOUNT_NON_LOCKED, true); + userProfile + .setProperty(ARGEO_CREDENTIALS_NON_EXPIRED, true); + session.save(); + session.getWorkspace().getVersionManager() + .checkin(userProfile.getPath()); + } } else { userProfile = JcrUtils.createUserProfile(securitySession, username);