Make security start up more robust
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 16 Nov 2012 12:13:00 +0000 (12:13 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 16 Nov 2012 12:13:00 +0000 (12:13 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@5849 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrLdapSynchronizer.java

index c8d8adc1968859e09d6d3dc77318a5259f730b4f..6210c6745d9a332819c06fca400f131c05c49785 100644 (file)
@@ -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 };