portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r327609 - in /portals/jetspeed-2/trunk/components/security/src: java/org/apache/jetspeed/security/impl/PermissionManagerImpl.java test/org/apache/jetspeed/security/TestPermissionManager.java
Date Fri, 21 Oct 2005 23:36:55 GMT
Author: taylor
Date: Fri Oct 21 16:36:53 2005
New Revision: 327609

URL: http://svn.apache.org/viewcvs?rev=327609&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-384
abstract Permission Manager checkPermission operation
in putting this to use in portlet filtering, 
it seemed easier for user to simply check return status instead of exceptions everytime

Modified:
    portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/PermissionManagerImpl.java
    portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/TestPermissionManager.java

Modified: portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/PermissionManagerImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/PermissionManagerImpl.java?rev=327609&r1=327608&r2=327609&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/PermissionManagerImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/java/org/apache/jetspeed/security/impl/PermissionManagerImpl.java
Fri Oct 21 16:36:53 2005
@@ -438,20 +438,24 @@
         return internalPermission;
     }
     
-    public void checkPermission(Subject subject, final Permission permission) 
-    throws SecurityException
+    public boolean checkPermission(Subject subject, final Permission permission) 
     {
-        //Subject.doAs(subject, new PrivilegedAction()
-        Subject.doAsPrivileged(subject, new PrivilegedAction()                
+        try
         {
-            public Object run()
+            //Subject.doAs(subject, new PrivilegedAction()
+            Subject.doAsPrivileged(subject, new PrivilegedAction()                
             {
-                AccessController.checkPermission(permission);
-                System.out.println("tst with policy: " + 
-                        Policy.getPolicy().getClass().getName());                
-                return null;
-            }
-        }, null);
-        System.out.println("Did not deny access for perm " + permission);         
+                public Object run()
+                {
+                    AccessController.checkPermission(permission);
+                    return null;
+                }
+            }, null);
+        }
+        catch (Exception e)
+        {
+            return false;
+        }
+        return true;         
     }
 }

Modified: portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/TestPermissionManager.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/TestPermissionManager.java?rev=327609&r1=327608&r2=327609&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/TestPermissionManager.java
(original)
+++ portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/TestPermissionManager.java
Fri Oct 21 16:36:53 2005
@@ -108,21 +108,22 @@
         principals.add(user);
         principals.add(role1);
         principals.add(role2);
-        boolean failNow = true;
+
         try
         {
             Subject subject = new Subject(true, principals, publicCredentials, privateCredentials);
       
-            pms.checkPermission(subject, perm1);
-            pms.checkPermission(subject, perm2);
-            pms.checkPermission(subject, perm3);
-            failNow = false;
-            pms.checkPermission(subject, perm3a);
-            fail("should have failed permission check on perm3a");
+            boolean access = pms.checkPermission(subject, perm1);
+            assertTrue("access to perm1 should be granted ", access);
+            access = pms.checkPermission(subject, perm2);
+            assertTrue("access to perm2 should be granted ", access);
+            access = pms.checkPermission(subject, perm3);
+            assertTrue("access to perm3 should be granted ", access);
+            access = pms.checkPermission(subject, perm3a);
+            assertFalse("access to perm3a should be denied ", access);
         }
         catch (AccessControlException e)
         {
-            if (failNow)
-                fail("failed permission check");
+            fail("failed permission check");
         }
         finally
         {



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message