From: Mathieu Baudier Date: Sun, 2 Oct 2011 17:52:34 +0000 (+0000) Subject: Male LDAP security DAO initialization more robust X-Git-Tag: argeo-commons-2.1.30~1128 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=01d5597f584ac37c81b5a9f6b3cdcf77a487c904;hp=70538e1286a2b47ecd58cb1cfb7ede8dddff5859;p=lgpl%2Fargeo-commons.git Male LDAP security DAO initialization more robust git-svn-id: https://svn.argeo.org/commons/trunk@4773 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/security/modules/org.argeo.security.dao.ldap/META-INF/spring/ldap-jcr.xml b/security/modules/org.argeo.security.dao.ldap/META-INF/spring/ldap-jcr.xml index 8e0ebc052..d8a78c1b5 100644 --- a/security/modules/org.argeo.security.dao.ldap/META-INF/spring/ldap-jcr.xml +++ b/security/modules/org.argeo.security.dao.ldap/META-INF/spring/ldap-jcr.xml @@ -58,7 +58,7 @@ - + diff --git a/security/modules/org.argeo.security.dao.ldap/META-INF/spring/ldap-osgi.xml b/security/modules/org.argeo.security.dao.ldap/META-INF/spring/ldap-osgi.xml index 69931f574..f67cfb492 100644 --- a/security/modules/org.argeo.security.dao.ldap/META-INF/spring/ldap-osgi.xml +++ b/security/modules/org.argeo.security.dao.ldap/META-INF/spring/ldap-osgi.xml @@ -7,8 +7,11 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + + + diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrCallback.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrCallback.java index 5901497a3..f8195a46d 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrCallback.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/JcrCallback.java @@ -1,6 +1,5 @@ package org.argeo.jcr; -import javax.jcr.RepositoryException; import javax.jcr.Session; /** An arbitrary execution on a JCR session, optionally returning a result. */ diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java index 003bcc69b..8adbae784 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/ThreadBoundJcrSessionFactory.java @@ -43,6 +43,8 @@ public abstract class ThreadBoundJcrSessionFactory { .getLog(ThreadBoundJcrSessionFactory.class); private Repository repository; + /** can be injected as list, only used if repository is null */ + private List repositories; private ThreadLocal session = new ThreadLocal(); private final Session proxiedSession; @@ -88,7 +90,7 @@ public abstract class ThreadBoundJcrSessionFactory { // Security) if (!forceDefaultCredentials) try { - newSession = repository.login(workspace); + newSession = repository().login(workspace); } catch (LoginException e1) { log.warn("Cannot login without credentials: " + e1.getMessage()); // invalid credentials, go to the next step @@ -102,7 +104,7 @@ public abstract class ThreadBoundJcrSessionFactory { try { SimpleCredentials sc = new SimpleCredentials(defaultUsername, defaultPassword.toCharArray()); - newSession = repository.login(sc, workspace); + newSession = repository().login(sc, workspace); } catch (RepositoryException e) { throw new ArgeoException("Cannot log in to repository", e); } @@ -202,10 +204,36 @@ public abstract class ThreadBoundJcrSessionFactory { return session; } + protected Repository repository() { + if (repository != null) + return repository; + if (repositories != null) { + // hardened for OSGi dynamic services + Iterator it = repositories.iterator(); + if (it.hasNext()) + return it.next(); + } + throw new ArgeoException("No repository injected"); + } + + // /** Useful for declarative registration of OSGi services (blueprint) */ + // public void register(Repository repository, Map params) { + // this.repository = repository; + // } + // + // /** Useful for declarative registration of OSGi services (blueprint) */ + // public void unregister(Repository repository, Map params) { + // this.repository = null; + // } + public void setRepository(Repository repository) { this.repository = repository; } + public void setRepositories(List repositories) { + this.repositories = repositories; + } + public void setDefaultUsername(String defaultUsername) { this.defaultUsername = defaultUsername; }