Use versions 1.1.3
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 23 Mar 2011 18:13:10 +0000 (18:13 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 23 Mar 2011 18:13:10 +0000 (18:13 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4353 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

pom.xml
security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java
security/runtime/org.argeo.security.jackrabbit/src/main/java/org/argeo/security/jackrabbit/ArgeoLoginModule.java
security/runtime/org.argeo.security.jackrabbit/src/main/java/org/argeo/security/jackrabbit/ArgeoSecurityManager.java
security/runtime/org.argeo.security.jackrabbit/src/main/java/org/argeo/security/jackrabbit/GrantedAuthorityPrincipal.java
server/plugins/org.argeo.jcr.ui.explorer/plugin.xml

diff --git a/pom.xml b/pom.xml
index 2cf560d380346364a3d7100c2f7012ea0bfc2217..6cd3dd046a7320a9aa682a902e5fb24cef293bb8 100644 (file)
--- a/pom.xml
+++ b/pom.xml
        <packaging>pom</packaging>
        <properties>
                <developmentCycle>0.2</developmentCycle>
-               <version.argeo-distribution>1.1.3-SNAPSHOT</version.argeo-distribution>
+               <version.argeo-distribution>1.1.3</version.argeo-distribution>
                <version.argeo-commons>0.2.3-SNAPSHOT</version.argeo-commons>
                <version.argeo-ria>0.12.5</version.argeo-ria>
                <version.equinox>3.6.1</version.equinox>
-               <version.maven-argeo-osgi>0.1.31-SNAPSHOT</version.maven-argeo-osgi>
+               <version.maven-argeo-osgi>0.1.31</version.maven-argeo-osgi>
                <version.maven-bundle-plugin>2.2.0</version.maven-bundle-plugin>
                <version.maven-argeo-qooxdoo>1.1.1</version.maven-argeo-qooxdoo>
                <site.repoBase>file:///srv/projects/www/commons/site</site.repoBase>
index a02221e323ce7dba34de0b03e46f5e5b8137948c..3235a9602bdad53f8aed8dcfe05765644353fdf1 100644 (file)
@@ -1,5 +1,9 @@
 package org.argeo.security.core;
 
+import java.security.AccessController;
+
+import javax.security.auth.Subject;
+
 import org.argeo.ArgeoException;
 import org.argeo.security.SystemExecutionService;
 import org.springframework.core.task.SimpleAsyncTaskExecutor;
@@ -39,12 +43,21 @@ public class KeyBasedSystemExecutionService implements SystemExecutionService,
                                                .getContext();
                                Authentication currentAuth = securityContext
                                                .getAuthentication();
-                               if (currentAuth != null) {
+                               if (currentAuth != null)
                                        throw new ArgeoException(
                                                        "System execution on an already authenticated thread: "
                                                                        + currentAuth + ", THREAD="
                                                                        + Thread.currentThread().getId());
-                               }
+
+                               Subject subject = Subject.getSubject(AccessController
+                                               .getContext());
+                               if (subject != null
+                                               && !subject.getPrincipals(Authentication.class)
+                                                               .isEmpty())
+                                       throw new ArgeoException(
+                                                       "There is already an authenticated subject: "
+                                                                       + subject);
+
                                Authentication auth = authenticationManager
                                                .authenticate(new InternalAuthentication(
                                                                systemAuthenticationKey));
index a83b6d56b4e9a5708925d5d1ffec302b4dfec958..f30af7060e295bac7260a5d99d0cba8526243728 100644 (file)
@@ -37,13 +37,22 @@ public class ArgeoLoginModule extends AbstractLoginModule {
        }
 
        protected Set<Principal> getPrincipals() {
+               // clear already registered Jackrabbit principals
+               clearPrincipals(AdminPrincipal.class);
+               clearPrincipals(AnonymousPrincipal.class);
+               clearPrincipals(GrantedAuthorityPrincipal.class);
+
+               return syncPrincipals();
+       }
+
+       protected Set<Principal> syncPrincipals() {
                // use linked HashSet instead of HashSet in order to maintain the order
                // of principals (as in the Subject).
-               Set<Principal> principals = new LinkedHashSet<Principal>();
-               principals.add(principal);
-
                org.springframework.security.Authentication authen = (org.springframework.security.Authentication) principal;
 
+               Set<Principal> principals = new LinkedHashSet<Principal>();
+               principals.add(authen);
+
                if (authen instanceof SystemAuthentication)
                        principals.add(new AdminPrincipal(authen.getName()));
                else if (authen instanceof AnonymousAuthenticationToken)
@@ -56,6 +65,11 @@ public class ArgeoLoginModule extends AbstractLoginModule {
                                        principals.add(new AdminPrincipal(authen.getName()));
                        }
 
+               // remove previous credentials
+               Set<SimpleCredentials> thisCredentials = subject
+                               .getPublicCredentials(SimpleCredentials.class);
+               if (thisCredentials != null)
+                       thisCredentials.clear();
                // override credentials since we did not used the one passed to us
                credentials = new SimpleCredentials(authen.getName(), authen
                                .getCredentials().toString().toCharArray());
@@ -73,10 +87,12 @@ public class ArgeoLoginModule extends AbstractLoginModule {
                clearPrincipals(AdminPrincipal.class);
                clearPrincipals(AnonymousPrincipal.class);
                clearPrincipals(GrantedAuthorityPrincipal.class);
-               Set<SimpleCredentials> thisCredentials = subject
-                               .getPublicCredentials(SimpleCredentials.class);
-               if (thisCredentials != null)
-                       thisCredentials.clear();
+
+               // we resync with Spring Security since the subject may have been reused
+               // in beetween
+               // TODO: check if this is clean
+               subject.getPrincipals().addAll(syncPrincipals());
+
                return true;
        }
 
index 6b58c6f6903fcec70f7b0e5d8174d4f45be264e3..1838dd05ef14741cc768eeea81a9d8062b52cf8b 100644 (file)
@@ -6,20 +6,14 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import javax.jcr.AccessDeniedException;
 import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.lock.LockException;
-import javax.jcr.security.AccessControlException;
 import javax.jcr.security.AccessControlList;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.security.AccessControlPolicy;
 import javax.jcr.security.AccessControlPolicyIterator;
 import javax.jcr.security.Privilege;
-import javax.jcr.version.VersionException;
 import javax.security.auth.Subject;
 
 import org.apache.commons.logging.Log;
index bf2eff60a70adb3367e465b60b50d2d771d38a16..4e9b87abd5e1851a94dc63b4d7ac30edf19260dd 100644 (file)
@@ -17,4 +17,16 @@ class GrantedAuthorityPrincipal implements Principal {
                return grantedAuthority.getAuthority();
        }
 
+       @Override
+       public int hashCode() {
+               return getName().hashCode();
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (!(obj instanceof GrantedAuthorityPrincipal))
+                       return false;
+               return getName().equals(((GrantedAuthorityPrincipal) obj).getName());
+       }
+
 }
index 5fc087c78c0f1599b7c414f0aa8e8c868d65de95..ad403464d15a33ccd990613cd0c24a311e600b2f 100644 (file)
      </command>
   </menuContribution>
        </extension>
+  <extension
+           point="org.eclipse.ui.activities">
+        <activity
+              description="Only for admins"
+              id="org.argeo.jcr.ui.explorer.adminActivity"
+              name="Admin">
+                 <enabledWhen>
+                   <with variable="roles">
+                     <iterate ifEmpty="false" operator="or">
+                       <equals value="ROLE_ADMIN" />
+                     </iterate>
+                   </with>
+                 </enabledWhen>
+        </activity>
+        <!-- TODO: find a way to exclude evrything -->
+        <activityPatternBinding
+              activityId="org.argeo.jcr.ui.explorer.adminActivity"
+              isEqualityPattern="true"
+              pattern="org.argeo.jcr.ui.explorer/org.argeo.jcr.ui.explorer.perspective">
+        </activityPatternBinding>
+     </extension>
 </plugin>