jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r758653 - in /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization: ./ acl/ combined/ principalbased/
Date Thu, 26 Mar 2009 14:08:19 GMT
Author: angela
Date: Thu Mar 26 14:07:59 2009
New Revision: 758653

URL: http://svn.apache.org/viewvc?rev=758653&view=rev
Log:
JCR-1588: Access Control

tests: missing session.logout (within tests and in case of failing setup)

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractEvaluationTest.java
Thu Mar 26 14:07:59 2009
@@ -55,13 +55,22 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        UserManager uMgr = getUserManager(superuser);
-
-        // create the testUser
-        String uid = "testUser" + UUID.randomUUID();
-        creds = new SimpleCredentials(uid, uid.toCharArray());
+        if (!isExecutable()) {
+            superuser.logout();
+            throw new NotExecutableException();
+        }
 
-        testUser = uMgr.createUser(uid, uid);
+        try {
+            UserManager uMgr = getUserManager(superuser);
+            // create the testUser
+            String uid = "testUser" + UUID.randomUUID();
+            creds = new SimpleCredentials(uid, uid.toCharArray());
+
+            testUser = uMgr.createUser(uid, uid);
+        } catch (Exception e) {
+            superuser.logout();
+            throw e;
+        }
     }
 
     protected void tearDown() throws Exception {
@@ -122,7 +131,8 @@
         return trn;
     }
 
-    
+    protected abstract boolean isExecutable();
+
     protected void checkReadOnly(String path) throws RepositoryException, NotExecutableException
{
         Privilege[] privs = getTestACManager().getPrivileges(path);
         assertTrue(privs.length == 1);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/AbstractWriteTest.java
Thu Mar 26 14:07:59 2009
@@ -915,8 +915,13 @@
         testUser = null;
 
         // try to retrieve the acl again
-        AccessControlManager acMgr = getAccessControlManager(helper.getSuperuserSession());
-        acMgr.getPolicies(acPath);
+        Session s = helper.getSuperuserSession();
+        try {
+            AccessControlManager acMgr = getAccessControlManager(s);
+            acMgr.getPolicies(acPath);
+        } finally {
+            s.logout();
+        }
     }
 
     private static Node findPolicyNode(Node start) throws RepositoryException {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/JackrabbitAccessControlListTest.java
Thu Mar 26 14:07:59 2009
@@ -55,6 +55,7 @@
             }
         }
         if (templ == null) {
+            superuser.logout();
             throw new NotExecutableException("No JackrabbitAccessControlList to test.");
         }
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/EvaluationUtil.java
Thu Mar 26 14:07:59 2009
@@ -34,6 +34,17 @@
  */
 final class EvaluationUtil {
 
+    static boolean isExecutable(AccessControlManager acMgr) {
+        try {
+            AccessControlPolicy[] rootPolicies = acMgr.getPolicies("/");
+            if (rootPolicies.length > 0 && rootPolicies[0] instanceof ACLTemplate)
{
+                return true;
+            }
+        } catch (RepositoryException e) {
+        }
+        return false;
+    }
+
     static JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path, Principal
principal) throws RepositoryException,
             AccessDeniedException, NotExecutableException {
         // try applicable (new) acls first

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/LockTest.java
Thu Mar 26 14:07:59 2009
@@ -30,6 +30,9 @@
  * <code>LockTest</code>...
  */
 public class LockTest extends AbstractLockManagementTest {
+    protected boolean isExecutable() {
+        return EvaluationUtil.isExecutable(acMgr);
+    }
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acMgr, String path,
Principal princ) throws
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/NodeTypeTest.java
Thu Mar 26 14:07:59 2009
@@ -30,6 +30,9 @@
  * <code>NodeTypeTest</code>...
  */
 public class NodeTypeTest extends AbstractNodeTypeManagementTest {
+    protected boolean isExecutable() {
+        return EvaluationUtil.isExecutable(acMgr);
+    }
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acMgr, String path,
Principal princ) throws
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/VersionTest.java
Thu Mar 26 14:07:59 2009
@@ -30,6 +30,9 @@
  * <code>VersionTest</code>...
  */
 public class VersionTest extends AbstractVersionManagementTest {
+    protected boolean isExecutable() {
+        return EvaluationUtil.isExecutable(acMgr);
+    }
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acMgr, String path,
Principal princ) throws
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/acl/WriteTest.java
Thu Mar 26 14:07:59 2009
@@ -40,16 +40,8 @@
  */
 public class WriteTest extends AbstractWriteTest {
 
-    protected void setUp() throws Exception {
-        super.setUp();
-        try {
-            AccessControlPolicy[] rootPolicies = acMgr.getPolicies("/");
-            if (rootPolicies.length == 0 || !(rootPolicies[0] instanceof ACLTemplate)) {
-                throw new NotExecutableException();
-            }
-        } catch (RepositoryException e) {
-            throw new NotExecutableException();
-        }
+    protected boolean isExecutable() {
+        return EvaluationUtil.isExecutable(acMgr);
     }
 
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path,
Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException
{

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/combined/WriteTest.java
Thu Mar 26 14:07:59 2009
@@ -46,7 +46,12 @@
         super.setUp();
 
         // simple test to check if proper provider is present:
-        getPrincipalBasedPolicy(acMgr, path, getTestUser().getPrincipal());
+        try {
+            getPrincipalBasedPolicy(acMgr, path, getTestUser().getPrincipal());
+        } catch (Exception e) {
+            superuser.logout();
+            throw e;
+        }
     }
 
     private JackrabbitAccessControlList getPrincipalBasedPolicy(AccessControlManager acM,
String path, Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException
{

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/EvaluationUtil.java
Thu Mar 26 14:07:59 2009
@@ -30,14 +30,34 @@
 import java.security.Principal;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Iterator;
 
 /**
  * <code>EvaluationTest</code>...
  */
 class EvaluationUtil {
 
-   static JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path, Principal
principal) throws RepositoryException,
-                AccessDeniedException, NotExecutableException {
+    static boolean isExecutable(SessionImpl s, AccessControlManager acMgr) {
+        if (acMgr instanceof JackrabbitAccessControlManager) {
+            for (Iterator it = s.getSubject().getPrincipals().iterator(); it.hasNext();)
{
+                Principal princ = (Principal) it.next();
+                try {
+                    AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acMgr).getApplicablePolicies(princ);
+                    for (int i = 0; i < policies.length; i++) {
+                        if (policies[i] instanceof ACLTemplate) {
+                            return true;
+                        }
+                    }
+                } catch (RepositoryException e) {
+                    // ignore
+                }
+            }
+        }
+        return false;
+    }
+
+    static JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path, Principal
principal) throws RepositoryException,
+            AccessDeniedException, NotExecutableException {
         if (acM instanceof JackrabbitAccessControlManager) {
             AccessControlPolicy[] policies = ((JackrabbitAccessControlManager) acM).getApplicablePolicies(principal);
             for (int i = 0; i < policies.length; i++) {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/LockTest.java
Thu Mar 26 14:07:59 2009
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.core.security.authorization.AbstractLockManagementTest;
 import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.api.jsr283.security.AccessControlManager;
 import org.apache.jackrabbit.test.NotExecutableException;
 
@@ -30,6 +31,11 @@
  * <code>LockTest</code>...
  */
 public class LockTest extends AbstractLockManagementTest {
+
+    protected boolean isExecutable() {
+        return EvaluationUtil.isExecutable((SessionImpl) superuser, acMgr);
+    }
+
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acMgr, String path,
Principal princ) throws
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/NodeTypeTest.java
Thu Mar 26 14:07:59 2009
@@ -18,6 +18,7 @@
 
 import org.apache.jackrabbit.core.security.authorization.AbstractNodeTypeManagementTest;
 import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.api.jsr283.security.AccessControlManager;
 import org.apache.jackrabbit.test.NotExecutableException;
 
@@ -30,6 +31,11 @@
  * <code>NodeTypeTest</code>...
  */
 public class NodeTypeTest extends AbstractNodeTypeManagementTest {
+
+    protected boolean isExecutable() {
+        return EvaluationUtil.isExecutable((SessionImpl) superuser, acMgr);
+    }
+    
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acMgr, String path,
Principal princ) throws
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/VersionTest.java
Thu Mar 26 14:07:59 2009
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
 import org.apache.jackrabbit.core.security.authorization.AbstractVersionManagementTest;
 import org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry;
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.api.jsr283.security.AccessControlManager;
 import org.apache.jackrabbit.api.jsr283.security.Privilege;
 import org.apache.jackrabbit.test.NotExecutableException;
@@ -42,6 +43,10 @@
 
     private static String VERSION_STORAGE_PATH = "/jcr:system/jcr:versionStorage";
 
+    protected boolean isExecutable() {
+        return EvaluationUtil.isExecutable((SessionImpl) superuser, acMgr);
+    }
+    
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acMgr, String path,
Principal princ) throws
             RepositoryException, NotExecutableException {
         return EvaluationUtil.getPolicy(acMgr, path, princ);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java?rev=758653&r1=758652&r2=758653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/principalbased/WriteTest.java
Thu Mar 26 14:07:59 2009
@@ -42,11 +42,8 @@
 
     private static Logger log = LoggerFactory.getLogger(WriteTest.class);
 
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        // simple test to check if proper provider is present:
-        getPolicy(acMgr, path, getTestUser().getPrincipal());
+    protected boolean isExecutable() {
+        return EvaluationUtil.isExecutable((SessionImpl) superuser, acMgr);
     }
 
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path,
Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException
{



Mime
View raw message