jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r736276 - in /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization: AbstractEvaluationTest.java AbstractWriteTest.java acl/WriteTest.java combined/WriteTest.java principalbased/WriteTest.java
Date Wed, 21 Jan 2009 09:59:03 GMT
Author: angela
Date: Wed Jan 21 01:59:02 2009
New Revision: 736276

URL: http://svn.apache.org/viewvc?rev=736276&view=rev
Log:
JCR-1588: JSR 283: Access Control (some minor test clean up)

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/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/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=736276&r1=736275&r2=736276&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
Wed Jan 21 01:59:02 2009
@@ -71,11 +71,11 @@
                 AccessControlPolicy[] policies = acMgr.getPolicies(path);
                 for (int i = 0; i < policies.length; i++) {
                     acMgr.removePolicy(path, policies[i]);
-                    superuser.save();
                 }
+                superuser.save();                
             } catch (RepositoryException e) {
                 // log error and ignore
-                log.error(e.getMessage());
+                log.debug(e.getMessage());
             }
         }
 
@@ -133,8 +133,13 @@
     protected abstract Map getRestrictions(Session session, String path) throws RepositoryException,
NotExecutableException;
 
     protected JackrabbitAccessControlList modifyPrivileges(String path, String privilege,
boolean isAllow) throws NotExecutableException, RepositoryException {
-        JackrabbitAccessControlList tmpl = getPolicy(acMgr, path, testUser.getPrincipal());
-        tmpl.addEntry(testUser.getPrincipal(), privilegesFromName(privilege), isAllow, getRestrictions(superuser,
path));
+        return modifyPrivileges(path, testUser.getPrincipal(), privilegesFromName(privilege),
isAllow, getRestrictions(superuser, path));
+    }
+
+    private JackrabbitAccessControlList modifyPrivileges(String path, Principal principal,
Privilege[] privileges, boolean isAllow, Map restrictions) throws NotExecutableException,
RepositoryException {
+        JackrabbitAccessControlList tmpl = getPolicy(acMgr, path, principal);
+        tmpl.addEntry(principal, privileges, isAllow, restrictions);
+        
         acMgr.setPolicy(tmpl.getPath(), tmpl);
         superuser.save();
 
@@ -142,4 +147,22 @@
         toClear.add(tmpl.getPath());
         return tmpl;
     }
+
+    protected JackrabbitAccessControlList givePrivileges(String nPath, Privilege[] privileges,
+                                                         Map restrictions) throws NotExecutableException,
RepositoryException {
+        return modifyPrivileges(nPath, testUser.getPrincipal(), privileges, true, restrictions);
+    }
+
+    protected JackrabbitAccessControlList givePrivileges(String nPath, Principal principal,
+                                                         Privilege[] privileges, Map restrictions)
throws NotExecutableException, RepositoryException {
+        return modifyPrivileges(nPath, principal, privileges, true, restrictions);
+    }
+
+    protected JackrabbitAccessControlList withdrawPrivileges(String nPath, Privilege[] privileges,
Map restrictions) throws NotExecutableException, RepositoryException {
+        return modifyPrivileges(nPath, testUser.getPrincipal(), privileges, false, restrictions);
+    }
+
+    protected JackrabbitAccessControlList withdrawPrivileges(String nPath, Principal principal,
Privilege[] privileges, Map restrictions) throws NotExecutableException, RepositoryException
{
+        return modifyPrivileges(nPath, principal, privileges, false, restrictions);
+    }
 }
\ No newline at end of file

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=736276&r1=736275&r2=736276&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
Wed Jan 21 01:59:02 2009
@@ -40,7 +40,6 @@
 import javax.jcr.observation.Event;
 import javax.jcr.observation.ObservationManager;
 import java.security.Principal;
-import java.util.Map;
 
 /**
  * <code>AbstractEvaluationTest</code>...
@@ -86,7 +85,6 @@
 
     protected void tearDown() throws Exception {
         // make sure all ac info is removed
-        clearACInfo();
         if (testGroup != null && testUser != null) {
             testGroup.removeMember(testUser);
             testGroup.remove();
@@ -94,34 +92,6 @@
         super.tearDown();
     }
 
-    protected abstract void clearACInfo();
-
-    protected JackrabbitAccessControlList givePrivileges(String nPath, Privilege[] privileges,
-                                                         Map restrictions) throws NotExecutableException,
RepositoryException {
-        return givePrivileges(nPath, testUser.getPrincipal(), privileges, restrictions);
-    }
-
-    protected JackrabbitAccessControlList givePrivileges(String nPath, Principal principal,
-                                                         Privilege[] privileges, Map restrictions)
throws NotExecutableException, RepositoryException {
-        JackrabbitAccessControlList tmpl = getPolicy(acMgr, nPath, principal);
-        tmpl.addEntry(principal, privileges, true, restrictions);
-        acMgr.setPolicy(tmpl.getPath(), tmpl);
-        superuser.save();
-        return tmpl;
-    }
-
-    protected JackrabbitAccessControlList withdrawPrivileges(String nPath, Privilege[] privileges,
Map restrictions) throws NotExecutableException, RepositoryException {
-        return withdrawPrivileges(nPath, testUser.getPrincipal(), privileges, restrictions);
-    }
-
-    protected JackrabbitAccessControlList withdrawPrivileges(String nPath, Principal principal,
Privilege[] privileges, Map restrictions) throws NotExecutableException, RepositoryException
{
-        JackrabbitAccessControlList tmpl = getPolicy(acMgr, nPath, principal);
-        tmpl.addEntry(principal, privileges, false, restrictions);
-        acMgr.setPolicy(tmpl.getPath(), tmpl);
-        superuser.save();
-        return tmpl;
-    }
-
     protected User getTestUser() {
         return testUser;
     }

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=736276&r1=736275&r2=736276&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
Wed Jan 21 01:59:02 2009
@@ -50,11 +50,6 @@
         }
     }
 
-    protected void clearACInfo() {
-        // nop since ac information is stored with nodes that get removed
-        // during the general tear-down.
-    }
-
     protected JackrabbitAccessControlList getPolicy(AccessControlManager acM, String path,
Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException
{
         AccessControlPolicyIterator it = acM.getApplicablePolicies(path);
         while (it.hasNext()) {

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=736276&r1=736275&r2=736276&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
Wed Jan 21 01:59:02 2009
@@ -31,11 +31,8 @@
 import javax.jcr.AccessDeniedException;
 import javax.jcr.RepositoryException;
 import java.security.Principal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 
 /**
  * <code>EvaluationTest</code>...
@@ -44,8 +41,6 @@
 
     private static Logger log = LoggerFactory.getLogger(WriteTest.class);
 
-    private List toClear = new ArrayList();
-
     protected void setUp() throws Exception {
         super.setUp();
 
@@ -53,29 +48,12 @@
         getPrincipalBasedPolicy(acMgr, path, getTestUser().getPrincipal());
     }
 
-    protected void clearACInfo() {
-        for (Iterator it = toClear.iterator(); it.hasNext();) {
-            String path = it.next().toString();
-            try {
-                AccessControlPolicy[] policies = acMgr.getPolicies(path);
-                for (int i = 0; i < policies.length; i++) {
-                    acMgr.removePolicy(path, policies[i]);
-                    superuser.save();
-                }
-            } catch (RepositoryException e) {
-                // log error and ignore
-                log.error(e.getMessage());
-            }
-        }
-    }
-
     private JackrabbitAccessControlList getPrincipalBasedPolicy(AccessControlManager acM,
String path, Principal principal) throws RepositoryException, AccessDeniedException, NotExecutableException
{
         if (acM instanceof JackrabbitAccessControlManager) {
             AccessControlPolicy[] tmpls = ((JackrabbitAccessControlManager) acM).getApplicablePolicies(principal);
             for (int i = 0; i < tmpls.length; i++) {
                 if (tmpls[i] instanceof JackrabbitAccessControlList) {
                     JackrabbitAccessControlList acl = (JackrabbitAccessControlList) tmpls[i];
-                    toClear.add(acl.getPath());
                     return acl;
                 }
             }
@@ -95,8 +73,6 @@
             tmpl.addEntry(principal, privileges, true, restrictions);
             acMgr.setPolicy(tmpl.getPath(), tmpl);
             superuser.save();
-            // remember for teardown
-            toClear.add(tmpl.getPath());
             return tmpl;
         }
     }
@@ -113,8 +89,6 @@
             tmpl.addEntry(principal, privileges, false, restrictions);
             acMgr.setPolicy(tmpl.getPath(), tmpl);
             superuser.save();
-            // remember for teardown
-            toClear.add(tmpl.getPath());
             return tmpl;
         }
     }

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=736276&r1=736275&r2=736276&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
Wed Jan 21 01:59:02 2009
@@ -16,28 +16,25 @@
  */
 package org.apache.jackrabbit.core.security.authorization.principalbased;
 
+import org.apache.jackrabbit.api.jsr283.security.AccessControlManager;
+import org.apache.jackrabbit.api.jsr283.security.AccessControlPolicy;
+import org.apache.jackrabbit.api.jsr283.security.Privilege;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.security.JackrabbitAccessControlManager;
 import org.apache.jackrabbit.core.security.authorization.AbstractWriteTest;
 import org.apache.jackrabbit.core.security.authorization.JackrabbitAccessControlList;
 import org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry;
-import org.apache.jackrabbit.core.security.JackrabbitAccessControlManager;
-import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.test.NotExecutableException;
-import org.apache.jackrabbit.api.jsr283.security.AccessControlManager;
-import org.apache.jackrabbit.api.jsr283.security.AccessControlPolicy;
-import org.apache.jackrabbit.api.jsr283.security.Privilege;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.RepositoryException;
 import javax.jcr.AccessDeniedException;
-import javax.jcr.Session;
 import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import java.security.Principal;
-import java.util.Map;
 import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Map;
 
 /**
  * <code>EvaluationTest</code>...
@@ -46,8 +43,6 @@
 
     private static Logger log = LoggerFactory.getLogger(WriteTest.class);
 
-    private List toClear = new ArrayList();
-
     protected void setUp() throws Exception {
         super.setUp();
 
@@ -55,29 +50,12 @@
         getPolicy(acMgr, path, getTestUser().getPrincipal());
     }
 
-    protected void clearACInfo() {
-        for (Iterator it = toClear.iterator(); it.hasNext();) {
-            String path = it.next().toString();
-            try {
-                AccessControlPolicy[] policies = acMgr.getPolicies(path);
-                for (int i = 0; i < policies.length; i++) {
-                    acMgr.removePolicy(path, policies[i]);
-                    superuser.save();
-                }
-            } catch (RepositoryException e) {
-                // log error and ignore
-                log.error(e.getMessage());
-            }
-        }
-    }
-
     protected 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++) {
                 if (policies[i] instanceof ACLTemplate) {
                     ACLTemplate acl = (ACLTemplate) policies[i];
-                    toClear.add(acl.getPath());
                     return acl;
                 }
             }



Mime
View raw message