Keep improving security
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.ldap / src / main / java / org / argeo / security / ldap / jcr / JcrUserDetailsContextMapper.java
index 6b166d5c5613dfd58483ccc2382758d40e2e5c1a..6b729a19b5db255bb7367becb139ef601c17df7e 100644 (file)
@@ -75,8 +75,11 @@ public class JcrUserDetailsContextMapper implements UserDetailsContextMapper,
 
                if (SecurityContextHolder.getContext().getAuthentication() == null) {
                        // authentication
-                       systemExecutor.execute(action);
-                       JcrUtils.logoutQuietly(session);
+                       try {
+                               systemExecutor.execute(action);
+                       } finally {
+                               JcrUtils.logoutQuietly(session);
+                       }
                } else {
                        // authenticated user
                        action.run();
@@ -120,7 +123,7 @@ public class JcrUserDetailsContextMapper implements UserDetailsContextMapper,
                        if (log.isDebugEnabled())
                                log.debug("Mapped " + ctx.getDn() + " to " + userProfile);
                        return userHomePath;
-               } catch (RepositoryException e) {
+               } catch (Exception e) {
                        JcrUtils.discardQuietly(session);
                        throw new ArgeoException("Cannot synchronize JCR and LDAP", e);
                } finally {