From d13caecab3c8add8392443c9c28ad42626a10816 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Fri, 16 Nov 2012 12:13:00 +0000 Subject: [PATCH] Make security start up more robust git-svn-id: https://svn.argeo.org/commons/trunk@5849 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../ldap/jcr/JcrLdapSynchronizer.java | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) 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 }; -- 2.30.2