portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r329116 - /portals/jetspeed-2/trunk/components/security/src/test/org/apache/jetspeed/security/TestPermissionManager.java
Date Fri, 28 Oct 2005 06:15:32 GMT
Author: taylor
Date: Thu Oct 27 23:15:29 2005
New Revision: 329116

URL: http://svn.apache.org/viewcvs?rev=329116&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-384
tests

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

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=329116&r1=329115&r2=329116&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
Thu Oct 27 23:15:29 2005
@@ -65,6 +65,101 @@
         return new TestSuite(TestPermissionManager.class);
     }
 
+    public void testWildcardPermissionCheck()
+    throws Exception
+    {
+        //////////////////////////////////////////////////////////////////////////
+        // setup
+        ////////////
+        UserPrincipal adminUser = new UserPrincipalImpl("admin");
+        UserPrincipal userUser = new UserPrincipalImpl("user");
+        PortletPermission adminPerm = new PortletPermission("admin::*", "view, edit");
+        PortletPermission userPerm = new PortletPermission("demo::*", "view, edit");
+        RolePrincipal adminRole = new RolePrincipalImpl("admin");
+        RolePrincipal userRole = new RolePrincipalImpl("user");
+        
+        try
+        {
+            ums.addUser(adminUser.getName(), "password");
+            ums.addUser(userUser.getName(), "password");            
+            rms.addRole(adminRole.getName());
+            rms.addRole(userRole.getName());            
+            rms.addRoleToUser(adminUser.getName(), adminRole.getName());
+            rms.addRoleToUser(userUser.getName(), userRole.getName());
+            rms.addRoleToUser(adminUser.getName(), userRole.getName());            
+            pms.addPermission(adminPerm);
+            pms.addPermission(userPerm);
+            pms.grantPermission(adminRole, adminPerm);
+            pms.grantPermission(userRole, userPerm);                        
+        }
+        catch (SecurityException sex)
+        {
+            assertTrue("failed to init testRemovePrincipalPermissions(), " + sex, false);
+        }
+        
+        //////////////////////////////////////////////////////////////////////////
+        // Run Test
+        ////////////        
+        Set adminPrincipals = new PrincipalsSet();
+        Set adminPublicCredentials = new HashSet();
+        Set adminPrivateCredentials = new HashSet();
+        Set userPrincipals = new PrincipalsSet();
+        Set userPublicCredentials = new HashSet();
+        Set userPrivateCredentials = new HashSet();
+        
+        adminPrincipals.add(adminUser);
+        adminPrincipals.add(adminRole);
+        adminPrincipals.add(userRole);
+
+        userPrincipals.add(userUser);
+        userPrincipals.add(userRole);
+        
+        try
+        {
+            Subject adminSubject = new Subject(true, adminPrincipals, adminPublicCredentials,
adminPrivateCredentials);
+            Subject userSubject = new Subject(true, userPrincipals, userPublicCredentials,
userPrivateCredentials);                    
+            
+            boolean access = pms.checkPermission(adminSubject, adminPerm);
+            assertTrue("access to admin Perm should be granted to Admin ", access);
+            
+            access = pms.checkPermission(adminSubject, userPerm);
+            assertTrue("access to user should NOT be granted to Admin ", access);
+
+            access = pms.checkPermission(userSubject, userPerm);
+            assertTrue("access to User Perm should be granted to User ", access);
+            
+            access = pms.checkPermission(userSubject, adminPerm);
+            assertFalse("access to Admin Perm should NOT be granted to User ", access);
+            
+        }
+        catch (AccessControlException e)
+        {
+            fail("failed permission check");
+        }
+        finally
+        {
+            //////////////////////////////////////////////////////////////////////////
+            // cleanup
+            ////////////
+            try
+            {
+                ums.removeUser(adminUser.getName());
+                ums.removeUser(userUser.getName());
+                rms.removeRole(adminRole.getName());
+                rms.removeRole(userRole.getName());
+                
+                pms.removePermission(adminPerm);
+                pms.removePermission(userPerm);
+            }
+            catch (SecurityException sex)
+            {
+                assertTrue("could not remove user and permission. exception caught: " + sex,
false);
+            }            
+        }
+        
+        
+    }
+    
     public void testPermissionCheck()
     throws Exception
     {



---------------------------------------------------------------------
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