Fix issues with Jackrabbit
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 25 Jun 2011 08:28:43 +0000 (08:28 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 25 Jun 2011 08:28:43 +0000 (08:28 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4601 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

server/modules/org.argeo.node.repo.jackrabbit/META-INF/MANIFEST.MF
server/modules/org.argeo.node.repo.jackrabbit/META-INF/spring/noderepo-osgi.xml
server/modules/org.argeo.node.repo.jackrabbit/META-INF/spring/noderepo.xml
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java

index de0b81627782d2e2e7ef1584391bba0ffd19c30a..96ba75f7cfe0db3c24e6ebdf24fc96be98804a0b 100644 (file)
@@ -12,6 +12,8 @@ Import-Package: com.mysql.jdbc;version="[5.0.0,6.0.0)";resolution:=optional,
  org.argeo.jackrabbit,
  org.argeo.jcr,
  org.argeo.security,
+ org.argeo.security.core,
  org.h2;version="[1.0.0,2.0.0)";resolution:=optional,
  org.postgresql;version="[8.0.0,9.0.0)";resolution:=optional,
- org.springframework.beans.factory.config
+ org.springframework.beans.factory.config,
+ org.springframework.security;version="2.0.6.RELEASE"
index cc38a3451ecdd538fdbb5d4f5c1eea6bdf152751..f6e210b7c216fa077e3d3665ada31317af309cf3 100644 (file)
@@ -10,7 +10,8 @@
        http://www.springframework.org/schema/util/spring-util-2.5.xsd">\r
 \r
        <!-- REFERENCES -->\r
-       <reference id="systemExecutionService" interface="org.argeo.security.SystemExecutionService" />\r
+       <reference id="authenticationManager"\r
+               interface="org.springframework.security.AuthenticationManager" />\r
 \r
        <!-- SERVICES -->\r
        <service ref="nodeJcrRepository" interface="javax.jcr.Repository">\r
index ec8bfca746b45a413f836073bd35ff4c03027656..02d697b243aa3c7ae87cd5f7d0342b7bee34bcbc 100644 (file)
@@ -11,7 +11,8 @@
                </property>
        </bean>
 
-       <bean id="nodeJcrRepository" class="org.argeo.jackrabbit.JackrabbitContainer">
+       <bean id="nodeJcrRepository" class="org.argeo.jackrabbit.JackrabbitContainer"
+               init-method="init" destroy-method="dispose">
                <property name="uri" value="${argeo.node.repo.uri}" />
                <property name="homeDirectory" value="${argeo.node.repo.home}" />
                <property name="configuration" value="${argeo.node.repo.configuration}" />
                                <value>classpath:/org/argeo/jcr/argeo.cnd</value>
                        </list>
                </property>
-               <property name="systemExecutor" ref="systemExecutionService" />
        </bean>
+
+       <!-- Execute initialization with a system authentication -->
+       <bean
+               class="org.argeo.security.core.AuthenticatedApplicationContextInitialization">
+               <property name="authenticationManager" ref="authenticationManager" />
+       </bean>
+
 </beans>
\ No newline at end of file
index c897b6bea92686774dfc4eaebf489dcc67d32567..d9cf424e63e7155f433b034e2c10d2d5352ad25c 100644 (file)
@@ -171,6 +171,10 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware {
 
        /** Executes migrations, if needed. */
        protected void migrate() {
+               // No migration to perform
+               if (dataModelMigrations.size() == 0)
+                       return;
+
                Boolean restartAndClearCaches = false;
 
                // migrate data
@@ -365,15 +369,15 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware {
 
        // JCR REPOSITORY (delegated)
        public String getDescriptor(String key) {
-               return repository.getDescriptor(key);
+               return getRepository().getDescriptor(key);
        }
 
        public String[] getDescriptorKeys() {
-               return repository.getDescriptorKeys();
+               return getRepository().getDescriptorKeys();
        }
 
        public Session login() throws LoginException, RepositoryException {
-               Session session = repository.login();
+               Session session = getRepository().login();
                processNewSession(session);
                return session;
        }
@@ -383,7 +387,7 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware {
                        RepositoryException {
                Session session;
                try {
-                       session = repository.login(credentials, workspaceName);
+                       session = getRepository().login(credentials, workspaceName);
                } catch (NoSuchWorkspaceException e) {
                        if (autocreateWorkspaces)
                                session = createWorkspaceAndLogsIn(credentials, workspaceName);
@@ -396,7 +400,7 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware {
 
        public Session login(Credentials credentials) throws LoginException,
                        RepositoryException {
-               Session session = repository.login(credentials);
+               Session session = getRepository().login(credentials);
                processNewSession(session);
                return session;
        }
@@ -405,7 +409,7 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware {
                        NoSuchWorkspaceException, RepositoryException {
                Session session;
                try {
-                       session = repository.login(workspaceName);
+                       session = getRepository().login(workspaceName);
                } catch (NoSuchWorkspaceException e) {
                        if (autocreateWorkspaces)
                                session = createWorkspaceAndLogsIn(null, workspaceName);
@@ -416,6 +420,17 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware {
                return session;
        }
 
+       /** Wraps access to the repository, making sure it is available. */
+       protected Repository getRepository() {
+               if (repository == null) {
+                       throw new ArgeoException(
+                                       "No repository initialized."
+                                                       + " Was the init() method called?"
+                                                       + " The dispose() method should also be called on shutdown.");
+               }
+               return repository;
+       }
+
        protected synchronized void processNewSession(Session session) {
                try {
                        NamespaceHelper namespaceHelper = new NamespaceHelper(session);
@@ -433,10 +448,10 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware {
                        String workspaceName) throws RepositoryException {
                if (workspaceName == null)
                        throw new ArgeoException("No workspace specified.");
-               Session session = repository.login(credentials);
+               Session session = getRepository().login(credentials);
                session.getWorkspace().createWorkspace(workspaceName);
                session.logout();
-               return repository.login(credentials, workspaceName);
+               return getRepository().login(credentials, workspaceName);
        }
 
        public void setResourceLoader(ResourceLoader resourceLoader) {
@@ -444,19 +459,19 @@ public class JackrabbitContainer implements Repository, ResourceLoaderAware {
        }
 
        public boolean isStandardDescriptor(String key) {
-               return repository.isStandardDescriptor(key);
+               return getRepository().isStandardDescriptor(key);
        }
 
        public boolean isSingleValueDescriptor(String key) {
-               return repository.isSingleValueDescriptor(key);
+               return getRepository().isSingleValueDescriptor(key);
        }
 
        public Value getDescriptorValue(String key) {
-               return repository.getDescriptorValue(key);
+               return getRepository().getDescriptorValue(key);
        }
 
        public Value[] getDescriptorValues(String key) {
-               return repository.getDescriptorValues(key);
+               return getRepository().getDescriptorValues(key);
        }
 
        // BEANS METHODS