You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by vt...@apache.org on 2004/06/05 21:25:37 UTC

svn commit: rev 20840 - in incubator/directory/janus/trunk: core/api/src/java/org/apache/janus/authentication core/api/src/java/org/apache/janus/authorization/role core/impl/src/java/org/apache/janus/authentication/realm core/impl/src/java/org/apache/janus/authorization core/impl/src/java/org/apache/janus/authorization/policy core/impl/src/java/org/apache/janus/authorization/role core/impl/src/test/org/apache/janus/authorization core/impl/src/test/org/apache/janus/authorization/policy core/impl/src/test/org/apache/janus/authorization/role script/src/java/org/apache/janus/script script/src/java/org/apache/janus/script/xml script/src/test/org/apache/janus/script/xml

Author: vtence
Date: Sat Jun  5 12:25:35 2004
New Revision: 20840

Modified:
   incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Authenticator.java
   incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Credential.java
   incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java
   incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authorization/role/RoleManager.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/AbstractPrincipal.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/DefaultRealm.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePrincipal.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/AbstractPermission.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/BasicPermission.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/DefaultAuthorizer.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/DefaultPolicyContext.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/PermissionCollection.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/role/DefaultRoleManager.java
   incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/role/RoleMembership.java
   incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/DefaultAuthorizerTest.java
   incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/SSNPrincipal.java
   incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/policy/DefaultPolicyContextTest.java
   incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/role/DefaultRoleManagerTest.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/PolicyContextBuilder.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/RoleManagerBuilder.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JPolicyContextBuilder.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRoleManagerBuilder.java
   incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JPolicyContextBuilderTest.java
   incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
   incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRoleManagerBuilderTest.java
Log:
o Fixed DIRJANUS-19 o Fixed DIRJANUS-21

Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Authenticator.java
==============================================================================
--- incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Authenticator.java	(original)
+++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Authenticator.java	Sat Jun  5 12:25:35 2004
@@ -37,8 +37,7 @@
      *
      * @param credentials A collection of credential objects provided as proof of identity
      * @return a Subject populated with appropriate principals
-     * @throws AuthenticationException
-     *          thrown if there is a problem during authentication
+     * @throws AuthenticationException thrown if there is a problem during authentication
      */
     Subject authenticate( CredentialSet credentials )
             throws AuthenticationException;

Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Credential.java
==============================================================================
--- incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Credential.java	(original)
+++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/Credential.java	Sat Jun  5 12:25:35 2004
@@ -55,7 +55,7 @@
         if ( this == o ) return true;
         if ( !(o instanceof Credential) ) return false;
 
-        final Credential credential = (Credential) o;
+        final Credential credential = ( Credential ) o;
 
         if ( !m_type.equals( credential.m_type ) ) return false;
         if ( !m_value.equals( credential.m_value ) ) return false;

Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java
==============================================================================
--- incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java	(original)
+++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authentication/CredentialSet.java	Sat Jun  5 12:25:35 2004
@@ -87,7 +87,7 @@
         final CredentialSet subSet = new CredentialSet();
         for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
         {
-            final Credential c = (Credential) it.next();
+            final Credential c = ( Credential ) it.next();
             if ( c.isOfType( type ) ) subSet.add( c );
         }
 
@@ -98,7 +98,7 @@
     {
         for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
         {
-            final Credential c = (Credential) it.next();
+            final Credential c = ( Credential ) it.next();
             if ( c.isOfType( type ) ) return c;
         }
 
@@ -115,7 +115,7 @@
         if ( this == o ) return true;
         if ( !(o instanceof CredentialSet) ) return false;
 
-        final CredentialSet credentialSet = (CredentialSet) o;
+        final CredentialSet credentialSet = ( CredentialSet ) o;
 
         if ( !m_credentials.equals( credentialSet.m_credentials ) ) return false;
 
@@ -134,7 +134,7 @@
         StringBuffer sb = new StringBuffer( "{" );
         for ( Iterator it = m_credentials.iterator(); it.hasNext(); )
         {
-            Credential c = (Credential) it.next();
+            Credential c = ( Credential ) it.next();
             sb.append( c ).append( ", " );
         }
 

Modified: incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authorization/role/RoleManager.java
==============================================================================
--- incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authorization/role/RoleManager.java	(original)
+++ incubator/directory/janus/trunk/core/api/src/java/org/apache/janus/authorization/role/RoleManager.java	Sat Jun  5 12:25:35 2004
@@ -23,5 +23,9 @@
  */
 public interface RoleManager
 {
-    boolean isPrincipalGranted( Principal p, Grant grant );
+    String[] getRoles( Principal p );
+
+    boolean grant( Principal p, String roleName );
+
+    boolean isInRole( Principal p, String roleName );
 }

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/AbstractPrincipal.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/AbstractPrincipal.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/AbstractPrincipal.java	Sat Jun  5 12:25:35 2004
@@ -46,9 +46,9 @@
     public boolean equals( Object o )
     {
         if ( this == o ) return true;
-        if ( !( o instanceof AbstractPrincipal ) ) return false;
+        if ( !(o instanceof AbstractPrincipal) ) return false;
 
-        final AbstractPrincipal abstractPrincipal = (AbstractPrincipal) o;
+        final AbstractPrincipal abstractPrincipal = ( AbstractPrincipal ) o;
 
         if ( !m_name.equals( abstractPrincipal.m_name ) ) return false;
 

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/DefaultRealm.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/DefaultRealm.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/DefaultRealm.java	Sat Jun  5 12:25:35 2004
@@ -31,6 +31,11 @@
     private final AuthenticationMethod m_authenticationMethod;
     private final Collection m_identities;
 
+    public DefaultRealm()
+    {
+        this( new UsernamePasswordAuthentication() );
+    }
+
     public DefaultRealm( AuthenticationMethod authenticationMethod )
     {
         m_authenticationMethod = authenticationMethod;
@@ -49,8 +54,7 @@
     {
         if ( !m_authenticationMethod.supports( credentials ) )
         {
-            throw new IllegalArgumentException(
-                    "Credentials not supported by authentication method" );
+            throw new IllegalArgumentException( "Credentials not supported by authentication method" );
         }
         if ( contains( credentials ) ) return false;
         m_identities.add( new CredentialSet( credentials ) );
@@ -68,7 +72,7 @@
     {
         for ( Iterator it = m_identities.iterator(); it.hasNext(); )
         {
-            CredentialSet creds = (CredentialSet) it.next();
+            CredentialSet creds = ( CredentialSet ) it.next();
             if ( criterion.matches( creds ) ) return true;
         }
 

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePrincipal.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePrincipal.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authentication/realm/UsernamePrincipal.java	Sat Jun  5 12:25:35 2004
@@ -29,7 +29,7 @@
     public boolean equals( Object o )
     {
         if ( this == o ) return true;
-        if ( !( o instanceof UsernamePrincipal ) ) return false;
+        if ( !(o instanceof UsernamePrincipal) ) return false;
         if ( !super.equals( o ) ) return false;
 
         return true;

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/AbstractPermission.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/AbstractPermission.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/AbstractPermission.java	Sat Jun  5 12:25:35 2004
@@ -45,9 +45,9 @@
     public boolean equals( Object o )
     {
         if ( this == o ) return true;
-        if ( !( o instanceof AbstractPermission ) ) return false;
+        if ( !(o instanceof AbstractPermission) ) return false;
 
-        final AbstractPermission abstractPermission = (AbstractPermission) o;
+        final AbstractPermission abstractPermission = ( AbstractPermission ) o;
 
         if ( !m_resource.equals( abstractPermission.m_resource ) ) return false;
 

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/BasicPermission.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/BasicPermission.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/BasicPermission.java	Sat Jun  5 12:25:35 2004
@@ -40,7 +40,7 @@
 
     public boolean equals( Object o )
     {
-        if (!(o instanceof BasicPermission)) return false;
+        if ( !(o instanceof BasicPermission) ) return false;
 
         return super.equals( o );
     }

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/DefaultAuthorizer.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/DefaultAuthorizer.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/DefaultAuthorizer.java	Sat Jun  5 12:25:35 2004
@@ -46,11 +46,12 @@
         Set principals = subject.getPrincipals();
         for ( Iterator it = principals.iterator(); it.hasNext(); )
         {
-            final Principal p = (Principal) it.next();
-            if ( m_roleManager.isPrincipalGranted( p,
-                    new PermissionGrant( m_policyContext, permission ) ) )
+            final Principal p = ( Principal ) it.next();
+            String[] roles = m_roleManager.getRoles( p );
+            for ( int i = 0; i < roles.length; i++ )
             {
-                return true;
+                final String role = roles[i];
+                if ( m_policyContext.checkPermission( role, permission ) ) return true;
             }
         }
 

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/DefaultPolicyContext.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/DefaultPolicyContext.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/DefaultPolicyContext.java	Sat Jun  5 12:25:35 2004
@@ -92,7 +92,7 @@
 
     private PermissionCollection getPermissions( String roleName )
     {
-        PermissionCollection permissions = (PermissionCollection) m_roles.get( roleName );
+        PermissionCollection permissions = ( PermissionCollection ) m_roles.get( roleName );
         return permissions;
     }
 

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/PermissionCollection.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/PermissionCollection.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/policy/PermissionCollection.java	Sat Jun  5 12:25:35 2004
@@ -53,8 +53,8 @@
     {
         for ( Iterator it = m_permissions.iterator(); it.hasNext(); )
         {
-            Permission p = (Permission) it.next();
-            if (p.implies( permission )) return true;
+            Permission p = ( Permission ) it.next();
+            if ( p.implies( permission ) ) return true;
         }
 
         return false;
@@ -64,8 +64,8 @@
     {
         for ( Iterator it = m_permissions.iterator(); it.hasNext(); )
         {
-            Permission p = (Permission) it.next();
-            if (permission.implies( p )) return true;
+            Permission p = ( Permission ) it.next();
+            if ( permission.implies( p ) ) return true;
         }
 
         return false;

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/role/DefaultRoleManager.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/role/DefaultRoleManager.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/role/DefaultRoleManager.java	Sat Jun  5 12:25:35 2004
@@ -17,43 +17,62 @@
 package org.apache.janus.authorization.role;
 
 import java.security.Principal;
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
+import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Set;
+import java.util.Map;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
-public class DefaultRoleManager implements MutableRoleManager
+public class DefaultRoleManager implements RoleManager
 {
-    private final Set m_memberships;
+    private final Map m_memberships;
 
     public DefaultRoleManager()
     {
-        this( Collections.EMPTY_LIST );
+        m_memberships = new HashMap();
     }
 
-    protected DefaultRoleManager( Collection memberships )
+    public String[] getRoles( Principal p )
     {
-        m_memberships = new HashSet( memberships );
+        final Collection roles = new ArrayList();
+        for ( Iterator it = m_memberships.values().iterator(); it.hasNext(); )
+        {
+            final RoleMembership m = ( RoleMembership ) it.next();
+            if ( m.inRole( p ) ) roles.add( m.getRoleName() );
+        }
+
+        return ( String[] ) roles.toArray( new String[roles.size()] );
     }
 
-    public boolean isPrincipalGranted( Principal p, Grant grant )
+    public boolean isInRole( Principal p, String roleName )
     {
-        for ( Iterator it = m_memberships.iterator(); it.hasNext(); )
-        {
-            RoleMembership m = (RoleMembership) it.next();
-            if ( m.inRole( p ) && m.given( grant ) ) return true;
-        }
+        RoleMembership m = getMembership( roleName );
+        return (m != null && m.inRole( p ));
+    }
 
-        return false;
+    private RoleMembership getMembership( String roleName )
+    {
+        final RoleMembership m = ( RoleMembership ) m_memberships.get( roleName );
+        return m;
+    }
+
+    public boolean grant( Principal p, String roleName )
+    {
+        if ( !roleDefined( roleName ) ) defineRole( roleName );
+        RoleMembership m = getMembership( roleName );
+        return m.addMember( p );
+    }
+
+    private boolean roleDefined( String roleName )
+    {
+        return m_memberships.containsKey( roleName );
     }
 
-    public boolean grantMembership( String roleName, Principal p )
+    private void defineRole( String roleName )
     {
-        RoleMembership membership = new RoleMembership( roleName, p );
-        return m_memberships.add( membership );
+        m_memberships.put( roleName, new RoleMembership( roleName ) );
     }
 }

Modified: incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/role/RoleMembership.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/role/RoleMembership.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/java/org/apache/janus/authorization/role/RoleMembership.java	Sat Jun  5 12:25:35 2004
@@ -17,6 +17,8 @@
 package org.apache.janus.authorization.role;
 
 import java.security.Principal;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
@@ -24,42 +26,31 @@
 public class RoleMembership
 {
     private final String m_roleName;
-    private final Principal m_principal;
+    private final Set m_members;
 
-    public RoleMembership( String roleName, Principal p )
+    public RoleMembership( String roleName )
     {
         m_roleName = roleName;
-        m_principal = p;
+        m_members = new HashSet();
     }
 
     public boolean inRole( Principal p )
     {
-        return m_principal.equals( p );
+        return m_members.contains( p );
     }
 
-    public boolean given( Grant g )
+    public boolean addMember( Principal p )
     {
-        return g.given( m_roleName );
+        return m_members.add( p );
     }
 
-    public boolean equals( Object o )
+    public String getRoleName()
     {
-        if ( this == o ) return true;
-        if ( !(o instanceof RoleMembership) ) return false;
-
-        final RoleMembership m = (RoleMembership) o;
-
-        if ( !m_principal.equals( m.m_principal ) ) return false;
-        if ( !m_roleName.equals( m.m_roleName ) ) return false;
-
-        return true;
+        return m_roleName;
     }
 
-    public int hashCode()
+    public boolean roleIs( String roleName )
     {
-        int result;
-        result = m_roleName.hashCode();
-        result = 29 * result + m_principal.hashCode();
-        return result;
+        return m_roleName.equals( roleName );
     }
 }

Modified: incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/DefaultAuthorizerTest.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/DefaultAuthorizerTest.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/DefaultAuthorizerTest.java	Sat Jun  5 12:25:35 2004
@@ -17,9 +17,8 @@
 package org.apache.janus.authorization;
 
 import org.apache.janus.authentication.realm.UsernamePrincipal;
-import org.apache.janus.authorization.policy.PolicyContext;
-import org.apache.janus.authorization.role.RoleManager;
-import org.jmock.Mock;
+import org.apache.janus.authorization.policy.DefaultPolicyContext;
+import org.apache.janus.authorization.role.DefaultRoleManager;
 import org.jmock.MockObjectTestCase;
 
 import javax.security.auth.Subject;
@@ -30,8 +29,8 @@
 public class DefaultAuthorizerTest extends MockObjectTestCase
 {
     private DefaultAuthorizer m_authorizer;
-    private Mock m_mockPolicyContext;
-    private Mock m_mockRoleManager;
+    private DefaultPolicyContext m_policyContext;
+    private DefaultRoleManager m_roleManager;
 
     public static void main( String[] args )
     {
@@ -40,64 +39,56 @@
 
     protected void setUp() throws Exception
     {
-        m_mockPolicyContext = new Mock( PolicyContext.class );
-        m_mockRoleManager = new Mock( RoleManager.class );
-        m_authorizer = new DefaultAuthorizer( ( PolicyContext ) m_mockPolicyContext.proxy(),
-                ( org.apache.janus.authorization.role.RoleManager ) m_mockRoleManager.proxy() );
+        m_policyContext = new DefaultPolicyContext();
+        m_roleManager = new DefaultRoleManager();
+        m_authorizer = new DefaultAuthorizer( m_policyContext, m_roleManager );
 
     }
 
     public void testUncheckedPermissionsAreGrantedToAnyone()
     {
-        m_mockPolicyContext.stubs().method( "requiresPriviledges" ).with( eq( new UncheckedPermission() ) ).will( returnValue( false ) );
+        m_policyContext.addToUncheckedPolicy( new UncheckedPermission() );
         assertTrue( "Unchecked permission was not granted",
-                m_authorizer.checkAuthorization( user( "johnDoe" ),
+                m_authorizer.checkAuthorization( subject( "johnDoe" ),
                         new UncheckedPermission() ) );
     }
 
     public void testSubjectWithoutPrincipalIsNotAuthorized()
     {
-        m_mockPolicyContext.stubs().method( "requiresPriviledges" ).with( eq( new CheckedPermission() ) ).will( returnValue( true ) );
+        m_policyContext.addToRole( "subject", new CheckedPermission() );
 
         assertFalse( "Authorization given to subject with no role",
                 m_authorizer.checkAuthorization( new Subject(),
                         new CheckedPermission() ) );
     }
 
-    public void testSubjectWithASinglePrincipalIsAuthorizedIfPrincipalIsInRole()
+    public void testSubjectIsAuthorizedIfOnePrincipalIsInRole()
     {
-        m_mockPolicyContext.stubs().method( "requiresPriviledges" ).with( eq( new CheckedPermission() ) ).will( returnValue( true ) );
-        m_mockRoleManager.stubs().method( "isPrincipalGranted" ).
-                with( eq( new UsernamePrincipal( "johnDoe" ) ), isA( PermissionGrant.class ) ).
-                will( returnValue( true ) );
-        assertTrue( "Principal in role did not get authorization",
-                m_authorizer.checkAuthorization( user( "johnDoe" ),
-                        new CheckedPermission() ) );
+        m_policyContext.addToRole( "insured", new CheckedPermission() );
+        m_roleManager.grant( new UsernamePrincipal( "janeDoe" ), "citizen" );
+        m_roleManager.grant( new SSNPrincipal( "123-456-789" ), "insured" );
+        assertTrue( m_authorizer.checkAuthorization( subject( "janeDoe", "123-456-789" ),
+                new CheckedPermission() ) );
     }
 
-    public void testSubjectWithSeveralPrincipalsIsAuthorizedIfOnePrincipalIsInRole()
+    public void testSubjectIsAuthorizedIfOneRoleHasAuthorization()
     {
-        m_mockPolicyContext.stubs().method( "requiresPriviledges" ).with( eq( new CheckedPermission() ) ).will( returnValue( true ) );
-        m_mockRoleManager.stubs().method( "isPrincipalGranted" ).
-                with( eq( new SSNPrincipal( "123-456-789" ) ), isA( PermissionGrant.class ) ).
-                will( returnValue( false ) );
-        m_mockRoleManager.stubs().method( "isPrincipalGranted" ).
-                with( eq( new UsernamePrincipal( "janeDoe" ) ), isA( PermissionGrant.class ) ).
-                will( returnValue( true ) );
+        m_policyContext.addToRole( "vip", new CheckedPermission() );
+        m_roleManager.grant( new UsernamePrincipal( "johnDoe" ), "subject" );
+        m_roleManager.grant( new UsernamePrincipal( "johnDoe" ), "vip" );
 
-        assertTrue( "Subject with principal in role did not get authorization",
-                m_authorizer.checkAuthorization( member( "janeDoe", "123-456-789" ),
-                        new CheckedPermission() ) );
+        assertTrue( m_authorizer.checkAuthorization( subject( "johnDoe" ),
+                new CheckedPermission() ) );
     }
 
-    private Subject user( String username )
+    private Subject subject( String username )
     {
         Subject subject = new Subject();
         subject.getPrincipals().add( new UsernamePrincipal( username ) );
         return subject;
     }
 
-    private Subject member( String username, String ssn )
+    private Subject subject( String username, String ssn )
     {
         Subject subject = new Subject();
         subject.getPrincipals().add( new UsernamePrincipal( username ) );

Modified: incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/SSNPrincipal.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/SSNPrincipal.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/SSNPrincipal.java	Sat Jun  5 12:25:35 2004
@@ -23,15 +23,15 @@
  */
 public class SSNPrincipal extends AbstractPrincipal
 {
-    public SSNPrincipal( String name )
+    public SSNPrincipal( String ssn )
     {
-        super( name );
+        super( ssn );
     }
 
     public boolean equals( Object o )
     {
         if ( this == o ) return true;
-        if ( !( o instanceof SSNPrincipal ) ) return false;
+        if ( !(o instanceof SSNPrincipal) ) return false;
         if ( !super.equals( o ) ) return false;
 
         return true;

Modified: incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/policy/DefaultPolicyContextTest.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/policy/DefaultPolicyContextTest.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/policy/DefaultPolicyContextTest.java	Sat Jun  5 12:25:35 2004
@@ -30,6 +30,7 @@
 /*
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
+
 public class DefaultPolicyContextTest extends TestCase
 {
     private DefaultPolicyContext m_policyContext;
@@ -69,7 +70,7 @@
     {
         PermissionCollection permissions = new PermissionCollection();
         permissions.add( new CheckedPermission() );
-        m_roles.put(  "member", permissions );
+        m_roles.put( "member", permissions );
         m_policyContext = new DefaultPolicyContext( m_roles, m_excludedPermissions, m_uncheckedPermissions );
 
         assertTrue( "Permission is checked but requires no priviledge", m_policyContext.requiresPriviledges( new CheckedPermission() ) );
@@ -102,7 +103,7 @@
     {
         PermissionCollection permissions = new PermissionCollection();
         permissions.add( new CheckedPermission() );
-        m_roles.put(  "member", permissions );
+        m_roles.put( "member", permissions );
         m_policyContext = new DefaultPolicyContext( m_roles, m_excludedPermissions, m_uncheckedPermissions );
 
         assertTrue( "Role has permission yet it denied it", m_policyContext.checkPermission( "member", new CheckedPermission() ) );
@@ -113,7 +114,7 @@
         m_excludedPermissions.add( new CheckedPermission() );
         PermissionCollection permissions = new PermissionCollection();
         permissions.add( new CheckedPermission() );
-        m_roles.put(  "member", permissions );
+        m_roles.put( "member", permissions );
         m_policyContext = new DefaultPolicyContext( m_roles, m_excludedPermissions, m_uncheckedPermissions );
 
         assertFalse( "Excluded statement did not overrule role statement", m_policyContext.checkPermission( "member", new CheckedPermission() ) );
@@ -133,7 +134,7 @@
     {
         PermissionCollection permissions = new PermissionCollection();
         permissions.add( new FullPermission() );
-        m_roles.put(  "member", permissions );
+        m_roles.put( "member", permissions );
         m_policyContext = new DefaultPolicyContext( m_roles, m_excludedPermissions, m_uncheckedPermissions );
 
         assertTrue( "Permission is implied by role permission yet it was denied", m_policyContext.checkPermission( "member", new ReadPermission() ) );
@@ -176,14 +177,14 @@
     {
         m_policyContext = new DefaultPolicyContext();
         m_policyContext.addToExcludedPolicy( new ExcludedPermission() );
-        assertFalse( "Permission was granted; should have been excluded", m_policyContext.checkPermission( "guest", new ExcludedPermission() ));
+        assertFalse( "Permission was granted; should have been excluded", m_policyContext.checkPermission( "guest", new ExcludedPermission() ) );
     }
 
     public void testAdditionOfUncheckedPolicyStatement()
     {
         m_policyContext = new DefaultPolicyContext();
         m_policyContext.addToUncheckedPolicy( new UncheckedPermission() );
-        assertFalse( "Permission should no longer require priviledge", m_policyContext.requiresPriviledges( new UncheckedPermission() ));
+        assertFalse( "Permission should no longer require priviledge", m_policyContext.requiresPriviledges( new UncheckedPermission() ) );
     }
 
     public void testAdditionOfPolicyStatement()
@@ -191,7 +192,7 @@
         m_policyContext = new DefaultPolicyContext();
         m_policyContext.addToRole( "member", new AccessPermission( "/sbin" ) );
         m_policyContext.addToRole( "member", new AccessPermission( "/root" ) );
-        assertTrue( m_policyContext.checkPermission( "member", new AccessPermission( "/root" ) ));
-        assertTrue( m_policyContext.checkPermission( "member", new AccessPermission( "/sbin" ) ));
+        assertTrue( m_policyContext.checkPermission( "member", new AccessPermission( "/root" ) ) );
+        assertTrue( m_policyContext.checkPermission( "member", new AccessPermission( "/sbin" ) ) );
     }
 }

Modified: incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/role/DefaultRoleManagerTest.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/role/DefaultRoleManagerTest.java	(original)
+++ incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/role/DefaultRoleManagerTest.java	Sat Jun  5 12:25:35 2004
@@ -19,9 +19,7 @@
 import junit.framework.TestCase;
 import org.apache.janus.authentication.realm.UsernamePrincipal;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
+import java.util.Arrays;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
@@ -35,59 +33,47 @@
         junit.textui.TestRunner.run( DefaultRoleManagerTest.class );
     }
 
-    public void testPrincipalWithNoRoleIsNeverInRole()
+    public void testPrincipalStartsWithNoRole()
     {
         m_roleManager = new DefaultRoleManager();
-        assertFalse( m_roleManager.isPrincipalGranted( john(), new Right() ) );
+        assertEquals( 0, m_roleManager.getRoles( john() ).length );
     }
 
-    public void testSingleRole()
+    public void testRoleGrant()
     {
-        RoleMembership m = new RoleMembership( "member", john() );
-        m_roleManager = new DefaultRoleManager( Collections.singleton( m ) );
-
-        assertTrue( "Principal did not get right",
-                m_roleManager.isPrincipalGranted( john(), new Right() ) );
-        assertFalse( "Principal did not get interdiction",
-                m_roleManager.isPrincipalGranted( john(), new Interdiction() ) );
-    }
-
-    public void testMultipleRole()
-    {
-        Collection roles = new ArrayList();
-        roles.add( new RoleMembership( "guest", john()  ) );
-        roles.add( new RoleMembership( "member", john()  ) );
-        m_roleManager = new DefaultRoleManager( roles );
-
-        assertTrue( "Role was not matched",
-                m_roleManager.isPrincipalGranted( john(), new RoleGrant( "member" ) ) );
+        m_roleManager = new DefaultRoleManager();
+        m_roleManager.grant( john(), "member" );
+        assertTrue( m_roleManager.isInRole( john(), "member" ) );
     }
 
-    private UsernamePrincipal john()
+    public void testRoleCanHaveMultiplePrincipals()
     {
-        return new UsernamePrincipal( "johnDoe" );
+        m_roleManager = new DefaultRoleManager();
+        m_roleManager.grant( john(), "member" );
+        m_roleManager.grant( jane(), "member" );
+        assertTrue( Arrays.asList( m_roleManager.getRoles( john() ) ).contains( "member" ) );
+        assertTrue( Arrays.asList( m_roleManager.getRoles( jane() ) ).contains( "member" ) );
     }
 
-    public void testGrantingMembershipMakesPrincipalInRole()
+    public void testPrincipalsCanHaveMultipleRoles()
     {
         m_roleManager = new DefaultRoleManager();
-        m_roleManager.grantMembership( "member", john() );
-        assertTrue( m_roleManager.isPrincipalGranted( john(), new RoleGrant( "member" ) ) );
+        m_roleManager.grant( john(), "member" );
+        m_roleManager.grant( john(), "vip" );
+        assertTrue( Arrays.asList( m_roleManager.getRoles( john() ) ).contains( "member" ) );
+        assertTrue( Arrays.asList( m_roleManager.getRoles( john() ) ).contains( "vip" ) );
     }
 
-    public void testExistingMembershipsArePreserved()
+    private UsernamePrincipal john()
     {
-        m_roleManager = new DefaultRoleManager();
-        m_roleManager.grantMembership( "member", john() );
-        m_roleManager.grantMembership( "member", jane() );
-        assertTrue( m_roleManager.isPrincipalGranted( john(), new RoleGrant( "member" ) ) );
+        return new UsernamePrincipal( "johnDoe" );
     }
 
     public void testGrantingMembershipTwiceIsIgnored()
     {
         m_roleManager = new DefaultRoleManager();
-        assertTrue( m_roleManager.grantMembership( "member", john() ) );
-        assertFalse( m_roleManager.grantMembership( "member", john() ) );
+        assertTrue( m_roleManager.grant( john(), "member" ) );
+        assertFalse( m_roleManager.grant( john(), "member" ) );
     }
 
     private UsernamePrincipal jane()

Modified: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/PolicyContextBuilder.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/PolicyContextBuilder.java	(original)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/PolicyContextBuilder.java	Sat Jun  5 12:25:35 2004
@@ -23,5 +23,5 @@
  */
 public interface PolicyContextBuilder
 {
-    void buildPolicyContext(MutablePolicyContext context);
+    void buildPolicyContext( MutablePolicyContext context );
 }

Modified: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/RoleManagerBuilder.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/RoleManagerBuilder.java	(original)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/RoleManagerBuilder.java	Sat Jun  5 12:25:35 2004
@@ -16,7 +16,7 @@
  */
 package org.apache.janus.script;
 
-import org.apache.janus.authorization.role.MutableRoleManager;
+import org.apache.janus.authorization.role.RoleManager;
 
 import java.io.IOException;
 
@@ -25,5 +25,5 @@
  */
 public interface RoleManagerBuilder
 {
-    void buildRoleManager( MutableRoleManager roleManager ) throws IOException;
+    void buildRoleManager( RoleManager roleManager ) throws IOException;
 }

Modified: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JPolicyContextBuilder.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JPolicyContextBuilder.java	(original)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JPolicyContextBuilder.java	Sat Jun  5 12:25:35 2004
@@ -48,15 +48,15 @@
         return doc;
     }
 
-    public void buildPolicyContext(MutablePolicyContext context)
+    public void buildPolicyContext( MutablePolicyContext context )
     {
         Element root = m_doc.getRootElement();
         Element denials = root.element( "denials" );
         addDenials( context, denials );
         Element grants = root.element( "grants" );
-        addGrants( context, grants);
+        addGrants( context, grants );
         Element roles = root.element( "roles" );
-        addRoles( context, roles);
+        addRoles( context, roles );
     }
 
     private void addRoles( MutablePolicyContext policy, Element roles )
@@ -65,7 +65,7 @@
 
         for ( Iterator it = rolesList.iterator(); it.hasNext(); )
         {
-            final Element element = (Element) it.next();
+            final Element element = ( Element ) it.next();
             addRole( policy, element );
         }
     }
@@ -76,8 +76,8 @@
         Collection permissions = element.elements( "access" );
         for ( Iterator iterator = permissions.iterator(); iterator.hasNext(); )
         {
-            final Element e = (Element) iterator.next();
-            policy.addToRole( roleName, getPermission( e ));
+            final Element e = ( Element ) iterator.next();
+            policy.addToRole( roleName, getPermission( e ) );
         }
     }
 
@@ -87,7 +87,7 @@
 
         for ( Iterator it = grantsList.iterator(); it.hasNext(); )
         {
-            final Element element = (Element) it.next();
+            final Element element = ( Element ) it.next();
             policy.addToUncheckedPolicy( getPermission( element ) );
         }
     }
@@ -105,7 +105,7 @@
 
         for ( Iterator it = denialsList.iterator(); it.hasNext(); )
         {
-            final Element element = (Element) it.next();
+            final Element element = ( Element ) it.next();
             policy.addToExcludedPolicy( getPermission( element ) );
         }
     }

Modified: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java	(original)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRealmBuilder.java	Sat Jun  5 12:25:35 2004
@@ -69,7 +69,7 @@
 
         for ( Iterator it = userList.iterator(); it.hasNext(); )
         {
-            final Element user = (Element) it.next();
+            final Element user = ( Element ) it.next();
             CredentialSet creds = new CredentialSet();
             String username = user.attributeValue( "username" );
             creds.add( new Credential( "username", username ) );

Modified: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRoleManagerBuilder.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRoleManagerBuilder.java	(original)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/Dom4JRoleManagerBuilder.java	Sat Jun  5 12:25:35 2004
@@ -17,7 +17,7 @@
 package org.apache.janus.script.xml;
 
 import org.apache.janus.authentication.realm.UsernamePrincipal;
-import org.apache.janus.authorization.role.MutableRoleManager;
+import org.apache.janus.authorization.role.RoleManager;
 import org.apache.janus.script.RoleManagerBuilder;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
@@ -44,7 +44,7 @@
         m_doc = readDocument( reader );
     }
 
-    public void buildRoleManager( MutableRoleManager roleManager ) throws IOException
+    public void buildRoleManager( RoleManager roleManager ) throws IOException
     {
         Element root = m_doc.getRootElement();
         addMemberships( roleManager, root );
@@ -58,28 +58,28 @@
         return doc;
     }
 
-    private void addMemberships( MutableRoleManager roleManager, Element roles )
+    private void addMemberships( RoleManager roleManager, Element roles )
     {
         List roleList = roles.elements( "role" );
 
         for ( Iterator it = roleList.iterator(); it.hasNext(); )
         {
-            final Element element = (Element) it.next();
+            final Element element = ( Element ) it.next();
             addMembers( roleManager, element );
         }
     }
 
-    private void addMembers( MutableRoleManager roleManager, final Element element )
+    private void addMembers( RoleManager roleManager, final Element element )
     {
         String roleName = element.attributeValue( "name" );
         List userList = element.elements( "user" );
 
         for ( Iterator itr = userList.iterator(); itr.hasNext(); )
         {
-            final Element e = (Element) itr.next();
+            final Element e = ( Element ) itr.next();
             String username = e.attributeValue( "username" );
             Principal user = new UsernamePrincipal( username );
-            roleManager.grantMembership( roleName, user );
+            roleManager.grant( user, roleName );
         }
     }
 }

Modified: incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JPolicyContextBuilderTest.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JPolicyContextBuilderTest.java	(original)
+++ incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JPolicyContextBuilderTest.java	Sat Jun  5 12:25:35 2004
@@ -16,18 +16,17 @@
  */
 package org.apache.janus.script.xml;
 
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-import junit.framework.TestCase;
 import org.apache.janus.authorization.AccessPermission;
 import org.apache.janus.authorization.policy.MutablePolicyContext;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
 
 import java.io.StringReader;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
-public class Dom4JPolicyContextBuilderTest extends TestCase
+public class Dom4JPolicyContextBuilderTest extends MockObjectTestCase
 {
     private Mock m_mockPolicyContext;
 
@@ -43,14 +42,12 @@
 
     public void testExcludedStatements() throws Exception
     {
-        Dom4JPolicyContextBuilder builder = new Dom4JPolicyContextBuilder( new StringReader(denialsDefinition()) );
+        Dom4JPolicyContextBuilder builder = new Dom4JPolicyContextBuilder( new StringReader( denialsDefinition() ) );
 
-        m_mockPolicyContext.expectAndReturn( "addToExcludedPolicy",
-                C.args( C.eq( new AccessPermission( "/dev") ) ), true );
-        m_mockPolicyContext.expectAndReturn( "addToExcludedPolicy",
-                C.args( C.eq( new AccessPermission( "/proc") ) ), true );
+        m_mockPolicyContext.expects( once() ).method( "addToExcludedPolicy" ).with( eq( new AccessPermission( "/dev" ) ) ).will( returnValue( true ) );
+        m_mockPolicyContext.expects( once() ).method( "addToExcludedPolicy" ).with( eq( new AccessPermission( "/proc" ) ) ).will( returnValue( true ) );
 
-        builder.buildPolicyContext( (MutablePolicyContext) m_mockPolicyContext.proxy() );
+        builder.buildPolicyContext( ( MutablePolicyContext ) m_mockPolicyContext.proxy() );
 
         m_mockPolicyContext.verify();
     }
@@ -58,28 +55,26 @@
     private String denialsDefinition()
     {
         String content = "<?xml version=\"1.0\"?>\n"
-                         + "<policy>\n"
-                         + "    <denials>\n"
-                         + "        <access resource=\"/dev\"/>\n"
-                         + "        <access resource=\"/proc\"/>\n"
-                         + "    </denials>\n"
-                         + "    <roles/>\n"
-                         + "    <grants/>\n"
-                         + "</policy>";
+                + "<policy>\n"
+                + "    <denials>\n"
+                + "        <access resource=\"/dev\"/>\n"
+                + "        <access resource=\"/proc\"/>\n"
+                + "    </denials>\n"
+                + "    <roles/>\n"
+                + "    <grants/>\n"
+                + "</policy>";
 
         return content;
     }
 
     public void testUncheckedStatements() throws Exception
     {
-        Dom4JPolicyContextBuilder builder = new Dom4JPolicyContextBuilder( new StringReader(grantsDefinition()) );
+        Dom4JPolicyContextBuilder builder = new Dom4JPolicyContextBuilder( new StringReader( grantsDefinition() ) );
 
-        m_mockPolicyContext.expectAndReturn( "addToUncheckedPolicy",
-                C.args( C.eq( new AccessPermission( "/tmp") ) ), true );
-        m_mockPolicyContext.expectAndReturn( "addToUncheckedPolicy",
-                C.args( C.eq( new AccessPermission( "/public") ) ), true );
+        m_mockPolicyContext.expects( once() ).method( "addToUncheckedPolicy" ).with( eq( new AccessPermission( "/tmp" ) ) ).will( returnValue( true ) );
+        m_mockPolicyContext.expects( once() ).method( "addToUncheckedPolicy" ).with( eq( new AccessPermission( "/public" ) ) ).will( returnValue( true ) );
 
-        builder.buildPolicyContext( (MutablePolicyContext) m_mockPolicyContext.proxy() );
+        builder.buildPolicyContext( ( MutablePolicyContext ) m_mockPolicyContext.proxy() );
 
         m_mockPolicyContext.verify();
     }
@@ -87,30 +82,27 @@
     private String grantsDefinition()
     {
         String content = "<?xml version=\"1.0\"?>\n"
-                         + "<policy>\n"
-                         + "    <denials/>\n"
-                         + "    <roles/>\n"
-                         + "    <grants>\n"
-                         + "        <access resource=\"/tmp\"/>\n"
-                         + "        <access resource=\"/public\"/>\n"
-                         + "    </grants>\n"
-                         + "</policy>";
+                + "<policy>\n"
+                + "    <denials/>\n"
+                + "    <roles/>\n"
+                + "    <grants>\n"
+                + "        <access resource=\"/tmp\"/>\n"
+                + "        <access resource=\"/public\"/>\n"
+                + "    </grants>\n"
+                + "</policy>";
 
         return content;
     }
 
     public void testCheckedStatements() throws Exception
     {
-        Dom4JPolicyContextBuilder builder = new Dom4JPolicyContextBuilder( new StringReader(rolesDefinition()) );
+        Dom4JPolicyContextBuilder builder = new Dom4JPolicyContextBuilder( new StringReader( rolesDefinition() ) );
 
-        m_mockPolicyContext.expectAndReturn( "addToRole",
-                C.args( C.eq( "member" ), C.eq( new AccessPermission( "/home") ) ), true );
-        m_mockPolicyContext.expectAndReturn( "addToRole",
-                C.args( C.eq( "member" ), C.eq( new AccessPermission( "/usr") ) ), true );
-        m_mockPolicyContext.expectAndReturn( "addToRole",
-                C.args( C.eq( "guest" ), C.eq( new AccessPermission( "/share") ) ), true );
+        m_mockPolicyContext.expects( once() ).method( "addToRole" ).with( eq( "member" ), eq( new AccessPermission( "/home" ) ) ).will( returnValue( true ) );
+        m_mockPolicyContext.expects( once() ).method( "addToRole" ).with( eq( "member" ), eq( new AccessPermission( "/usr" ) ) ).will( returnValue( true ) );
+        m_mockPolicyContext.expects( once() ).method( "addToRole" ).with( eq( "guest" ), eq( new AccessPermission( "/share" ) ) ).will( returnValue( true ) );
 
-        builder.buildPolicyContext( (MutablePolicyContext) m_mockPolicyContext.proxy() );
+        builder.buildPolicyContext( ( MutablePolicyContext ) m_mockPolicyContext.proxy() );
 
         m_mockPolicyContext.verify();
     }
@@ -118,19 +110,19 @@
     private String rolesDefinition()
     {
         String content = "<?xml version=\"1.0\"?>\n"
-                         + "<policy>\n"
-                         + "    <denials/>\n"
-                         + "    <roles>\n"
-                         + "        <role name=\"member\">\n"
-                         + "            <access resource=\"/home\"/>\n"
-                         + "            <access resource=\"/usr\"/>\n"
-                         + "        </role>\n"
-                         + "        <role name=\"guest\">\n"
-                         + "            <access resource=\"/share\"/>\n"
-                         + "        </role>\n"
-                         + "    </roles>\n"
-                         + "    <grants/>\n"
-                         + "</policy>";
+                + "<policy>\n"
+                + "    <denials/>\n"
+                + "    <roles>\n"
+                + "        <role name=\"member\">\n"
+                + "            <access resource=\"/home\"/>\n"
+                + "            <access resource=\"/usr\"/>\n"
+                + "        </role>\n"
+                + "        <role name=\"guest\">\n"
+                + "            <access resource=\"/share\"/>\n"
+                + "        </role>\n"
+                + "    </roles>\n"
+                + "    <grants/>\n"
+                + "</policy>";
 
         return content;
     }

Modified: incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java	(original)
+++ incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRealmBuilderTest.java	Sat Jun  5 12:25:35 2004
@@ -16,21 +16,21 @@
  */
 package org.apache.janus.script.xml;
 
-import com.mockobjects.dynamic.Mock;
-import junit.framework.TestCase;
 import org.apache.janus.authentication.Credential;
 import org.apache.janus.authentication.CredentialSet;
 import org.apache.janus.authentication.realm.DefaultRealm;
 import org.apache.janus.authentication.realm.MutableRealm;
 import org.apache.janus.authentication.realm.UsernamePasswordAuthentication;
 import org.apache.janus.script.RealmBuilderMonitor;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
 
 import java.io.StringReader;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
-public class Dom4JRealmBuilderTest extends TestCase
+public class Dom4JRealmBuilderTest extends MockObjectTestCase
 {
     public static void main( String[] args )
     {
@@ -42,10 +42,10 @@
         Dom4JRealmBuilder builder = new Dom4JRealmBuilder( new StringReader( simpleRealm() ) );
 
         Mock mockRealm = new Mock( MutableRealm.class );
-        mockRealm.expectAndReturn( "addIdentity", johnCredentials(), true );
-        mockRealm.expectAndReturn( "addIdentity", janeCredentials(), true );
+        mockRealm.expects( once() ).method( "addIdentity" ).with( eq( johnCredentials() ) ).will( returnValue( true ) );
+        mockRealm.expects( once() ).method( "addIdentity" ).with( eq( janeCredentials() ) ).will( returnValue( true ) );
 
-        builder.buildRealm( (MutableRealm) mockRealm.proxy() );
+        builder.buildRealm( ( MutableRealm ) mockRealm.proxy() );
 
         mockRealm.verify();
     }
@@ -53,12 +53,12 @@
     private String simpleRealm()
     {
         String content = "<?xml version=\"1.0\"?>\n"
-                         + "<realm>\n"
-                         + "    <users>\n"
-                         + "        <user username=\"john\" password=\"doe\"/>\n"
-                         + "        <user username=\"jane\" password=\"doe\"/>\n"
-                         + "    </users>\n"
-                         + "</realm>";
+                + "<realm>\n"
+                + "    <users>\n"
+                + "        <user username=\"john\" password=\"doe\"/>\n"
+                + "        <user username=\"jane\" password=\"doe\"/>\n"
+                + "    </users>\n"
+                + "</realm>";
         return content;
     }
 
@@ -81,11 +81,10 @@
     public void testNotifiesOfDuplicateIdentities() throws Exception
     {
         Mock mockMonitor = new Mock( RealmBuilderMonitor.class );
-        Dom4JRealmBuilder builder = new Dom4JRealmBuilder(
-                new StringReader( realmWithDuplicateIdentity() ),
-                (RealmBuilderMonitor) mockMonitor.proxy() );
+        Dom4JRealmBuilder builder = new Dom4JRealmBuilder( new StringReader( realmWithDuplicateIdentity() ),
+                ( RealmBuilderMonitor ) mockMonitor.proxy() );
 
-        mockMonitor.expect( "duplicateIdentity", johnCredentials() );
+        mockMonitor.expects( once() ).method( "duplicateIdentity" ).with( eq( johnCredentials() ) );
         builder.buildRealm( new DefaultRealm( new UsernamePasswordAuthentication() ) );
 
         mockMonitor.verify();
@@ -94,12 +93,12 @@
     private String realmWithDuplicateIdentity()
     {
         String content = "<?xml version=\"1.0\"?>\n"
-                         + "<realm>\n"
-                         + "    <users>\n"
-                         + "        <user username=\"john\" password=\"doe\"/>\n"
-                         + "        <user username=\"john\" password=\"doe\"/>\n"
-                         + "    </users>\n"
-                         + "</realm>";
+                + "<realm>\n"
+                + "    <users>\n"
+                + "        <user username=\"john\" password=\"doe\"/>\n"
+                + "        <user username=\"john\" password=\"doe\"/>\n"
+                + "    </users>\n"
+                + "</realm>";
         return content;
     }
 }

Modified: incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRoleManagerBuilderTest.java
==============================================================================
--- incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRoleManagerBuilderTest.java	(original)
+++ incubator/directory/janus/trunk/script/src/test/org/apache/janus/script/xml/Dom4JRoleManagerBuilderTest.java	Sat Jun  5 12:25:35 2004
@@ -16,18 +16,17 @@
  */
 package org.apache.janus.script.xml;
 
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-import junit.framework.TestCase;
 import org.apache.janus.authentication.realm.UsernamePrincipal;
-import org.apache.janus.authorization.role.MutableRoleManager;
+import org.apache.janus.authorization.role.RoleManager;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
 
 import java.io.StringReader;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
-public class Dom4JRoleManagerBuilderTest extends TestCase
+public class Dom4JRoleManagerBuilderTest extends MockObjectTestCase
 {
     private Mock m_mockRoleManager;
 
@@ -38,20 +37,17 @@
 
     protected void setUp() throws Exception
     {
-        m_mockRoleManager = new Mock( MutableRoleManager.class );
+        m_mockRoleManager = new Mock( RoleManager.class );
     }
 
     public void testSimpleRolesBuild() throws Exception
     {
-        Dom4JRoleManagerBuilder builder = new Dom4JRoleManagerBuilder(
-                new StringReader( simpleRolesDefinition() ) );
+        Dom4JRoleManagerBuilder builder = new Dom4JRoleManagerBuilder( new StringReader( simpleRolesDefinition() ) );
 
-        m_mockRoleManager.expectAndReturn( "grantMembership",
-                C.args( C.eq( "member" ), C.eq( john() ) ), true );
-        m_mockRoleManager.expectAndReturn( "grantMembership",
-                C.args( C.eq( "member" ), C.eq( jane() ) ), true );
+        m_mockRoleManager.expects( once() ).method( "grant" ).with( eq( john() ), eq( "member" ) ).will( returnValue( true ) );
+        m_mockRoleManager.expects( once() ).method( "grant" ).with( eq( jane() ), eq( "member" ) ).will( returnValue( true ) );
 
-        builder.buildRoleManager( (MutableRoleManager) m_mockRoleManager.proxy() );
+        builder.buildRoleManager( ( RoleManager ) m_mockRoleManager.proxy() );
 
         m_mockRoleManager.verify();
     }
@@ -59,13 +55,13 @@
     private String simpleRolesDefinition()
     {
         String content = "<?xml version=\"1.0\"?>\n"
-                         + "<roles>\n"
-                         + "    <role name=\"member\">\n"
-                         + "        <user username=\"john\"/>"
-                         + "        <user username=\"jane\"/>"
-                         + "    </role>\n"
-                         + "    <role name=\"vip\"/>\n"
-                         + "</roles>";
+                + "<roles>\n"
+                + "    <role name=\"member\">\n"
+                + "        <user username=\"john\"/>"
+                + "        <user username=\"jane\"/>"
+                + "    </role>\n"
+                + "    <role name=\"vip\"/>\n"
+                + "</roles>";
         return content;
     }