directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r490646 [3/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/main/java/org/safehaus/triplesec/guardian/Profile.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Profile.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Profile.java (original)
+++ directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Profile.java Wed Dec 27 20:48:29 2006
@@ -22,6 +22,8 @@
 
 import java.io.Serializable;
 import java.security.AccessControlException;
+import java.security.Permission;
+import java.security.Permissions;
 import java.util.Iterator;
 
 
@@ -31,17 +33,17 @@
  * to manage access controls for user profiles associated with applications.
  * Profiles associate users with applications.  This class models that profile
  * by linking the user with an application and allowing the assignment of an
- * application specific {@link Role} set and {@link Permission} set to the 
+ * application specific {@link Role} set and {@link StringPermission} set to the
  * profile.
  * </p>  
  * <p>
  * Profiles contain three sets of Permissions and a set of Roles used for 
  * managing an authorization policy of a user.  A Role Based Access Control 
- * (RBAC) model is used to easily manage the Profile.  The three Permission
+ * (RBAC) model is used to easily manage the Profile.  The three StringPermission
  * sets are: grants, denials and the effective calculated permissions for the 
- * profile.  Roles assigned to the Profile lead to the inheritance of Permission
- * granted to Role.  Besides Role based Permission inheritence, additional
- * Permission may be granted or denied to influence the total effective Permission.  
+ * profile.  Roles assigned to the Profile lead to the inheritance of StringPermission
+ * granted to Role.  Besides Role based StringPermission inheritence, additional
+ * StringPermission may be granted or denied to influence the total effective StringPermission.
  * The grants Permissions set contains extra granted Permissions which may not be 
  * inherited by assigned Roles.  The denials Permissions set contains
  * {@link Permissions} that are denied whether they are inherited by assigned
@@ -73,8 +75,10 @@
     private final Permissions grants;
     /** the permissions denied by this Profile */
     private final Permissions denials;
-    /** the effective calculated permissions for this Profile */
-    private final Permissions effectivePermissions;
+    /** the calculated effective granted permissions for this Profile */
+    private final Permissions effectiveGrantedPermissions;
+    /** the calculated effective denied permissions for this Profile */
+    private final Permissions effectiveDeniedPermissions;
     /** a brief description of the Profile */
     private final String description;
     /** whether or not this profile is disabled */
@@ -143,32 +147,32 @@
         }
         if( grants == null )
         {
-            grants = new Permissions( store.getApplicationName(), null );
-        }
-        if( !store.getApplicationName().equals( grants.getApplicationName() ) )
-        {
-            throw new IllegalArgumentException( "Invalid applicationName in grants: " + grants.getApplicationName() );
-        }
-        if( !store.getPermissions().containsAll( grants ) )
-        {
-            throw new IllegalArgumentException(
-                    "store doesn't provide all permissions specified: " +
-                    grants );
+            grants = new Permissions();
         }
+//        if( !store.getApplicationName().equals( grants.getApplicationName() ) )
+//        {
+//            throw new IllegalArgumentException( "Invalid applicationName in grants: " + grants.getApplicationName() );
+//        }
+//        if( !store.getPermissions().containsAll( grants ) )
+//        {
+//            throw new IllegalArgumentException(
+//                    "store doesn't provide all permissions specified: " +
+//                    grants );
+//        }
         if( denials == null )
         {
-            denials = new Permissions( store.getApplicationName(), null );
-        }
-        if( !store.getApplicationName().equals( denials.getApplicationName() ) )
-        {
-            throw new IllegalArgumentException( "Invalid applicationName in denials: " + denials.getApplicationName() );
-        }
-        if( !store.getPermissions().containsAll( denials ) )
-        {
-            throw new IllegalArgumentException(
-                    "store doesn't provide all permissions specified: " +
-                    denials );
+            denials = new Permissions();
         }
+//        if( !store.getApplicationName().equals( denials.getApplicationName() ) )
+//        {
+//            throw new IllegalArgumentException( "Invalid applicationName in denials: " + denials.getApplicationName() );
+//        }
+//        if( !store.getPermissions().containsAll( denials ) )
+//        {
+//            throw new IllegalArgumentException(
+//                    "store doesn't provide all permissions specified: " +
+//                    denials );
+//        }
         
         this.disabled = disabled;
         this.store = store;
@@ -180,14 +184,20 @@
         this.description = description;
 
         // Calculate effective permissions
-        Permissions effectivePermissions = new Permissions( store.getApplicationName(), null );
+        effectiveGrantedPermissions = new Permissions();
+        for( Iterator i = roles.iterator(); i.hasNext(); )
+        {
+            Role r = ( Role ) i.next();
+            PermissionsUtil.addAll(effectiveGrantedPermissions, r.getGrantedPermissions() );
+        }
+        PermissionsUtil.addAll(effectiveGrantedPermissions, grants );
+        effectiveDeniedPermissions = new Permissions();
         for( Iterator i = roles.iterator(); i.hasNext(); )
         {
             Role r = ( Role ) i.next();
-            effectivePermissions = effectivePermissions.addAll( r.getGrants() );
+            PermissionsUtil.addAll(effectiveDeniedPermissions, r.getDeniedPermissions() );
         }
-        effectivePermissions = effectivePermissions.addAll( grants );
-        this.effectivePermissions = effectivePermissions.removeAll( denials );
+        PermissionsUtil.addAll(effectiveDeniedPermissions, denials );
     }
 
     
@@ -270,9 +280,9 @@
 
 
     /**
-     * Gets the set of {@link Permission}s granted to this Profile.
+     * Gets the set of {@link StringPermission}s granted to this Profile.
      * 
-     * @return a container of granted {@link Permission} objects
+     * @return a container of granted {@link StringPermission} objects
      */
     public Permissions getGrants()
     {
@@ -284,7 +294,7 @@
      * This is the only time and place where negative permissions will ever be
      * found.
      * 
-     * @return a container of denied {@link Permission} objects
+     * @return a container of denied {@link StringPermission} objects
      */
     public Permissions getDenials()
     {
@@ -298,52 +308,26 @@
      * granted {@link Permissions} and denied {@link Permissions} of this
      * Profile.
      * 
-     * @return a container of effective {@link Permission} objects for this profile.
+     * @return a container of effective {@link StringPermission} objects for this profile.
      */
-    public Permissions getEffectivePermissions()
+    public Permissions getEffectiveGrantedPermissions()
     {
-        return effectivePermissions;
+        return effectiveGrantedPermissions;
     }
 
-
-    /**
-     * Assertive check to test if this Profile has the effective {@link Permission}.
-     * 
-     * @param permissionName the permission name to check for
-     * @throws AccessControlException if the permission is not granted or
-     *      inherited from an assigned Role
-     */
-    public void checkPermission( String permissionName )
-    {
-        checkPermission(
-                permissionName,
-                "User '" + profileId + "' " +
-                "in application '" + getApplicationName() + '\'' +
-                "does not posess the permission '" + permissionName + "'." );
+    public Permissions getEffectiveDeniedPermissions() {
+        return effectiveDeniedPermissions;
     }
 
-
     /**
      * Get's whether or not this Profile has the permission.
      *
      * @param permission the permission to check for
      * @return true if the permission is granted, false otherwise
      */
-    public boolean hasPermission( Permission permission )
-    {
-        return effectivePermissions.contains( permission );
-    }
-
-
-    /**
-     * Get's whether or not this Profile has the permission.
-     *
-     * @param permissionName the permission to check for
-     * @return true if the permission is granted, false otherwise
-     */
-    public boolean hasPermission( String permissionName )
+    public boolean implies( Permission permission )
     {
-        return effectivePermissions.get( permissionName ) != null;
+        return effectiveGrantedPermissions.implies( permission ) && ! effectiveDeniedPermissions.implies(permission);
     }
 
 
@@ -355,7 +339,7 @@
      * @throws AccessControlException if the permission is not granted or
      *      inherited from an assigned Role
      */
-    public void checkPermission( Permission permission )
+    public void checkPermission( StringPermission permission )
     {
         checkPermission(
                 permission,
@@ -369,42 +353,19 @@
      * Assertive permission check to test if this Profile has the effective 
      * permission.
      * 
-     * @param permissionName the permission name to check for
-     * @param message to use for AccessControlException if it is thrown
-     * @throws AccessControlException if the permission is not granted or
-     *      inherited from an assigned Role
-     */
-    public void checkPermission( String permissionName, String message )
-    {
-        if ( permissionName == null )
-        {
-            throw new NullPointerException( "permissionName" );    
-        }
-        
-        if ( !effectivePermissions.contains( permissionName ) )
-        {
-            throw new AccessControlException( message );
-        }
-    }
-
-
-    /**
-     * Assertive permission check to test if this Profile has the effective 
-     * permission.
-     * 
      * @param permission the permission to check for
      * @param message to use for AccessControlException if it is thrown
      * @throws AccessControlException if the permission is not granted or
      *      inherited from an assigned Role
      */
-    public void checkPermission( Permission permission, String message )
+    public void checkPermission( StringPermission permission, String message )
     {
         if ( permission == null )
         {
             throw new NullPointerException( "permission" );    
         }
         
-        if ( !effectivePermissions.contains( permission ) )
+        if ( !implies( permission ) )
         {
             throw new AccessControlException( message );
         }
@@ -468,6 +429,6 @@
 
     public String toString()
     {
-        return "Profile(" + getProfileId() + ": " + effectivePermissions + ')';
+        return "Profile(" + getProfileId() + ": " + effectiveGrantedPermissions + ')';
     }
 }

Modified: directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Role.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Role.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Role.java (original)
+++ directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Role.java Wed Dec 27 20:48:29 2006
@@ -22,6 +22,7 @@
 
 import java.io.Serializable;
 import java.security.AccessControlException;
+import java.security.Permissions;
 
 
 /**
@@ -37,15 +38,13 @@
 {
     private static final long serialVersionUID = 6190625586883412135L;
 
-    /** an empty byte array used as a placeholder for empty grants */
-    private static final Permission[] EMPTY_PERMISSION_ARRAY = new Permission[0];
-    
     /** the name of this Role */
     private final String name;
     /** the store the Role is defined for */
     private final ApplicationPolicy store;
-    /** the permissions granted for this role */
-    private final Permissions permissions;
+    /** the grantedPermissions granted for this role */
+    private final Permissions grantedPermissions;
+    private final Permissions deniedPermissions;
     /** a brief description of the Role */
     private final String description;
 
@@ -55,10 +54,11 @@
      * 
      * @param store the parent store this role is defined for
      * @param name the name of this role
-     * @param permissions a set of permissions granted for this role
+     * @param grantedPermissions
+     * @param deniedPermissions
      * @param description a breif description of the role
      */
-    public Role( ApplicationPolicy store, String name, Permissions permissions, String description )
+    public Role(ApplicationPolicy store, String name, Permissions grantedPermissions, Permissions deniedPermissions, String description)
     {
         if( store == null )
         {
@@ -73,28 +73,33 @@
             throw new IllegalArgumentException( "name is empty." );
         }
         
-        if( permissions == null )
+        if( grantedPermissions == null )
         {
-            permissions = new Permissions(
-                    store.getApplicationName(), EMPTY_PERMISSION_ARRAY );
+            grantedPermissions = new Permissions();
         }
-        if( !store.getApplicationName().equals( permissions.getApplicationName() ) )
+        if( deniedPermissions == null )
         {
-            throw new IllegalArgumentException(
-                    "Invalid applicationName in permissions: " +
-                    permissions.getApplicationName() );
-        }
-        
-        if( !store.getPermissions().containsAll( permissions ) )
-        {
-            throw new IllegalArgumentException(
-                    "store doesn't provide all permissions specified: " +
-                    permissions );
+            deniedPermissions = new Permissions();
         }
+//        if( !store.getApplicationName().equals( grantedPermissions.getApplicationName() ) )
+//        {
+//            throw new IllegalArgumentException(
+//                    "Invalid applicationName in grantedPermissions: " +
+//                    grantedPermissions.getApplicationName() );
+//        }
+
+        //This is meaningless if grantedPermissions.implies is used rather than equality.
+//        if( !store.getPermissions().containsAll( grantedPermissions ) )
+//        {
+//            throw new IllegalArgumentException(
+//                    "store doesn't provide all grantedPermissions specified: " +
+//                    grantedPermissions );
+//        }
         
         this.store = store;
         this.name = name;
-        this.permissions = permissions;
+        this.grantedPermissions = grantedPermissions;
+        this.deniedPermissions = deniedPermissions;
         this.description = description;
     }
 
@@ -104,11 +109,12 @@
      *
      * @param store the parent store this role is defined for
      * @param name the name of this role
-     * @param permissions a set of permissions granted for this role
+     * @param grantedPermissions
+     * @param deniedPermissions
      */
-    public Role( ApplicationPolicy store, String name, Permissions permissions )
+    public Role(ApplicationPolicy store, String name, Permissions grantedPermissions, Permissions deniedPermissions)
     {
-        this ( store, name, permissions, null );
+        this ( store, name, grantedPermissions, deniedPermissions, null );
     }
 
 
@@ -146,15 +152,18 @@
 
 
     /**
-     * Gets a set of permissions granted to this role.
+     * Gets a set of grantedPermissions granted to this role.
      * 
-     * @return a set of permissions granted to this role.
+     * @return a set of grantedPermissions granted to this role.
      */
-    public Permissions getGrants()
+    public Permissions getGrantedPermissions()
     {
-        return permissions;
+        return grantedPermissions;
     }
 
+    public Permissions getDeniedPermissions() {
+        return deniedPermissions;
+    }
 
     /**
      * Assertive permission check to test if this role has the effective
@@ -163,7 +172,7 @@
      * @param permission the permission to check for
      * @throws AccessControlException if the permission is not granted
      */
-    public void checkPermission( Permission permission )
+    public void checkPermission( StringPermission permission )
     {
         checkPermission(
                 permission,
@@ -176,41 +185,12 @@
     /**
      * Get's whether or not this Role has the permission.
      *
-     * @param permissionName the permission to check for
-     * @return true if the permission is granted,false otherwise
-     */
-    public boolean hasPermission( String permissionName )
-    {
-        return permissions.get( permissionName ) != null;
-    }
-
-
-    /**
-     * Get's whether or not this Role has the permission.
-     *
      * @param permission the name of permission to check for
      * @return true if the permission is granted,false otherwise
      */
-    public boolean hasPermission( Permission permission )
-    {
-        return permissions.contains( permission );
-    }
-
-
-    /**
-     * Assertive permission check to test if this role has the effective 
-     * permission.
-     * 
-     * @param permissionName the name of the permission to check for
-     * @throws AccessControlException if the permission is not granted
-     */
-    public void checkPermission( String permissionName )
+    public boolean hasPermission( StringPermission permission )
     {
-        checkPermission(
-                permissionName,
-                "Role '" + name + "' " +
-                "in application '" + getApplicationName() + '\'' +
-                "does not posess the permission '" + permissionName + "'." );
+        return grantedPermissions.implies( permission );
     }
 
 
@@ -222,36 +202,14 @@
      * @param message to use for AccessControlException if it is thrown
      * @throws AccessControlException if the permission is not granted
      */
-    public void checkPermission( Permission permission, String message )
+    public void checkPermission( StringPermission permission, String message )
     {
         if ( permission == null )
         {
             throw new NullPointerException( "permission" );    
         }
         
-        if ( !permissions.contains( permission ) )
-        {
-            throw new AccessControlException( message );
-        }
-    }
-
-
-    /**
-     * Assertive permission check to test if this role has the effective 
-     * permission.
-     * 
-     * @param permissionName the permission name to check for
-     * @param message to use for AccessControlException if it is thrown
-     * @throws AccessControlException if the permission is not granted
-     */
-    public void checkPermission( String permissionName, String message )
-    {
-        if ( permissionName == null )
-        {
-            throw new NullPointerException( "permissionName" );    
-        }
-        
-        if ( !permissions.contains( permissionName ) )
+        if ( !grantedPermissions.implies( permission ) )
         {
             throw new AccessControlException( message );
         }
@@ -302,8 +260,8 @@
     }
 
 
-    public Object clone()
-    {
+    @Override
+    public Object clone() throws CloneNotSupportedException {
         try
         {
             return super.clone();
@@ -317,6 +275,6 @@
 
     public String toString()
     {
-        return "Role(" + getName() + ": " + permissions + ')';
+        return "Role(" + getName() + ": " + grantedPermissions + ')';
     }
 }

Modified: directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Roles.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Roles.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Roles.java (original)
+++ directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/Roles.java Wed Dec 27 20:48:29 2006
@@ -246,56 +246,33 @@
     }
 
     
-    public Roles getDependentRoles( String permName )
-    {
-        List dependents = new ArrayList();
-        for ( Iterator ii = this.roles.values().iterator(); ii.hasNext(); /**/ )
-        {
-            Role role = ( Role ) ii.next(); 
-            if ( role.hasPermission( permName ) )
-            {
-                dependents.add( role );
-            }
-        }
-        
-        if ( dependents.size() == 0 )
-        {
-            return new Roles( getApplicationName(), EMPTY_ROLE_ARRAY );
-        }
-        
-        Role[] roleArray = new Role[dependents.size()];
-        dependents.toArray( roleArray );
-        return new Roles( getApplicationName(), roleArray );
-    }
-    
-    
-    public Roles getDependentRoles( Permission perm )
-    {
-        if ( ! perm.getApplicationName().equals( getApplicationName() ) )
-        {
-            throw new IllegalArgumentException( "The permission '" + perm.getName() + "' is not " +
-                    "\nassociated with this application.  It is associated with " + perm.getApplicationName() );
-        }
-        
-        List dependents = new ArrayList();
-        for ( Iterator ii = this.roles.values().iterator(); ii.hasNext(); /**/ )
-        {
-            Role role = ( Role ) ii.next(); 
-            if ( role.hasPermission( perm ) )
-            {
-                dependents.add( role );
-            }
-        }
-        
-        if ( dependents.size() == 0 )
-        {
-            return new Roles( getApplicationName(), EMPTY_ROLE_ARRAY );
-        }
-        
-        Role[] roleArray = new Role[dependents.size()];
-        dependents.toArray( roleArray );
-        return new Roles( getApplicationName(), roleArray );
-    }
+//    public Roles getDependentRoles( StringPermission perm )
+//    {
+//        if ( ! perm.getApplicationName().equals( getApplicationName() ) )
+//        {
+//            throw new IllegalArgumentException( "The permission '" + perm.getName() + "' is not " +
+//                    "\nassociated with this application.  It is associated with " + perm.getApplicationName() );
+//        }
+//
+//        List dependents = new ArrayList();
+//        for ( Iterator ii = this.roles.values().iterator(); ii.hasNext(); /**/ )
+//        {
+//            Role role = ( Role ) ii.next();
+//            if ( role.hasPermission( perm ) )
+//            {
+//                dependents.add( role );
+//            }
+//        }
+//
+//        if ( dependents.size() == 0 )
+//        {
+//            return new Roles( getApplicationName(), EMPTY_ROLE_ARRAY );
+//        }
+//
+//        Role[] roleArray = new Role[dependents.size()];
+//        dependents.toArray( roleArray );
+//        return new Roles( getApplicationName(), roleArray );
+//    }
     
 
     // ------------------------------------------------------------------------

Added: directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/StringPermission.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/StringPermission.java?view=auto&rev=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/StringPermission.java (added)
+++ directory/trunks/triplesec/guardian-api/src/main/java/org/safehaus/triplesec/guardian/StringPermission.java Wed Dec 27 20:48:29 2006
@@ -0,0 +1,166 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.guardian;
+
+import java.io.Serializable;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+
+/**
+ * An application permission.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @author Trustin Lee
+ * @version $Rev: 71 $, $Date: 2005-11-07 19:11:39 -0500 (Mon, 07 Nov 2005) $
+ */
+public class StringPermission extends Permission implements Comparable, Cloneable, Serializable {
+    private static final long serialVersionUID = -522561010304299861L;
+
+    /** the name of the permission */
+//    private final String permissionName;
+    /**
+     * the name of the application this permission is associated with
+     */
+//    private final String applicationName;
+    /**
+     * a short description of the permission
+     */
+//    private final String description;
+
+
+
+    /**
+     * Creates a new permission instance with description.
+     *
+     * @param permissionName  the permissionName of the permission
+     */
+    public StringPermission(String permissionName) {
+        super(permissionName);
+        if (permissionName == null) {
+            throw new NullPointerException("permissionName");
+        }
+        if (permissionName.length() == 0) {
+            throw new IllegalArgumentException("permissionName is empty.");
+        }
+    }
+
+
+    public String getActions() {
+        return "";
+    }
+
+
+    // ------------------------------------------------------------------------
+    // Object Overrides
+    // ------------------------------------------------------------------------
+
+
+    public int hashCode() {
+        return getName().hashCode();
+    }
+
+
+    public boolean implies(Permission permission) {
+        return permission instanceof StringPermission && permission.getName().equals(getName());
+    }
+
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+
+        if (that instanceof StringPermission) {
+            StringPermission thatP = (StringPermission) that;
+            return getName().equals(thatP.getName());
+        }
+
+        return false;
+    }
+
+
+    public int compareTo(Object that) {
+        StringPermission thatP = (StringPermission) that;
+        return this.getName().compareTo(thatP.getName());
+    }
+
+
+    public String toString() {
+        return "StringPermission(" + getName() + ')';
+    }
+
+
+    @Override
+    public Object clone() throws CloneNotSupportedException {
+        try {
+            return super.clone();
+        }
+        catch (CloneNotSupportedException e) {
+            throw new InternalError();
+        }
+    }
+
+    @Override
+    public PermissionCollection newPermissionCollection() {
+        return new StringPermissionCollection();
+    }
+
+    private static class StringPermissionCollection extends PermissionCollection {
+
+        private final Map<String, StringPermission> permissionMap = new HashMap<String, StringPermission>();
+
+
+        public void add(Permission permission) {
+            if (permission instanceof StringPermission) {
+                permissionMap.put(permission.getName(), (StringPermission) permission);
+            } else {
+                throw new IllegalArgumentException("Permission must be a StringPermission not a " + permission.getClass());
+            }
+        }
+
+        public boolean implies(Permission permission) {
+            if (permission instanceof StringPermission) {
+                return permissionMap.containsKey(permission.getName());
+            }
+            return false;
+        }
+
+        public Enumeration<Permission> elements() {
+            final Iterator<StringPermission> iterator = permissionMap.values().iterator();
+
+            return new Enumeration<Permission>() {
+
+
+                public boolean hasMoreElements() {
+                    return iterator.hasNext();
+                }
+
+                public StringPermission nextElement() {
+                    return iterator.next();
+                }
+            };
+        }
+    }
+
+}

Modified: directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/AbstractEntityTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/AbstractEntityTest.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/AbstractEntityTest.java (original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/AbstractEntityTest.java Wed Dec 27 20:48:29 2006
@@ -29,11 +29,11 @@
  */
 public abstract class AbstractEntityTest extends TestCase {
 
-    private Object a1;
-    private Object a2;
-    private Object b1;
-    private Object b2;
-    private Object wrong;
+    protected Object a1;
+    protected Object a2;
+    protected Object b1;
+    protected Object b2;
+    protected Object wrong;
 
     protected abstract Object newInstanceA1();
     protected abstract Object newInstanceA2();

Modified: directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/ApplicationPolicyFactoryTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/ApplicationPolicyFactoryTest.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/ApplicationPolicyFactoryTest.java (original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/ApplicationPolicyFactoryTest.java Wed Dec 27 20:48:29 2006
@@ -19,6 +19,7 @@
  */
 package org.safehaus.triplesec.guardian;
 
+import java.security.Permissions;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Properties;
@@ -176,7 +177,7 @@
                     return null;
                 }
 
-                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/PermissionTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/PermissionTest.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/PermissionTest.java (original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/PermissionTest.java Wed Dec 27 20:48:29 2006
@@ -30,25 +30,25 @@
 
     protected Object newInstanceA1()
     {
-        return new Permission( "app1", "perm1" );
+        return new StringPermission("perm1" );
     }
 
 
     protected Object newInstanceA2()
     {
-        return new Permission( "app1", "perm1" );
+        return new StringPermission("perm1" );
     }
 
 
     protected Object newInstanceB1()
     {
-        return new Permission( "app1", "perm2" );
+        return new StringPermission("perm2" );
     }
 
 
     protected Object newInstanceB2()
     {
-        return new Permission( "app2", "perm1" );
+        return new StringPermission("perm2" );
     }
 
 
@@ -56,49 +56,47 @@
     {
         try
         {
-            new Permission( "test", null );
+            new StringPermission(null );
             fail( "Exception is not thrown." );
         }
         catch ( NullPointerException e )
         {
             // OK
         }
-        try
-        {
-            new Permission( null, "test" );
-            fail( "Exception is not thrown." );
-        }
-        catch ( NullPointerException e )
-        {
-            // OK
-        }
-        try
-        {
-            new Permission( "test", "" );
-            fail( "Exception is not thrown." );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            // OK
-        }
-        try
-        {
-            new Permission( "", "test" );
-            fail( "Exception is not thrown." );
-        }
-        catch ( IllegalArgumentException e )
-        {
-            // OK
-        }
+//        try
+//        {
+//            new StringPermission("test" );
+//            fail( "Exception is not thrown." );
+//        }
+//        catch ( NullPointerException e )
+//        {
+//            // OK
+//        }
+//        try
+//        {
+//            new StringPermission("" );
+//            fail( "Exception is not thrown." );
+//        }
+//        catch ( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
+//        try
+//        {
+//            new StringPermission("test" );
+//            fail( "Exception is not thrown." );
+//        }
+//        catch ( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
     }
 
 
     public void testPropeties()
     {
-        Permission p = new Permission( "a", "b", "c" );
-        assertEquals( "a", p.getApplicationName() );
+        StringPermission p = new StringPermission("b");
         assertEquals( "b", p.getName() );
-        assertEquals( "c", p.getDescription() );
     }
 
 

Modified: directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/PermissionsTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/PermissionsTest.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/PermissionsTest.java (original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/PermissionsTest.java Wed Dec 27 20:48:29 2006
@@ -19,204 +19,214 @@
  */
 package org.safehaus.triplesec.guardian;
 
+import java.security.Permission;
+import java.security.Permissions;
+import java.util.Enumeration;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 
 import junit.framework.Assert;
 
 
 /**
- * 
- *
  * @author Trustin Lee
  * @version $Rev: 52 $, $Date: 2005-08-19 23:03:36 -0400 (Fri, 19 Aug 2005) $
- *
  */
-public class PermissionsTest extends AbstractEntityTest
-{
-    protected Object newInstanceA1()
-    {
-        return new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm1" ),
-                new Permission( "app1", "perm2" ),
-                new Permission( "app1", "perm3" ),
+public class PermissionsTest extends AbstractEntityTest {
+    protected Object newInstanceA1() {
+        return newPermissions(new StringPermission[]{
+                new StringPermission("perm1"),
+                new StringPermission("perm2"),
+                new StringPermission("perm3"),
         });
     }
 
-    protected Object newInstanceA2()
-    {
-        return new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm1" ),
-                new Permission( "app1", "perm2" ),
-                new Permission( "app1", "perm3" ),
+    private Permissions newPermissions(Permission[] permissions) {
+        Permissions perms = new Permissions();
+        for (Permission perm : permissions) {
+            perms.add(perm);
+        }
+        return perms;
+    }
+
+    protected Object newInstanceA2() {
+        return newPermissions(new StringPermission[]{
+                new StringPermission("perm1"),
+                new StringPermission("perm2"),
+                new StringPermission("perm3"),
         });
     }
 
-    protected Object newInstanceB1()
-    {
-        return new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm1" ),
+    protected Object newInstanceB1() {
+        return newPermissions(new StringPermission[]{
+                new StringPermission("perm1"),
         });
     }
 
-    protected Object newInstanceB2()
+    protected Object newInstanceB2() {
+        return newPermissions(new StringPermission[0]);
+    }
+
+    public void testEquals() {
+        assertTrue(PermissionsUtil.equivalent((Permissions) a1, (Permissions) a1));
+        assertTrue(PermissionsUtil.equivalent((Permissions) a1, (Permissions) a2));
+//        assertFalse(a1.equals(null));
+        assertFalse(PermissionsUtil.equivalent((Permissions) a1, (Permissions) b1));
+        assertFalse(PermissionsUtil.equivalent((Permissions) a1, (Permissions) b2));
+//        assertFalse(a1.equals(wrong));
+    }
+
+    public void testHashCode()
     {
-        return new Permissions( "app2", new Permission[0] );
+        //we can't affect Permissions.hashCode()
     }
-    
-    public void testInstantiation()
+
+    public void testClone() throws Exception
     {
+        //Permissions is not cloneable
+    }
+
+
+    public void testInstantiation() {
         // Test null values
-        try
-        {
-            new Permissions( null, null );
-            Assert.fail( "Execption is not thrown." );
-        }
-        catch( NullPointerException e )
-        {
-            // OK
-        }
-        
+//        try
+//        {
+//            new Permissions( null, null );
+//            Assert.fail( "Execption is not thrown." );
+//        }
+//        catch( NullPointerException e )
+//        {
+//            // OK
+//        }
+
         // Test empty values
-        try
-        {
-            new Permissions( "", null );
-            Assert.fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-        
+//        try
+//        {
+//            new Permissions( "", null );
+//            Assert.fail( "Execption is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
+
         // Test null elements
-        Permissions perms = new Permissions( "app1", new Permission[] {
-                null, null, null,
-        });
-        Assert.assertTrue( perms.isEmpty() );
-        
+//        Permissions perms = newPermissions(new StringPermission[] {
+//                null, null, null,
+//        });
+//        Assert.assertTrue( PermissionsUtil.isEmpty(perms) );
+
         // Test mismatching application names
-        try
-        {
-            new Permissions( "app1", new Permission[] {
-                    new Permission( "app2", "perm1" ),
-            });
-            Assert.fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            //OK
-        }
-        
-        Assert.assertTrue( perms.isEmpty() );
-    }
-    
-    public void testProperties()
-    {
-        Permission p1 = new Permission( "app1", "perm1" );
-        Permission p2 = new Permission( "app1", "perm2" );
-        Permission p3 = new Permission( "app1", "perm3" );
-        Permissions perms = new Permissions( "app1", new Permission[] {
+//        try
+//        {
+//            newPermissions(new StringPermission[] {
+//                    new StringPermission( "app2", "perm1" ),
+//            });
+//            Assert.fail( "Execption is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            //OK
+//        }
+
+//        Assert.assertTrue( PermissionsUtil.isEmpty(perms) );
+    }
+
+    public void testProperties() {
+        StringPermission p1 = new StringPermission("perm1");
+        StringPermission p2 = new StringPermission("perm2");
+        StringPermission p3 = new StringPermission("perm3");
+        Permissions perms = newPermissions(new StringPermission[]{
                 p1, p2, p3,
         });
-        
-        Assert.assertEquals( "app1", perms.getApplicationName() );
-        Assert.assertEquals( 3, perms.size() );
-        Assert.assertTrue( perms.contains( p1 ) );
-        Assert.assertTrue( perms.contains( p2 ) );
-        Assert.assertTrue( perms.contains( p3 ) );
-        Assert.assertTrue( perms.contains( p1.getName() ) );
-        Assert.assertTrue( perms.contains( p2.getName() ) );
-        Assert.assertTrue( perms.contains( p3.getName() ) );
-        Assert.assertEquals( p1, perms.get( p1.getName() ) );
-        Assert.assertEquals( p2, perms.get( p2.getName() ) );
-        Assert.assertEquals( p3, perms.get( p3.getName() ) );
-        
+
+//        Assert.assertEquals( "app1", perms.getApplicationName() );
+        Assert.assertEquals(3, PermissionsUtil.size(perms));
+        Assert.assertTrue(perms.implies(p1));
+        Assert.assertTrue(perms.implies(p2));
+        Assert.assertTrue(perms.implies(p3));
+
         // Test iterator integrity
         Set allPerms = new HashSet();
-        allPerms.add( p1 );
-        allPerms.add( p2 );
-        allPerms.add( p3 );
-        for( Iterator i = perms.iterator(); i.hasNext(); )
-        {
-            Permission p = ( Permission ) i.next();
-            Assert.assertTrue( allPerms.contains( p ) );
-            allPerms.remove( p );
+        allPerms.add(p1);
+        allPerms.add(p2);
+        allPerms.add(p3);
+        for (Enumeration<Permission> i = perms.elements(); i.hasMoreElements();) {
+            StringPermission p = (StringPermission) i.nextElement();
+            Assert.assertTrue(allPerms.contains(p));
+            allPerms.remove(p);
         }
     }
-    
-    public void testSetOperations()
-    {
-        Permissions perms1 = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm1" ),
+
+    public void testSetOperations() {
+        Permissions perms1 = newPermissions(new StringPermission[]{
+                new StringPermission("perm1"),
+        });
+        Permissions perms2 = newPermissions(new StringPermission[]{
+                new StringPermission("perm2"),
         });
-        Permissions perms2 = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm2" ),
+        Permissions perms12 = newPermissions(new StringPermission[]{
+                new StringPermission("perm1"),
+                new StringPermission("perm2"),
         });
-        Permissions perms12 = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm1" ),
-                new Permission( "app1", "perm2" ),
-        });
-        Permissions wrongPerms = new Permissions( "wrongApp", null );
-        
-        
+        Permissions wrongPerms = new Permissions();
+
         // addAll
-        Assert.assertEquals( perms12, perms1.addAll( perms2 ) );
-        Assert.assertEquals( perms1, perms1.addAll( perms1 ) );
-        try
-        {
-            perms1.addAll( wrongPerms );
-            Assert.fail( "Exception is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-        
+        Assert.assertTrue(PermissionsUtil.equivalent(perms12, PermissionsUtil.union(perms1, perms2)));
+        Assert.assertTrue(PermissionsUtil.equivalent(perms1, PermissionsUtil.union(perms1, perms1)));
+//        try
+//        {
+//            PermissionsUtil.union(perms1, wrongPerms );
+//            Assert.fail( "Exception is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
+
         // removeAll
-        Assert.assertEquals( perms1, perms12.removeAll( perms2 ) );
-        Assert.assertEquals( perms1, perms1.removeAll( perms2 ) );
-        try
-        {
-            perms1.removeAll( wrongPerms );
-            Assert.fail( "Exception is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-        
+//        Assert.assertEquals( perms1, perms12.removeAll( perms2 ) );
+//        Assert.assertEquals( perms1, perms1.removeAll( perms2 ) );
+//        try
+//        {
+//            perms1.removeAll( wrongPerms );
+//            Assert.fail( "Exception is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+        // OK
+//        }
+
         // retainAll
-        Assert.assertEquals( perms1, perms12.retainAll( perms1 ) );
-        Assert.assertEquals(
-                new Permissions( "app1", null ), perms1.retainAll( perms2 ) );
-        try
-        {
-            perms1.retainAll( wrongPerms );
-            Assert.fail( "Exception is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
+//        Assert.assertEquals( perms1, perms12.retainAll( perms1 ) );
+//        Assert.assertEquals(
+//                new Permissions( "app1", null ), perms1.retainAll( perms2 ) );
+//        try
+//        {
+//            perms1.retainAll( wrongPerms );
+//            Assert.fail( "Exception is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+        // OK
+//        }
 
         // containsAll
-        Assert.assertTrue( perms12.containsAll( perms12 ) );
-        Assert.assertFalse( perms1.containsAll( perms12 ) );
-        try
-        {
-            perms1.containsAll( wrongPerms );
-            Assert.fail( "Exception is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
+//        Assert.assertTrue( perms12.containsAll( perms12 ) );
+//        Assert.assertFalse( perms1.containsAll( perms12 ) );
+//        try
+//        {
+//            perms1.containsAll( wrongPerms );
+//            Assert.fail( "Exception is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//             OK
+//        }
     }
-    
-    public static void main( String[] args )
-    {
-        junit.textui.TestRunner.run( PermissionsTest.class );
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(PermissionsTest.class);
     }
 
 }

Modified: directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/ProfileTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/ProfileTest.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/ProfileTest.java (original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/ProfileTest.java Wed Dec 27 20:48:29 2006
@@ -20,6 +20,7 @@
 package org.safehaus.triplesec.guardian;
 
 import java.security.AccessControlException;
+import java.security.Permissions;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Set;
@@ -31,370 +32,286 @@
  * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
  * @version $Rev: 72 $
  */
-public class ProfileTest extends AbstractEntityTest
-{
+public class ProfileTest extends AbstractEntityTest {
     private static final ApplicationPolicy STORE1 = new TestApplicationPolicyStore(
-            "app1" );
+            "app1");
 
     private static final ApplicationPolicy STORE2 = new TestApplicationPolicyStore(
-            "app2" );
+            "app2");
 
-    protected Object newInstanceA1()
-    {
-        return new Profile( STORE1, "trustin", "trustin", null, null, null, false );
+    protected Object newInstanceA1() {
+        return new Profile(STORE1, "trustin", "trustin", null, null, null, false);
     }
 
-    protected Object newInstanceA2()
-    {
-        return new Profile( STORE1, "trustin", "trustin", null, null, null, false );
+    protected Object newInstanceA2() {
+        return new Profile(STORE1, "trustin", "trustin", null, null, null, false);
     }
 
-    protected Object newInstanceB1()
-    {
-        return new Profile( STORE1, "alex", "alex", null, null, null, false );
+    protected Object newInstanceB1() {
+        return new Profile(STORE1, "alex", "alex", null, null, null, false);
     }
 
-    protected Object newInstanceB2()
-    {
-        return new Profile( STORE2, "trustin", "trustin", null, null, null, false );
+    protected Object newInstanceB2() {
+        return new Profile(STORE2, "trustin", "trustin", null, null, null, false);
     }
 
-    public void testInstantiation()
-    {
-        Roles roles = new Roles( "app1", new Role[] {
-           new Role( STORE1, "role1", new Permissions( "app1", new Permission[] {
-                   new Permission( "app1", "perm1" ),
-           })),
-        });
-        Permissions grants = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm1" ),
-        });
-        Permissions denials = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm2" ),
+    public void testInstantiation() {
+        StringPermission perm1 = new StringPermission("perm1");
+        Roles roles = new Roles("app1", new Role[]{
+                new Role(STORE1, "role1", newPermissions(perm1), null),
         });
+        Permissions grants = newPermissions(perm1);
+        StringPermission perm2 = new StringPermission("perm2");
+        Permissions denials = newPermissions(perm2);
 
         // Test null parameters
-        try
-        {
-            new Profile( null, "trustin", "trustin", roles, grants, denials, false );
-            Assert.fail( "Execption is not thrown." );
+        try {
+            new Profile(null, "trustin", "trustin", roles, grants, denials, false);
+            Assert.fail("Execption is not thrown.");
         }
-        catch( NullPointerException e )
-        {
+        catch (NullPointerException e) {
             // OK
         }
-        try
-        {
-            new Profile( STORE1, null, "trustin", roles, grants, denials, false );
-            Assert.fail( "Execption is not thrown." );
+        try {
+            new Profile(STORE1, null, "trustin", roles, grants, denials, false);
+            Assert.fail("Execption is not thrown.");
         }
-        catch( NullPointerException e )
-        {
+        catch (NullPointerException e) {
             // OK
         }
 
         // Test empty fields
-        try
-        {
-            new Profile( STORE1, "", "trustin", roles, grants, denials, false );
-            Assert.fail( "Execption is not thrown." );
+        try {
+            new Profile(STORE1, "", "trustin", roles, grants, denials, false);
+            Assert.fail("Execption is not thrown.");
         }
-        catch( IllegalArgumentException e )
-        {
+        catch (IllegalArgumentException e) {
             // OK
         }
-        try
-        {
-            new Profile( new TestApplicationPolicyStore( "" ), "role1", "trustin", roles, grants, denials, false );
-            Assert.fail( "Execption is not thrown." );
+        try {
+            new Profile(new TestApplicationPolicyStore(""), "role1", "trustin", roles, grants, denials, false);
+            Assert.fail("Execption is not thrown.");
         }
-        catch( IllegalArgumentException e )
-        {
+        catch (IllegalArgumentException e) {
             // OK
         }
-        
+
         // Test unknown permissions
-        Permissions wrongPerms = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "wrongPerm" ),
-        });
-        try
-        {
-                                                                             
-            new Profile( STORE1, "trustin", "trustin", roles, wrongPerms, denials, false );
-            Assert.fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-        try
-        {
-                                                                             
-            new Profile( STORE1, "trustin", "trustin", roles, grants, wrongPerms, false );
-            Assert.fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-        
+        //TODO could be resuscitated if we implement impliesAll
+//        Permissions wrongPerms = new Permissions( "app1", new StringPermission[] {
+//                new StringPermission( "app1", "wrongPerm" ),
+//        });
+//        try
+//        {
+//
+//            new Profile( STORE1, "trustin", "trustin", roles, wrongPerms, denials, false );
+//            Assert.fail( "Execption is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
+//        try
+//        {
+//
+//            new Profile( STORE1, "trustin", "trustin", roles, grants, wrongPerms, false );
+//            Assert.fail( "Execption is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
 
         // Test mismatching application names.
-        try
-        {
-            new Profile( STORE2, "role1", "trustin", roles, null, null, false );
-            Assert.fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-        try
-        {
-            new Profile( STORE2, "role1", "trustin", null, grants, null, false );
-            Assert.fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-        try
-        {
-            new Profile( STORE2, "role1", "trustin", null, null, denials, false );
-            Assert.fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
+        try {
+            new Profile(STORE2, "role1", "trustin", roles, null, null, false);
+            Assert.fail("Execption is not thrown.");
+        }
+        catch (IllegalArgumentException e) {
+            // OK
+        }
+//        try {
+//            new Profile(STORE2, "role1", "trustin", null, grants, null, false);
+//            Assert.fail("Execption is not thrown.");
+//        }
+//        catch (IllegalArgumentException e) {
+//            // OK
+//        }
+//        try {
+//            new Profile(STORE2, "role1", "trustin", null, null, denials, false);
+//            Assert.fail("Execption is not thrown.");
+//        }
+//        catch (IllegalArgumentException e) {
+//            // OK
+//        }
+
+        Profile p = new Profile(STORE1, "role1", "trustin", null, null, null, false);
+        Assert.assertEquals(0, p.getRoles().size());
+        Assert.assertEquals(0, PermissionsUtil.size(p.getGrants()));
+        Assert.assertEquals(0, PermissionsUtil.size(p.getDenials()));
+        assertEquals("trustin", p.getUserName());
+    }
 
-        Profile p = new Profile( STORE1, "role1", "trustin", null, null, null, false );
-        Assert.assertEquals( 0, p.getRoles().size() );
-        Assert.assertEquals( 0, p.getGrants().size() );
-        Assert.assertEquals( 0, p.getDenials().size() );
-        assertEquals( "trustin", p.getUserName() );
+    private Permissions newPermissions(StringPermission perm1) {
+        Permissions permissions = new Permissions();
+        permissions.add(perm1);
+        return permissions;
     }
 
-    public void testProperties()
-    {
-        Roles roles = new Roles( "app1", new Role[] {
-                new Role( STORE1, "role1", new Permissions( "app1", new Permission[] {
-                        new Permission( "app1", "perm2" ),
-                        new Permission( "app1", "perm3" ),
-                        new Permission( "app1", "perm4" ),
-                })),
-        });
-        Permissions grants = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm1" ),
-                new Permission( "app1", "perm2" ),
+    public void testProperties() {
+        Permissions permissions = new Permissions();
+        permissions.add(new StringPermission("perm2"));
+        permissions.add(new StringPermission("perm3"));
+        permissions.add(new StringPermission("perm4"));
+        Roles roles = new Roles("app1", new Role[]{
+                new Role(STORE1, "role1", permissions, null),
         });
-        Permissions denials = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm3" ),
-        });
-        
-        Profile p = new Profile( STORE1, "trustin", "trustin", roles, grants, denials, "test description", false );
-        assertEquals( "app1", p.getApplicationName() );
-        assertEquals( "trustin", p.getProfileId() );
-        assertEquals( roles, p.getRoles() );
-        assertEquals( grants, p.getGrants() );
-        assertEquals( denials, p.getDenials() );
-        assertEquals( "test description", p.getDescription() );
-        
-        Permissions effectivePermissions = new Permissions( "app1", new Permission[] {
-                new Permission( "app1", "perm1" ),
-                new Permission( "app1", "perm2" ),
-                new Permission( "app1", "perm4" ),
-        });
-        assertEquals( effectivePermissions, p.getEffectivePermissions() );
-        
-        assertTrue( p.isInRole( "role1" ) );
+        Permissions grants = new Permissions();
+        grants.add(new StringPermission("perm1"));
+        grants.add(new StringPermission("perm2"));
+
+        Permissions denials = newPermissions(new StringPermission("perm3"));
+
+        Profile p = new Profile(STORE1, "trustin", "trustin", roles, grants, denials, "test description", false);
+        assertEquals("app1", p.getApplicationName());
+        assertEquals("trustin", p.getProfileId());
+        assertEquals(roles, p.getRoles());
+        assertEquals(grants, p.getGrants());
+        assertEquals(denials, p.getDenials());
+        assertEquals("test description", p.getDescription());
+
+        Permissions effectivePermissions = new Permissions();
+        effectivePermissions.add(new StringPermission("perm1"));
+        effectivePermissions.add(new StringPermission("perm2"));
+        effectivePermissions.add(new StringPermission("perm3"));
+        effectivePermissions.add(new StringPermission("perm4"));
+        assertTrue(PermissionsUtil.equivalent(effectivePermissions, p.getEffectiveGrantedPermissions()));
+        assertTrue(PermissionsUtil.equivalent(denials, p.getEffectiveDeniedPermissions()));
+
+        assertTrue(p.isInRole("role1"));
     }
 
-    public void testRolePermissions()
-    {
-        Permission perm = new Permission( "app1", "perm1" );
-        Permission wrongPerm = new Permission( "app1", "perm2" );
-        Permissions perms = new Permissions( "app1", new Permission[] { perm, } );
+    public void testRolePermissions() {
+        StringPermission perm = new StringPermission("perm1");
+        StringPermission wrongPerm = new StringPermission("perm2");
+        Permissions perms = newPermissions(perm);
 
         // Effective permissions will be: 'perm1'
         Profile p = new Profile(
                 STORE1, "trustin", "trustin",
-                new Roles( "app1", null ),
-                perms, null, false );
-        
+                new Roles("app1", null),
+                perms, null, false);
+
         // Check existing permissions
-        p.checkPermission( perm );
-        p.checkPermission( perm, "unused" );
-        p.checkPermission( perm.getName() );
-        p.checkPermission( perm.getName(), "unused" );
-        assertTrue( p.hasPermission( perm ) );
-        assertTrue( p.hasPermission( perm.getName() ) );
-        assertFalse( p.hasPermission( "nonexistant" ) );
+        p.checkPermission(perm);
+        p.checkPermission(perm, "unused");
+        assertTrue(p.implies(perm));
+        assertFalse(p.implies(new StringPermission("nonexistant")));
 
         // Check null parameters
-        try
-        {
-            p.checkPermission( ( Permission ) null );
-            Assert.fail( "Exception is not thrown." );
-        }
-        catch( NullPointerException e )
-        {
-            // OK
-        }
-        try
-        {
-            p.checkPermission( ( String ) null );
-            Assert.fail( "Exception is not thrown." );
-        }
-        catch( NullPointerException e )
-        {
-            // OK
-        }
-        try
-        {
-            p.checkPermission( ( Permission ) null, "unused" );
-            Assert.fail( "Exception is not thrown." );
+        try {
+            p.checkPermission((StringPermission) null);
+            Assert.fail("Exception is not thrown.");
         }
-        catch( NullPointerException e )
-        {
+        catch (NullPointerException e) {
             // OK
         }
-        try
-        {
-            p.checkPermission( ( String ) null, "unused" );
-            Assert.fail( "Exception is not thrown." );
+        try {
+            p.checkPermission((StringPermission) null, "unused");
+            Assert.fail("Exception is not thrown.");
         }
-        catch( NullPointerException e )
-        {
+        catch (NullPointerException e) {
             // OK
         }
-
         // Check non-existing permissions
-        try
-        {
-            p.checkPermission( wrongPerm );
-            Assert.fail( "Exception is not thrown." );
-        }
-        catch( AccessControlException e )
-        {
-            // OK
-        }
-        try
-        {
-            p.checkPermission( wrongPerm, "unused" );
-            Assert.fail( "Exception is not thrown." );
-        }
-        catch( AccessControlException e )
-        {
-            // OK
-        }
-        try
-        {
-            p.checkPermission( wrongPerm.getName() );
-            Assert.fail( "Exception is not thrown." );
+        try {
+            p.checkPermission(wrongPerm);
+            Assert.fail("Exception is not thrown.");
         }
-        catch( AccessControlException e )
-        {
+        catch (AccessControlException e) {
             // OK
         }
-        try
-        {
-            p.checkPermission( wrongPerm.getName(), "unused" );
-            Assert.fail( "Exception is not thrown." );
+        try {
+            p.checkPermission(wrongPerm, "unused");
+            Assert.fail("Exception is not thrown.");
         }
-        catch( AccessControlException e )
-        {
+        catch (AccessControlException e) {
             // OK
         }
     }
-    
-    
-    protected void _testClone( Object a, Object b )
-    {
-        Profile pa = ( Profile ) a;
-        Profile pb = ( Profile ) b;
-        Assert.assertEquals( pa.getRoles(), pb.getRoles() );
-        Assert.assertEquals( pa.getGrants(), pb.getGrants() );
-        Assert.assertEquals( pa.getDenials(), pb.getDenials() );
+
+
+    protected void _testClone(Object a, Object b) {
+        Profile pa = (Profile) a;
+        Profile pb = (Profile) b;
+        Assert.assertEquals(pa.getRoles(), pb.getRoles());
+        Assert.assertEquals(pa.getGrants(), pb.getGrants());
+        Assert.assertEquals(pa.getDenials(), pb.getDenials());
     }
 
     private static class TestApplicationPolicyStore implements
-            ApplicationPolicy
-    {
+            ApplicationPolicy {
         private final String appName;
 
-        public TestApplicationPolicyStore( String appName )
-        {
+        public TestApplicationPolicyStore(String appName) {
             this.appName = appName;
         }
 
-        public String getApplicationName()
-        {
+        public String getApplicationName() {
             return appName;
         }
 
-        public Roles getRoles()
-        {
+        public Roles getRoles() {
             return null;
         }
 
-        public Permissions getPermissions()
-        {
-            Permission[] perms = new Permission[] {
-                    new Permission( appName, "perm1" ),
-                    new Permission( appName, "perm2" ),
-                    new Permission( appName, "perm3" ),
-                    new Permission( appName, "perm4" ),
-            };
-            return new Permissions( appName, perms );
+        public Permissions getPermissions() {
+            Permissions perms = new Permissions();
+            perms.add(new StringPermission("perm1"));
+            perms.add(new StringPermission("perm2"));
+            perms.add(new StringPermission("perm3"));
+            perms.add(new StringPermission("perm4"));
+            return perms;
         }
 
-        public Profile getProfile( String userName )
-        {
+        public Profile getProfile(String userName) {
             return null;
         }
 
 
-        public String getDescription()
-        {
+        public String getDescription() {
             return null;
         }
 
 
-        public void close() {}
+        public void close() {
+        }
 
-        public boolean removePolicyListener( PolicyChangeListener listener )
-        {
+        public boolean removePolicyListener(PolicyChangeListener listener) {
             return false;
         }
 
-        public boolean addPolicyListener( PolicyChangeListener listener )
-        {
+        public boolean addPolicyListener(PolicyChangeListener listener) {
             return false;
         }
 
-        public Set getDependentProfileNames( Role role ) throws GuardianException
-        {
+        public Set getDependentProfileNames(Role role) throws GuardianException {
             return null;
         }
 
-        public Set getDependentProfileNames( Permission permission ) throws GuardianException
-        {
+        public Set getDependentProfileNames(StringPermission permission) throws GuardianException {
             return null;
         }
 
-        public Set getUserProfileIds( String userName ) throws GuardianException
-        {
+        public Set getUserProfileIds(String userName) throws GuardianException {
             return Collections.EMPTY_SET;
         }
 
-        public Iterator getProfileIdIterator() throws GuardianException
-        {
+        public Iterator getProfileIdIterator() throws GuardianException {
             return null;
         }
 
-        public Profile getAdminProfile()
-        {
+        public Profile getAdminProfile() {
             return null;
         }
     }

Modified: directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/RoleTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/RoleTest.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/RoleTest.java (original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/RoleTest.java Wed Dec 27 20:48:29 2006
@@ -21,6 +21,7 @@
 
 
 import java.security.AccessControlException;
+import java.security.Permissions;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Set;
@@ -41,32 +42,32 @@
 
     protected Object newInstanceA1()
     {
-        return new Role( STORE1, "role1", null );
+        return new Role( STORE1, "role1", null, null);
     }
 
     protected Object newInstanceA2()
     {
-        return new Role( STORE1, "role1", null );
+        return new Role( STORE1, "role1", null, null);
     }
 
     protected Object newInstanceB1()
     {
-        return new Role( STORE1, "role2", null );
+        return new Role( STORE1, "role2", null, null);
     }
 
     protected Object newInstanceB2()
     {
-        return new Role( STORE2, "role1", null );
+        return new Role( STORE2, "role1", null, null);
     }
 
     public void testInstantiation()
     {
-        Permissions perms = new Permissions( "app1", null );
+        Permissions perms = new Permissions();
 
         // Test null parameters
         try
         {
-            new Role( null, "role1", perms );
+            new Role( null, "role1", perms, null);
             fail( "Execption is not thrown." );
         }
         catch( NullPointerException e )
@@ -75,7 +76,7 @@
         }
         try
         {
-            new Role( STORE1, null, perms );
+            new Role( STORE1, null, perms, null);
             fail( "Execption is not thrown." );
         }
         catch( NullPointerException e )
@@ -86,91 +87,90 @@
         // Test empty fields
         try
         {
-            new Role( STORE2, "", perms );
-            fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-        try
-        {
-            new Role( new TestApplicationPolicyStore( "" ), "role1", perms );
+            new Role( STORE2, "", perms, null);
             fail( "Execption is not thrown." );
         }
         catch( IllegalArgumentException e )
         {
             // OK
         }
+//        try
+//        {
+//            new Role( new TestApplicationPolicyStore( "" ), "role1", perms );
+//            fail( "Execption is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
         
         // Test unknown permissions
-        try
-        {
-            Permissions wrongPerms = new Permissions( "app1", new Permission[] {
-                    new Permission( "app1", "wrongPerm" ),
-            });
-                                                                             
-            new Role( STORE1, "role1", wrongPerms );
-            fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
+        //TODO could be resuscitated if we had an impliesAll method.
+//        try
+//        {
+//            Permissions wrongPerms = new Permissions( "app1", new StringPermission[] {
+//                    new StringPermission( "app1", "wrongPerm" ),
+//            });
+//
+//            new Role( STORE1, "role1", wrongPerms );
+//            fail( "Execption is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
         
 
         // Test mismatching application names.
-        try
-        {
-            new Role( STORE2, "role1", perms );
-            fail( "Execption is not thrown." );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK
-        }
-
-        Role r = new Role( STORE1, "role1", null );
-        assertEquals( 0, r.getGrants().size() );
+//        try
+//        {
+//            new Role( STORE2, "role1", perms );
+//            fail( "Execption is not thrown." );
+//        }
+//        catch( IllegalArgumentException e )
+//        {
+//            // OK
+//        }
+
+        Role r = new Role( STORE1, "role1", null, null);
+        assertEquals( 0, PermissionsUtil.size(r.getGrantedPermissions()) );
+        assertEquals( 0, PermissionsUtil.size(r.getDeniedPermissions()) );
     }
 
     public void testProperties()
     {
-        Permission perm1= new Permission( "app1", "perm1" );
-        Permissions perms = new Permissions( "app1", new Permission[] {
-                perm1,
-                new Permission( "app1", "perm2" ),
-                new Permission( "app1", "perm3" ), } );
+        StringPermission perm1= new StringPermission("perm1" );
+        Permissions perms = new Permissions();
+                perms.add(perm1);
+                perms.add(new StringPermission("perm2" ));
+                perms.add(new StringPermission("perm3" ));
 
-        Role r = new Role( STORE1, "role1", perms, "test description" );
+        Role r = new Role( STORE1, "role1", perms, null, "test description" );
         assertEquals( "app1", r.getApplicationName() );
         assertEquals( "role1", r.getName() );
-        assertEquals( perms, r.getGrants() );
+        assertEquals( perms, r.getGrantedPermissions() );
         assertEquals( "test description", r.getDescription() );
         assertTrue( r.hasPermission( perm1 ) ) ;
-        assertTrue( r.hasPermission( perm1.getName() ) ) ;
     }
 
     public void testRolePermissions()
     {
-        Permission perm = new Permission( "app1", "perm1" );
-        Permission wrongPerm = new Permission( "app1", "perm2" );
-        Permissions perms = new Permissions( "app1", new Permission[] { perm, } );
+        StringPermission perm = new StringPermission("perm1" );
+        StringPermission wrongPerm = new StringPermission("perm2" );
+        Permissions perms = new Permissions();
+        perms.add(perm);
 
-        Role r = new Role( STORE1, "role1", perms );
+        Role r = new Role( STORE1, "role1", perms, null);
 
         // Check existing permissions
         r.checkPermission( perm );
-        assertTrue( r.hasPermission( perm.getName() ) );
         assertTrue( r.hasPermission( perm ) );
         r.checkPermission( perm, "unused" );
-        r.checkPermission( perm.getName() );
-        r.checkPermission( perm.getName(), "unused" );
 
         // Check null parameters
         try
         {
-            r.checkPermission( ( Permission ) null );
+            r.checkPermission( ( StringPermission ) null );
             fail( "Exception is not thrown." );
         }
         catch( NullPointerException e )
@@ -179,32 +179,13 @@
         }
         try
         {
-            r.checkPermission( ( String ) null );
+            r.checkPermission( ( StringPermission ) null, "unused" );
             fail( "Exception is not thrown." );
         }
         catch( NullPointerException e )
         {
             // OK
         }
-        try
-        {
-            r.checkPermission( ( Permission ) null, "unused" );
-            fail( "Exception is not thrown." );
-        }
-        catch( NullPointerException e )
-        {
-            // OK
-        }
-        try
-        {
-            r.checkPermission( ( String ) null, "unused" );
-            fail( "Exception is not thrown." );
-        }
-        catch( NullPointerException e )
-        {
-            // OK
-        }
-
         // Check non-existing permissions
         try
         {
@@ -224,24 +205,6 @@
         {
             // OK
         }
-        try
-        {
-            r.checkPermission( wrongPerm.getName() );
-            fail( "Exception is not thrown." );
-        }
-        catch( AccessControlException e )
-        {
-            // OK
-        }
-        try
-        {
-            r.checkPermission( wrongPerm.getName(), "unused" );
-            fail( "Exception is not thrown." );
-        }
-        catch( AccessControlException e )
-        {
-            // OK
-        }
     }
     
     
@@ -250,7 +213,7 @@
     {
         Role ra = ( Role ) a;
         Role rb = ( Role ) b;
-        assertEquals( ra.getGrants(), rb.getGrants() );
+        assertEquals( ra.getGrantedPermissions(), rb.getGrantedPermissions() );
     }
 
     private static class TestApplicationPolicyStore implements
@@ -273,14 +236,12 @@
             return null;
         }
 
-        public Permissions getPermissions()
-        {
-            Permission[] perms = new Permission[] {
-                    new Permission( appName, "perm1" ),
-                    new Permission( appName, "perm2" ),
-                    new Permission( appName, "perm3" ),
-            };
-            return new Permissions( appName, perms );
+        public Permissions getPermissions() {
+            Permissions perms = new Permissions();
+            perms.add(new StringPermission("perm1"));
+            perms.add(new StringPermission("perm2"));
+            perms.add(new StringPermission("perm3"));
+            return perms;
         }
 
         public Profile getProfile( String userName )
@@ -310,7 +271,7 @@
             return null;
         }
 
-        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/RolesTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/RolesTest.java?view=diff&rev=490646&r1=490645&r2=490646
==============================================================================
--- directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/RolesTest.java (original)
+++ directory/trunks/triplesec/guardian-api/src/test/java/org/safehaus/triplesec/guardian/RolesTest.java Wed Dec 27 20:48:29 2006
@@ -19,6 +19,7 @@
  */
 package org.safehaus.triplesec.guardian;
 
+import java.security.Permissions;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -36,34 +37,35 @@
  */
 public class RolesTest extends AbstractEntityTest
 {
+    private static final String APP1 = "app1";
     private static final ApplicationPolicy STORE1 = new TestApplicationPolicyStore(
-            "app1" );
+            APP1 );
 
     private static final ApplicationPolicy STORE2 = new TestApplicationPolicyStore(
             "app2" );
 
     protected Object newInstanceA1()
     {
-        return new Roles( "app1", new Role[] {
-                new Role( STORE1, "role1", null ),
-                new Role( STORE1, "role2", null ),
-                new Role( STORE1, "role3", null ),
+        return new Roles( APP1, new Role[] {
+                new Role( STORE1, "role1", null, null),
+                new Role( STORE1, "role2", null, null),
+                new Role( STORE1, "role3", null, null),
         });
     }
 
     protected Object newInstanceA2()
     {
-        return new Roles( "app1", new Role[] {
-                new Role( STORE1, "role1", null ),
-                new Role( STORE1, "role2", null ),
-                new Role( STORE1, "role3", null ),
+        return new Roles( APP1, new Role[] {
+                new Role( STORE1, "role1", null, null),
+                new Role( STORE1, "role2", null, null),
+                new Role( STORE1, "role3", null, null),
         });
     }
 
     protected Object newInstanceB1()
     {
-        return new Roles( "app1", new Role[] {
-                new Role( STORE1, "role1", null ),
+        return new Roles( APP1, new Role[] {
+                new Role( STORE1, "role1", null, null),
         });
     }
 
@@ -97,7 +99,7 @@
         }
         
         // Test null elements
-        Roles roles = new Roles( "app1", new Role[] {
+        Roles roles = new Roles( APP1, new Role[] {
                 null, null, null,
         });
         Assert.assertTrue( roles.isEmpty() );
@@ -105,8 +107,8 @@
         // Test mismatching application names
         try
         {
-            new Roles( "app1", new Role[] {
-                    new Role( STORE2, "role1", null ),
+            new Roles( APP1, new Role[] {
+                    new Role( STORE2, "role1", null, null),
             });
             Assert.fail( "Execption is not thrown." );
         }
@@ -120,14 +122,14 @@
     
     public void testProperties()
     {
-        Role r1 = new Role( STORE1, "role1", null );
-        Role r2 = new Role( STORE1, "role2", null );
-        Role r3 = new Role( STORE1, "role3", null );
-        Roles roles = new Roles( "app1", new Role[] {
+        Role r1 = new Role( STORE1, "role1", null, null);
+        Role r2 = new Role( STORE1, "role2", null, null);
+        Role r3 = new Role( STORE1, "role3", null, null);
+        Roles roles = new Roles( APP1, new Role[] {
                 r1, r2, r3,
         });
         
-        Assert.assertEquals( "app1", roles.getApplicationName() );
+        Assert.assertEquals( APP1, roles.getApplicationName() );
         Assert.assertEquals( 3, roles.size() );
         Assert.assertTrue( roles.contains( r1 ) );
         Assert.assertTrue( roles.contains( r2 ) );
@@ -154,15 +156,15 @@
     
     public void testSetOperations()
     {
-        Roles roles1 = new Roles( "app1", new Role[] {
-                new Role( STORE1, "role1", null ),
+        Roles roles1 = new Roles( APP1, new Role[] {
+                new Role( STORE1, "role1", null, null),
         });
-        Roles roles2 = new Roles( "app1", new Role[] {
-                new Role( STORE1, "role2", null ),
+        Roles roles2 = new Roles( APP1, new Role[] {
+                new Role( STORE1, "role2", null, null),
         });
-        Roles roles12 = new Roles( "app1", new Role[] {
-                new Role( STORE1, "role1", null ),
-                new Role( STORE1, "role2", null ),
+        Roles roles12 = new Roles( APP1, new Role[] {
+                new Role( STORE1, "role1", null, null),
+                new Role( STORE1, "role2", null, null),
         });
         Roles wrongRoles = new Roles( "wrongApp", null );
         
@@ -222,35 +224,35 @@
     }
     
     
-    public void testGetDependentRoles()
-    {
-        Role role1 = new Role( STORE1, "role1", STORE1.getPermissions() );
-        Role role2 = new Role( STORE1, "role2", null );
-        Roles roles12 = new Roles( "app1", new Role[] { role1, role2 });
-
-        Roles dependents = roles12.getDependentRoles( "perm1" );
-        assertEquals( 1, dependents.size() );
-        assertEquals( role1, dependents.get( "role1" ) );
-        
-        dependents = roles12.getDependentRoles( STORE1.getPermissions().get( "perm1" ) );
-        assertEquals( 1, dependents.size() );
-        assertEquals( role1, dependents.get( "role1" ) );
-
-        dependents = roles12.getDependentRoles( "perm99" );
-        assertEquals( 0, dependents.size() );
-
-        dependents = roles12.getDependentRoles( new Permission( "app1", "perm99" ) );
-        assertEquals( 0, dependents.size() );
-        
-        try
-        {
-            dependents = roles12.getDependentRoles( new Permission( "blah", "perm99" ) );
-            fail( "Should never get here due to an exception" );
-        }
-        catch ( IllegalArgumentException e )
-        {
-        }
-    }
+//    public void testGetDependentRoles()
+//    {
+//        Role role1 = new Role( STORE1, "role1", STORE1.getPermissions(), null);
+//        Role role2 = new Role( STORE1, "role2", null, null);
+//        Roles roles12 = new Roles( APP1, new Role[] { role1, role2 });
+//
+//        Roles dependents = roles12.getDependentRoles(new StringPermission(APP1, "perm1" ));
+//        assertEquals( 1, dependents.size() );
+//        assertEquals( role1, dependents.get( "role1" ) );
+//
+//        dependents = roles12.getDependentRoles(new StringPermission(APP1,   "perm1" ));
+//        assertEquals( 1, dependents.size() );
+//        assertEquals( role1, dependents.get( "role1" ) );
+//
+//        dependents = roles12.getDependentRoles(new StringPermission(APP1,  "perm99" ));
+//        assertEquals( 0, dependents.size() );
+//
+//        dependents = roles12.getDependentRoles( new StringPermission( APP1, "perm99" ) );
+//        assertEquals( 0, dependents.size() );
+//
+//        try
+//        {
+//            dependents = roles12.getDependentRoles( new StringPermission( "blah", "perm99" ) );
+//            fail( "Should never get here due to an exception" );
+//        }
+//        catch ( IllegalArgumentException e )
+//        {
+//        }
+//    }
     
     
     public static void main( String[] args )
@@ -277,16 +279,14 @@
             return null;
         }
         
-        public Permissions getPermissions()
-        {
-            Permission[] perms = new Permission[] {
-                    new Permission( appName, "perm1" ),
-                    new Permission( appName, "perm2" ),
-                    new Permission( appName, "perm3" ),
-            };
-            return new Permissions( appName, perms );
+        public Permissions getPermissions() {
+            Permissions perms = new Permissions();
+            perms.add(new StringPermission("perm1"));
+            perms.add(new StringPermission("perm2"));
+            perms.add(new StringPermission("perm3"));
+            return perms;
         }
-        
+
         public Profile getProfile( String userName )
         {
             return null;
@@ -314,7 +314,7 @@
             return null;
         }
 
-        public Set getDependentProfileNames( Permission permission ) throws GuardianException
+        public Set getDependentProfileNames( StringPermission permission ) throws GuardianException
         {
             return null;
         }



Mime
View raw message