directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r490646 [4/8] - in /directory/trunks/triplesec: ./ admin-api/ admin-api/src/main/java/org/safehaus/triplesec/admin/ admin-api/src/main/java/org/safehaus/triplesec/admin/dao/ admin-api/src/main/java/org/safehaus/triplesec/admin/dao/ldap/ adm...
Date Thu, 28 Dec 2006 04:48:33 GMT
Modified: directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/mock/MockApplicationPolicy.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/mock/MockApplicationPolicy.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/mock/MockApplicationPolicy.java
(original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/mock/MockApplicationPolicy.java
Wed Dec 27 20:48:29 2006
@@ -20,9 +20,22 @@
 package org.safehaus.triplesec.guardian.mock;
 
 
-import org.safehaus.triplesec.guardian.*;
-
-import java.util.*;
+import java.security.Permissions;
+import java.security.Permission;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.safehaus.triplesec.guardian.ApplicationPolicy;
+import org.safehaus.triplesec.guardian.GuardianException;
+import org.safehaus.triplesec.guardian.PolicyChangeListener;
+import org.safehaus.triplesec.guardian.Profile;
+import org.safehaus.triplesec.guardian.Role;
+import org.safehaus.triplesec.guardian.Roles;
+import org.safehaus.triplesec.guardian.StringPermission;
 
 
 /**
@@ -43,56 +56,79 @@
     {
         name = "mockApplication";
         profileByName = new HashMap();
-        Set permSet = new HashSet();
+        Set<Permission> permSet = new HashSet<Permission>();
         Set roleSet = new HashSet();
 
         // --------------------------------------------------------------------------------
         // add permissions
         // --------------------------------------------------------------------------------
 
-        Permission perm0 = new Permission( name, "mockPerm0" ); permSet.add( perm0 );
-        Permission perm1 = new Permission( name, "mockPerm1" ); permSet.add( perm1 );
-        Permission perm2 = new Permission( name, "mockPerm2" ); permSet.add( perm2 );
-        Permission perm3 = new Permission( name, "mockPerm3" ); permSet.add( perm3 );
-        Permission perm4 = new Permission( name, "mockPerm4" ); permSet.add( perm4 );
-        Permission perm5 = new Permission( name, "mockPerm5" ); permSet.add( perm5 );
-        Permission perm6 = new Permission( name, "mockPerm6" ); permSet.add( perm6 );
-        Permission perm7 = new Permission( name, "mockPerm7" ); permSet.add( perm7 );
-        Permission perm8 = new Permission( name, "mockPerm8" ); permSet.add( perm8 );
-        Permission perm9 = new Permission( name, "mockPerm9" ); permSet.add( perm9 );
-
-        Permission[] permArray = ( Permission[] ) permSet.toArray( new Permission[0] );
-        perms = new Permissions( name, permArray );
+        StringPermission perm0 = new StringPermission("mockPerm0" ); permSet.add( perm0 );
+        StringPermission perm1 = new StringPermission("mockPerm1" ); permSet.add( perm1 );
+        StringPermission perm2 = new StringPermission("mockPerm2" ); permSet.add( perm2 );
+        StringPermission perm3 = new StringPermission("mockPerm3" ); permSet.add( perm3 );
+        StringPermission perm4 = new StringPermission("mockPerm4" ); permSet.add( perm4 );
+        StringPermission perm5 = new StringPermission("mockPerm5" ); permSet.add( perm5 );
+        StringPermission perm6 = new StringPermission("mockPerm6" ); permSet.add( perm6 );
+        StringPermission perm7 = new StringPermission("mockPerm7" ); permSet.add( perm7 );
+        StringPermission perm8 = new StringPermission("mockPerm8" ); permSet.add( perm8 );
+        StringPermission perm9 = new StringPermission("mockPerm9" ); permSet.add( perm9 );
+
+        perms = new Permissions();
+         for (Permission perm: permSet) {
+             perms.add(perm);
+         }
 
         // --------------------------------------------------------------------------------
         // add roles
         // --------------------------------------------------------------------------------
 
         // role without any permissions toggled
-        Permissions grants = new Permissions( name, new Permission[0] );
-        Role role0 = new Role( this, "mockRole0", grants );
+        Permissions grants = new Permissions();
+        Role role0 = new Role( this, "mockRole0", grants, null);
         roleSet.add( role0 );
 
         // role with permission mockPerm0
-        grants = new Permissions( name, new Permission[] {perm0});
-        Role role1 = new Role( this, "mockRole1", grants );
+        grants = new Permissions();
+        grants.add(perm0);
+        Role role1 = new Role( this, "mockRole1", grants, null);
         roleSet.add( role1 );
 
         // role with permission mockPerm1
-        grants = new Permissions( name, new Permission[] {perm1});
-        Role role2 = new Role( this, "mockRole2", grants );
+        grants = new Permissions();
+        grants.add(perm1);
+        Role role2 = new Role( this, "mockRole2", grants, null);
         roleSet.add( role2 );
 
         // role with permission mockPerm2 and mochPerm3
-        grants = new Permissions( name, new Permission[] {perm2, perm3});
-        Role role3 = new Role( this, "mockRole3", grants );
+        grants = new Permissions();
+        grants.add(perm2);
+        grants.add(perm3);
+        Role role3 = new Role( this, "mockRole3", grants, null);
         roleSet.add( role3 );
 
         // role with permission mockPerm4, mockPerm5, mockPerm6, mockPerm7, mockPerm9
-        grants = new Permissions( name, new Permission[] {perm4, perm5, perm6, perm7, perm9});
-        Role role4 = new Role( this, "mockRole4", grants );
+        grants = new Permissions();
+        grants.add(perm4);
+        grants.add(perm5);
+        grants.add(perm6);
+        grants.add(perm7);
+        grants.add(perm9);
+        Role role4 = new Role( this, "mockRole4", grants, null);
         roleSet.add( role4 );
 
+        // role with permission mockPerm4, mockPerm5, mockPerm6, mockPerm7, mockPerm9
+        grants = new Permissions();
+        grants.add(perm4);
+        grants.add(perm5);
+        grants.add(perm6);
+        grants.add(perm7);
+        grants.add(perm9);
+        Permissions denials = new Permissions();
+        denials.add(perm6);
+        Role role5 = new Role( this, "mockRole5", grants, denials);
+        roleSet.add( role5 );
+
         Role[] rolesArray = ( Role [] ) roleSet.toArray( new Role[0] );
         roles = new Roles( name, rolesArray );
 
@@ -101,40 +137,55 @@
         // --------------------------------------------------------------------------------
 
         // a profile that has no permissions at all, and no roles (basis case)
-        grants = new Permissions( name, new Permission[0] );
-        Permissions denials = new Permissions( name, new Permission[0] );
+        grants = new Permissions();
+        denials = new Permissions();
         Roles roles = new Roles( name, new Role[0] );
         Profile profile = new Profile( this, "mockProfile0", "trustin", roles, grants, denials,
false );
         profileByName.put( profile.getProfileId(), profile );
 
         // a profile for checking union of role1 and role2 - inherits perm0 and perm1
-        grants = new Permissions( name, new Permission[0] );
-        denials = new Permissions( name, new Permission[0] );
+        grants = new Permissions();
+        denials = new Permissions();
         roles = new Roles( name, new Role[] { role1, role2 } );
         profile = new Profile( this, "mockProfile1", "trustin", roles, grants, denials, false
);
         profileByName.put( profile.getProfileId(), profile );
 
         // a profile for checking union of roles with grants - granted perm0 and inherits
perm1
-        grants = new Permissions( name, new Permission[] { perm0 } );
-        denials = new Permissions( name, new Permission[0] );
+        grants = new Permissions();
+        grants.add(perm0 );
+        denials = new Permissions();
         roles = new Roles( name, new Role[] { role2 } );
         profile = new Profile( this, "mockProfile2", "trustin", roles, grants, denials, false
);
         profileByName.put( profile.getProfileId(), profile );
 
         // a profile for checking union of roles with grants - granted perm0, perm7 and inherits
perm2 and perm3
-        grants = new Permissions( name, new Permission[] { perm0, perm7 } );
-        denials = new Permissions( name, new Permission[0] );
+        grants = new Permissions();
+        grants.add(perm0);
+        grants.add(perm7);
+        denials = new Permissions();
         roles = new Roles( name, new Role[] { role3 } );
         profile = new Profile( this, "mockProfile3", "trustin", roles, grants, denials, false
);
         profileByName.put( profile.getProfileId(), profile );
 
         // a profile for checking union of roles with grants and denials
         // granted perm0, in role3 and role4 but denied inherited perm7
-        grants = new Permissions( name, new Permission[] { perm0 } );
-        denials = new Permissions( name, new Permission[] { perm7 } );
+        grants = new Permissions();
+        grants.add(perm0);
+        denials = new Permissions();
+        denials.add(perm7);
         roles = new Roles( name, new Role[] { role3, role4 } );
         profile = new Profile( this, "mockProfile4", "trustin", roles, grants, denials, false
);
         profileByName.put( profile.getProfileId(), profile );
+
+        // a profile for checking union of roles with grants and denials
+        // granted perm0, in role3 and role4 but denied inherited perm7
+        grants = new Permissions();
+        grants.add(perm0);
+        denials = new Permissions();
+        denials.add(perm7);
+        roles = new Roles( name, new Role[] { role3, role4, role5 } );
+        profile = new Profile( this, "mockProfile5", "trustin", roles, grants, denials, false
);
+        profileByName.put( profile.getProfileId(), profile );
     }
 
 
@@ -191,7 +242,7 @@
     }
 
 
-    public Set getDependentProfileNames( Permission permission ) throws GuardianException
+    public Set getDependentProfileNames( StringPermission permission ) throws GuardianException
     {
         return null;
     }

Modified: directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/mock/MockApplicationPolicyTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/mock/MockApplicationPolicyTest.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/mock/MockApplicationPolicyTest.java
(original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/mock/MockApplicationPolicyTest.java
Wed Dec 27 20:48:29 2006
@@ -23,6 +23,8 @@
 import junit.framework.TestCase;
 import org.safehaus.triplesec.guardian.ApplicationPolicyFactory;
 import org.safehaus.triplesec.guardian.Profile;
+import org.safehaus.triplesec.guardian.StringPermission;
+import org.safehaus.triplesec.guardian.PermissionsUtil;
 
 
 /**
@@ -34,6 +36,7 @@
 public class MockApplicationPolicyTest extends TestCase
 {
     MockApplicationPolicy store;
+    private static final String APP_NAME = "mockApplication";
 
     protected void setUp() throws Exception
     {
@@ -53,29 +56,29 @@
 
     public void testProfile0()
     {
-        assertEquals( 5, store.getRoles().size() );
+        assertEquals( 6, store.getRoles().size() );
         Profile p = store.getProfile( "mockProfile0" );
-        assertTrue( p.getEffectivePermissions().isEmpty() );
+        assertTrue( PermissionsUtil.isEmpty(p.getEffectiveGrantedPermissions()) );
         assertTrue( p.getRoles().isEmpty() );
     }
 
     public void testProfile1()
     {
         Profile p = store.getProfile( "mockProfile1" );
-        assertEquals( 2, p.getEffectivePermissions().size() );
-        assertTrue( p.hasPermission( "mockPerm0" ) );
-        assertTrue( p.hasPermission( "mockPerm1" ) );
-        assertFalse( p.hasPermission( "mockPerm3") );
+        assertEquals( 2, PermissionsUtil.size(p.getEffectiveGrantedPermissions()) );
+        assertTrue( p.implies( new StringPermission("mockPerm0" )));
+        assertTrue( p.implies( new StringPermission("mockPerm1" )));
+        assertFalse( p.implies( new StringPermission("mockPerm3")));
         assertEquals( 2, p.getRoles().size() );
     }
 
     public void testProfile2()
     {
         Profile p = store.getProfile( "mockProfile2" );
-        assertEquals( 2, p.getEffectivePermissions().size() );
-        assertTrue( p.hasPermission( "mockPerm0" ) );
-        assertTrue( p.hasPermission( "mockPerm1" ) );
-        assertFalse( p.hasPermission( "mockPerm3") );
+        assertEquals( 2, PermissionsUtil.size(p.getEffectiveGrantedPermissions()) );
+        assertTrue( p.implies( new StringPermission("mockPerm0" )));
+        assertTrue( p.implies( new StringPermission("mockPerm1" )));
+        assertFalse( p.implies( new StringPermission("mockPerm3")));
         assertEquals( 1, p.getRoles().size() );
         assertTrue( p.getRoles().contains( "mockRole2" ) );
     }
@@ -83,12 +86,12 @@
     public void testProfile3()
     {
         Profile p = store.getProfile( "mockProfile3" );
-        assertEquals( 4, p.getEffectivePermissions().size() );
-        assertTrue( p.hasPermission( "mockPerm0" ) );
-        assertTrue( p.hasPermission( "mockPerm7" ) );
-        assertTrue( p.hasPermission( "mockPerm2" ) );
-        assertTrue( p.hasPermission( "mockPerm3" ) );
-        assertFalse( p.hasPermission( "mockPerm4" ) );
+        assertEquals( 4, PermissionsUtil.size(p.getEffectiveGrantedPermissions()) );
+        assertTrue( p.implies( new StringPermission("mockPerm0" )));
+        assertTrue( p.implies( new StringPermission("mockPerm7" )));
+        assertTrue( p.implies( new StringPermission("mockPerm2" )));
+        assertTrue( p.implies( new StringPermission("mockPerm3" )));
+        assertFalse( p.implies( new StringPermission("mockPerm4" )));
         assertEquals( 1, p.getRoles().size() );
         assertTrue( p.getRoles().contains( "mockRole3" ) );
     }
@@ -96,21 +99,46 @@
     public void testProfile4()
     {
         Profile p = store.getProfile( "mockProfile4" );
-        assertEquals( 7, p.getEffectivePermissions().size() );
-        assertTrue( p.hasPermission( "mockPerm0" ) );
-        assertFalse( p.hasPermission( "mockPerm1" ) );
-        assertTrue( p.hasPermission( "mockPerm2" ) );
-        assertTrue( p.hasPermission( "mockPerm3" ) );
-        assertTrue( p.hasPermission( "mockPerm4" ) );
-        assertTrue( p.hasPermission( "mockPerm5" ) );
-        assertTrue( p.hasPermission( "mockPerm6" ) );
-        assertFalse( p.hasPermission( "mockPerm7" ) );
-        assertFalse( p.hasPermission( "mockPerm8" ) );
-        assertTrue( p.hasPermission( "mockPerm9" ) );
+        assertEquals( 8, PermissionsUtil.size(p.getEffectiveGrantedPermissions()) );
+        assertEquals( 1, PermissionsUtil.size(p.getEffectiveDeniedPermissions()) );
+        assertTrue( p.implies( new StringPermission("mockPerm0" )));
+        assertFalse( p.implies( new StringPermission("mockPerm1" )));
+        assertTrue( p.implies( new StringPermission("mockPerm2" )));
+        assertTrue( p.implies( new StringPermission("mockPerm3" )));
+        assertTrue( p.implies( new StringPermission("mockPerm4" )));
+        assertTrue( p.implies( new StringPermission("mockPerm5" )));
+        assertTrue( p.implies( new StringPermission("mockPerm6" )));
+        assertFalse( p.implies( new StringPermission("mockPerm7" )));
+        assertFalse( p.implies( new StringPermission("mockPerm8" )));
+        assertTrue( p.implies( new StringPermission("mockPerm9" )));
 
-        assertFalse( p.hasPermission( "mockPerm14" ) );
+        assertFalse( p.implies( new StringPermission("mockPerm14" )));
         assertEquals( 2, p.getRoles().size() );
         assertTrue( p.getRoles().contains( "mockRole3" ) );
         assertTrue( p.getRoles().contains( "mockRole4" ) );
+    }
+
+    public void testProfile5()
+    {
+        Profile p = store.getProfile( "mockProfile5" );
+        assertEquals( 8, PermissionsUtil.size(p.getEffectiveGrantedPermissions()) );
+        assertEquals( 2, PermissionsUtil.size(p.getEffectiveDeniedPermissions()) );
+        assertTrue( p.implies( new StringPermission("mockPerm0" )));
+        assertFalse( p.implies( new StringPermission("mockPerm1" )));
+        assertTrue( p.implies( new StringPermission("mockPerm2" )));
+        assertTrue( p.implies( new StringPermission("mockPerm3" )));
+        assertTrue( p.implies( new StringPermission("mockPerm4" )));
+        assertTrue( p.implies( new StringPermission("mockPerm5" )));
+        //from denial in role5
+        assertFalse( p.implies( new StringPermission("mockPerm6" )));
+        assertFalse( p.implies( new StringPermission("mockPerm7" )));
+        assertFalse( p.implies( new StringPermission("mockPerm8" )));
+        assertTrue( p.implies( new StringPermission("mockPerm9" )));
+
+        assertFalse( p.implies( new StringPermission("mockPerm14" )));
+        assertEquals( 3, p.getRoles().size() );
+        assertTrue( p.getRoles().contains( "mockRole3" ) );
+        assertTrue( p.getRoles().contains( "mockRole4" ) );
+        assertTrue( p.getRoles().contains( "mockRole5" ) );
     }
 }

Modified: directory/trunks/triplesec/guardian-ldap/pom.xml
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-ldap/pom.xml?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-ldap/pom.xml (original)
+++ directory/trunks/triplesec/guardian-ldap/pom.xml Wed Dec 27 20:48:29 2006
@@ -49,6 +49,12 @@
       <version>${pom.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <artifactId>triplesec-itest-data</artifactId>
+      <groupId>${pom.groupId}</groupId>
+      <version>${pom.version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -122,6 +128,35 @@
       <activation>
         <property><name>integration</name></property>
       </activation>
+        <build>
+        <plugins>
+            <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>dependency-maven-plugin</artifactId>
+            <executions>
+                <execution>
+                    <id>unpack-itest-data</id>
+                    <phase>compile</phase>
+                    <goals>
+                        <goal>unpack</goal>
+                    </goals>
+                    <configuration>
+                        <artifactItems>
+                            <artifactItem>
+                                <groupId>${pom.groupId}</groupId>
+                                <artifactId>triplesec-itest-data</artifactId>
+                                <version>${pom.version}</version>
+                            </artifactItem>
+                        </artifactItems>
+                        <outputDirectory>${project.build.directory}/serverHome/conf</outputDirectory>
+                    </configuration>
+                </execution>
+
+            </executions>
+        </plugin>
+
+        </plugins>
+        </build>
     </profile>
   </profiles>
 



Mime
View raw message