From: Mathieu Baudier Date: Fri, 16 Nov 2012 12:13:00 +0000 (+0000) Subject: Make security start up more robust X-Git-Tag: argeo-commons-2.1.30~740 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=d13caecab3c8add8392443c9c28ad42626a10816;p=lgpl%2Fargeo-commons.git Make security start up more robust git-svn-id: https://svn.argeo.org/commons/trunk@5849 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- 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 c8d8adc19..6210c6745 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 @@ -121,22 +121,32 @@ public class JcrLdapSynchronizer implements UserDetailsContextMapper, try { nodeSession = repository.login(); - synchronize(); - - // LDAP - subTreeSearchControls = new SearchControls(); - subTreeSearchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); - // LDAP listener - ldapUserListener = new LdapUserListener(); - rawLdapTemplate.executeReadOnly(new ContextExecutor() { - public Object executeWithContext(DirContext ctx) - throws NamingException { - EventDirContext ectx = (EventDirContext) ctx.lookup(""); - ectx.addNamingListener(userBase, "(" + usernameAttribute - + "=*)", subTreeSearchControls, ldapUserListener); - return null; - } - }); + // TODO put this in a different thread, and poll the LDAP server + // until it is up + try { + synchronize(); + + // LDAP + subTreeSearchControls = new SearchControls(); + subTreeSearchControls + .setSearchScope(SearchControls.SUBTREE_SCOPE); + // LDAP listener + ldapUserListener = new LdapUserListener(); + rawLdapTemplate.executeReadOnly(new ContextExecutor() { + public Object executeWithContext(DirContext ctx) + throws NamingException { + EventDirContext ectx = (EventDirContext) ctx.lookup(""); + ectx.addNamingListener(userBase, "(" + + usernameAttribute + "=*)", + subTreeSearchControls, ldapUserListener); + return null; + } + }); + } catch (Exception e) { + log.error("Could not synchronize and listen to LDAP," + + " probably because the LDAP server is not available." + + " Restart the system as soon as possible.", e); + } // JCR String[] nodeTypes = { ArgeoTypes.ARGEO_USER_PROFILE };