Improve inital Jackrabbit login
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 30 Mar 2011 12:27:07 +0000 (12:27 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 30 Mar 2011 12:27:07 +0000 (12:27 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4404 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

security/modules/org.argeo.security.dao.jackrabbit/META-INF/spring/jcrsecuritydao-osgi.xml
security/modules/org.argeo.security.dao.jackrabbit/security.properties
security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/OsAuthenticationProvider.java
server/modules/org.argeo.node.repo.jackrabbit/META-INF/spring/noderepo-osgi.xml
server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitContainer.java

index 21d316f169bc883c2918840bfeb8aee0aa37d6e6..2797fd975017705aa81990a1cfc8d988362f72e4 100644 (file)
@@ -16,7 +16,7 @@
                        unbind-method="unregister" />\r
        </reference>\r
        <reference id="nodeRepository" interface="javax.jcr.Repository"\r
-               filter="(argeo.jcr.repository.alias=node)" cardinality="0..1">\r
+               filter="(argeo.jcr.repository.alias=${org.argeo.node.repo.alias})" cardinality="0..1">\r
                <listener ref="osJcrAuthenticationProvider" bind-method="register"\r
                        unbind-method="unregister" />\r
        </reference>\r
index ae7aa87255c7fa30407b417fa351fb241cd1384c..9397ba9deed0065483939e8f982f5b92e1631e05 100644 (file)
@@ -1 +1,2 @@
 argeo.security.systemKey=argeo
+org.argeo.node.repo.alias=node
index fa70489fc4397b2f64e60358f9c185ea042cb62e..524e73f8f7cdf4d440d7eb7b5e0fc89aab492868 100644 (file)
@@ -1,18 +1,14 @@
 package org.argeo.security.core;
 
-import java.security.AccessController;
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.security.auth.Subject;
-
 import org.argeo.security.OsAuthenticationToken;
 import org.springframework.security.Authentication;
 import org.springframework.security.AuthenticationException;
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
 import org.springframework.security.providers.AuthenticationProvider;
-import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
 
 /** Validates an OS authentication. */
 public class OsAuthenticationProvider implements AuthenticationProvider {
@@ -24,22 +20,8 @@ public class OsAuthenticationProvider implements AuthenticationProvider {
 
        public Authentication authenticate(Authentication authentication)
                        throws AuthenticationException {
-               final OsAuthenticationToken oat;
-               // if (authentication instanceof UsernamePasswordAuthenticationToken) {
-               // Subject subject = Subject.getSubject(AccessController.getContext());
-               // if (subject == null)
-               // return null;
-               // oat = new OsAuthenticationToken();
-               // } else
-               if (authentication instanceof OsAuthenticationToken) {
-                       oat = (OsAuthenticationToken) authentication;
-               } else {
+               if (!(authentication instanceof OsAuthenticationToken))
                        return null;
-               }
-
-               // not OS authenticated
-//             if (oat.getUser() == null)
-//                     return null;
 
                List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
                auths.add(new GrantedAuthorityImpl(osUserRole));
@@ -59,6 +41,10 @@ public class OsAuthenticationProvider implements AuthenticationProvider {
                this.osUserRole = osUserRole;
        }
 
+       public void setUserRole(String userRole) {
+               this.userRole = userRole;
+       }
+
        public void setAdminRole(String adminRole) {
                this.adminRole = adminRole;
        }
index c926720f45a37cb31cfd44b643acceb28de482f1..cc38a3451ecdd538fdbb5d4f5c1eea6bdf152751 100644 (file)
@@ -9,7 +9,7 @@
        http://www.springframework.org/schema/util\r
        http://www.springframework.org/schema/util/spring-util-2.5.xsd">\r
 \r
-       <!-- REFERENCE -->\r
+       <!-- REFERENCES -->\r
        <reference id="systemExecutionService" interface="org.argeo.security.SystemExecutionService" />\r
 \r
        <!-- SERVICES -->\r
index 6f50f735821d5821417ea871b75a5b0972788513..0ad12327fc47f5168133d208892c99dd94c3984a 100644 (file)
@@ -90,6 +90,12 @@ public class JackrabbitContainer implements InitializingBean, DisposableBean,
        private Credentials adminCredentials;
 
        public void afterPropertiesSet() throws Exception {
+               if (repository != null) {
+                       // we are just wrapping another repository
+                       importNodeTypeDefinitions(repository);
+                       return;
+               }
+
                // remote repository
                if (uri != null && !uri.trim().equals("")) {
                        Map<String, String> params = new HashMap<String, String>();
@@ -171,9 +177,11 @@ public class JackrabbitContainer implements InitializingBean, DisposableBean,
        protected void importNodeTypeDefinitions(final Repository repository) {
                final Credentials credentialsToUse;
                if (systemExecutor == null) {
-                       if (adminCredentials == null)
-                               throw new ArgeoException(
-                                               "No system executor or admin credentials found");
+                       if (adminCredentials == null) {
+                               log.error("No system executor or admin credentials found,"
+                                               + " cannot import node types");
+                               return;
+                       }
                        credentialsToUse = adminCredentials;
                } else {
                        credentialsToUse = null;
@@ -371,4 +379,8 @@ public class JackrabbitContainer implements InitializingBean, DisposableBean,
                this.adminCredentials = adminCredentials;
        }
 
+       public void setRepository(Repository repository) {
+               this.repository = repository;
+       }
+
 }