directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 9638 - in incubator/directory/janus/trunk/core: api/src/java/org/apache/janus/authorization/policy impl/src/java/org/apache/janus/authorization/policy impl/src/test/org/apache/janus/authorization/policy
Date Fri, 19 Mar 2004 23:22:05 GMT
Author: vtence
Date: Fri Mar 19 15:22:04 2004
New Revision: 9638

Removed:
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/RoleEntry.java
Modified:
   incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authorization/policy/PolicyContext.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/DefaultPolicyContext.java
   incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/policy/DefaultPolicyContextTest.java
Log:
o DIR-7: Implemented mutability on DefaultPolicyContext

Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authorization/policy/PolicyContext.java
==============================================================================
--- incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authorization/policy/PolicyContext.java
(original)
+++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authorization/policy/PolicyContext.java
Fri Mar 19 15:22:04 2004
@@ -26,7 +26,7 @@
     /**
      * This method is used to determine if a role has a given permission.
      */
-    boolean checkPermission( String roleName, Permission permission );
+    boolean checkPermission( String roleName, Permission p );
 
-    boolean requiresPriviledges( Permission permission );
+    boolean requiresPriviledges( Permission p );
 }

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/DefaultPolicyContext.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/DefaultPolicyContext.java
(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/DefaultPolicyContext.java
Fri Mar 19 15:22:04 2004
@@ -19,9 +19,8 @@
 import org.apache.janus.authorization.Permission;
 
 import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * todo: use a map indexed on role names instead of a set
@@ -32,74 +31,74 @@
 {
     private final PermissionCollection m_excludedPermissions;
     private final PermissionCollection m_uncheckedPermissions;
-    private final Set m_roles;
+    private final Map m_roles;
 
     public DefaultPolicyContext()
     {
-        m_roles = new HashSet();
+        m_roles = new HashMap();
         m_excludedPermissions = new PermissionCollection();
         m_uncheckedPermissions = new PermissionCollection();
     }
 
-    protected DefaultPolicyContext( Set roles,
+    protected DefaultPolicyContext( Map roles,
                                     Collection excludedPermissions,
                                     Collection uncheckedPermissions )
     {
-        m_roles = new HashSet( roles );
+        m_roles = new HashMap( roles );
         m_excludedPermissions = new PermissionCollection( excludedPermissions );
         m_uncheckedPermissions = new PermissionCollection( uncheckedPermissions );
     }
 
-    public boolean checkPermission( String roleName, Permission permission )
+    public boolean checkPermission( String roleName, Permission p )
     {
-        if (m_excludedPermissions.dependsOn( permission )) return false;
-        if (m_uncheckedPermissions.implies( permission )) return true;
+        if ( m_excludedPermissions.dependsOn( p ) ) return false;
+        if ( m_uncheckedPermissions.implies( p ) ) return true;
+        if ( !containsRole( roleName ) ) return false;
 
-        for ( Iterator it = m_roles.iterator(); it.hasNext(); )
-        {
-            final RoleEntry role = (RoleEntry) it.next();
-            if (role.is( roleName ) && role.implies( permission )) return true;
-        }
-
-        return false;
+        PermissionCollection permissions = getPermissions( roleName );
+        return permissions.implies( p );
     }
 
-    public boolean requiresPriviledges( Permission permission )
+    public boolean requiresPriviledges( Permission p )
     {
-        if (m_excludedPermissions.dependsOn( permission )) return true;
-        if (m_uncheckedPermissions.implies( permission )) return false;
+        if ( m_excludedPermissions.dependsOn( p ) ) return true;
+        if ( m_uncheckedPermissions.implies( p ) ) return false;
 
         return true;
     }
 
-    public boolean addToExcludedPolicy( Permission permission )
+    public boolean addToExcludedPolicy( Permission p )
     {
-        return m_excludedPermissions.add( permission );
+        return m_excludedPermissions.add( p );
     }
 
-    public boolean addToUncheckedPolicy( Permission permission )
+    public boolean addToUncheckedPolicy( Permission p )
     {
-        return m_uncheckedPermissions.add( permission );
+        return m_uncheckedPermissions.add( p );
     }
 
     public boolean addToRole( String roleName, Permission p )
     {
-        for ( Iterator it = m_roles.iterator(); it.hasNext(); )
-        {
-            final RoleEntry roleEntry = (RoleEntry) it.next();
-            if (roleEntry.is( roleName )) return roleEntry.add( p );
-        }
+        if ( !containsRole( roleName ) ) addRole( roleName );
 
-        RoleEntry roleEntry = addRole( roleName );
-        roleEntry.add( p );
-        return true;
+        PermissionCollection permissions = getPermissions( roleName );
+        return permissions.add( p );
     }
 
-    private RoleEntry addRole( String roleName )
+    private boolean containsRole( String roleName )
     {
-        RoleEntry roleEntry = new RoleEntry( roleName );
-        m_roles.add( roleEntry );
-        return roleEntry;
+        return m_roles.containsKey( roleName );
     }
 
+    private PermissionCollection getPermissions( String roleName )
+    {
+        PermissionCollection permissions = (PermissionCollection) m_roles.get( roleName );
+        return permissions;
+    }
+
+    private void addRole( String roleName )
+    {
+        PermissionCollection permissions = new PermissionCollection();
+        m_roles.put( roleName, permissions );
+    }
 }

Modified: incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/policy/DefaultPolicyContextTest.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/policy/DefaultPolicyContextTest.java
(original)
+++ incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/policy/DefaultPolicyContextTest.java
Fri Mar 19 15:22:04 2004
@@ -24,6 +24,8 @@
 
 import java.util.HashSet;
 import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
 
 /*
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
@@ -33,7 +35,7 @@
     private DefaultPolicyContext m_policyContext;
     private Set m_excludedPermissions;
     private Set m_uncheckedPermissions;
-    private Set m_roles;
+    private Map m_roles;
 
     public static void main( String[] args )
     {
@@ -44,7 +46,7 @@
     {
         m_excludedPermissions = new HashSet();
         m_uncheckedPermissions = new HashSet();
-        m_roles = new HashSet();
+        m_roles = new HashMap();
     }
 
     public void testUncheckedPermissionRequiresNoPriviledge()
@@ -65,10 +67,9 @@
 
     public void testCheckedPermissionRequiresPriviledges()
     {
-        Set permissions = new HashSet();
+        PermissionCollection permissions = new PermissionCollection();
         permissions.add( new CheckedPermission() );
-        RoleEntry role = new RoleEntry( "member", permissions );
-        m_roles.add( role );
+        m_roles.put(  "member", permissions );
         m_policyContext = new DefaultPolicyContext( m_roles, m_excludedPermissions, m_uncheckedPermissions
);
 
         assertTrue( "Permission is checked but requires no priviledge", m_policyContext.requiresPriviledges(
new CheckedPermission() ) );
@@ -99,10 +100,9 @@
 
     public void testPermissionGrantedIfInRole()
     {
-        Set permissions = new HashSet();
+        PermissionCollection permissions = new PermissionCollection();
         permissions.add( new CheckedPermission() );
-        RoleEntry role = new RoleEntry( "member", permissions );
-        m_roles.add( role );
+        m_roles.put(  "member", permissions );
         m_policyContext = new DefaultPolicyContext( m_roles, m_excludedPermissions, m_uncheckedPermissions
);
 
         assertTrue( "Role has permission yet it denied it", m_policyContext.checkPermission(
"member", new CheckedPermission() ) );
@@ -111,10 +111,9 @@
     public void testExcludedStatementHasPrecedenceOverRoleStatement()
     {
         m_excludedPermissions.add( new CheckedPermission() );
-        Set permissions = new HashSet();
+        PermissionCollection permissions = new PermissionCollection();
         permissions.add( new CheckedPermission() );
-        RoleEntry role = new RoleEntry( "member", permissions );
-        m_roles.add( role );
+        m_roles.put(  "member", permissions );
         m_policyContext = new DefaultPolicyContext( m_roles, m_excludedPermissions, m_uncheckedPermissions
);
 
         assertFalse( "Excluded statement did not overrule role statement", m_policyContext.checkPermission(
"member", new CheckedPermission() ) );
@@ -132,10 +131,9 @@
 
     public void testPermissionImpliedByCheckedPermissionIsGranted()
     {
-        Set permissions = new HashSet();
+        PermissionCollection permissions = new PermissionCollection();
         permissions.add( new FullPermission() );
-        RoleEntry role = new RoleEntry( "member", permissions );
-        m_roles.add( role );
+        m_roles.put(  "member", permissions );
         m_policyContext = new DefaultPolicyContext( m_roles, m_excludedPermissions, m_uncheckedPermissions
);
 
         assertTrue( "Permission is implied by role permission yet it was denied", m_policyContext.checkPermission(
"member", new ReadPermission() ) );

Mime
View raw message