directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 20769 - in incubator/directory/janus/trunk: . core/impl/src/test/org/apache/janus/authentication core/impl/src/test/org/apache/janus/authentication/realm core/impl/src/test/org/apache/janus/authorization src xdocs
Date Thu, 03 Jun 2004 04:02:53 GMT
Author: vtence
Date: Wed Jun  2 21:02:51 2004
New Revision: 20769

Removed:
   incubator/directory/janus/trunk/src/
Modified:
   incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authentication/DefaultAuthenticatorTest.java
   incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authentication/realm/DefaultRealmTest.java
   incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authorization/DefaultAuthorizerTest.java
   incubator/directory/janus/trunk/maven.xml
   incubator/directory/janus/trunk/project.xml
   incubator/directory/janus/trunk/xdocs/index.xml
Log:
o Switched core test code to using JMock

Modified: incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authentication/DefaultAuthenticatorTest.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authentication/DefaultAuthenticatorTest.java
(original)
+++ incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authentication/DefaultAuthenticatorTest.java
Wed Jun  2 21:02:51 2004
@@ -16,17 +16,16 @@
  */
 package org.apache.janus.authentication;
 
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-import junit.framework.TestCase;
 import org.apache.janus.authentication.realm.Realm;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
 
 import javax.security.auth.Subject;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
-public class DefaultAuthenticatorTest extends TestCase
+public class DefaultAuthenticatorTest extends MockObjectTestCase
 {
     private DefaultAuthenticator m_authenticator;
     private Mock m_mockRealm;
@@ -41,7 +40,7 @@
         m_mockRealm
                 = new Mock( Realm.class );
         m_authenticator
-                = new DefaultAuthenticator( (Realm) m_mockRealm.proxy() );
+                = new DefaultAuthenticator( ( Realm ) m_mockRealm.proxy() );
     }
 
     private CredentialSet banana()
@@ -53,8 +52,7 @@
 
     public void testAuthentication()
     {
-        m_mockRealm.matchAndReturn( "validateCredentials", C.eq( banana() ),
-                new FruitPrincipal( "banana" ) );
+        m_mockRealm.expects( once() ).method( "validateCredentials" ).with( eq( banana()
) ).will( returnValue( new FruitPrincipal( "banana" ) ) );
 
         Subject subject = null;
         try
@@ -71,7 +69,7 @@
 
     public void testAuthenticationFailure()
     {
-        m_mockRealm.matchAndReturn( "validateCredentials", C.ANY_ARGS, null );
+        m_mockRealm.stubs().method( "validateCredentials" ).will( returnValue( null ) );
 
         try
         {

Modified: incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authentication/realm/DefaultRealmTest.java
==============================================================================
--- incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authentication/realm/DefaultRealmTest.java
(original)
+++ incubator/directory/janus/trunk/core/impl/src/test/org/apache/janus/authentication/realm/DefaultRealmTest.java
Wed Jun  2 21:02:51 2004
@@ -16,11 +16,10 @@
  */
 package org.apache.janus.authentication.realm;
 
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-import junit.framework.TestCase;
 import org.apache.janus.authentication.Credential;
 import org.apache.janus.authentication.CredentialSet;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
 
 import java.security.Principal;
 import java.util.HashSet;
@@ -29,7 +28,7 @@
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
-public class DefaultRealmTest extends TestCase
+public class DefaultRealmTest extends MockObjectTestCase
 {
     public static void main( String[] args )
     {
@@ -41,16 +40,16 @@
     public void testValidationFailsIfCredentialSetNotSupported()
     {
         Mock mockAuthenticationMethod = new Mock( AuthenticationMethod.class );
-        realm = new DefaultRealm( (AuthenticationMethod) mockAuthenticationMethod.proxy()
);
-        mockAuthenticationMethod.matchAndReturn( "supports", joeCredentials(), false );
+        realm = new DefaultRealm( ( AuthenticationMethod ) mockAuthenticationMethod.proxy()
);
+        mockAuthenticationMethod.expects( atLeastOnce() ).method( "supports" ).with( eq(
joeCredentials() ) ).will( returnValue( false ) );
         assertNull( "Empty credential set was validated", realm.validateCredentials( joeCredentials()
) );
     }
 
-    public void testEmptyRealmNeverValidates()
+    public void testEmptyRealmNeverValidatesAnyCredentialSet()
     {
         Mock mockAuthenticationMethod = createMockAuthenticationMethod();
-        mockAuthenticationMethod.matchAndReturn( "matcher", C.ANY_ARGS, new AlwaysMatch()
);
-        realm = new DefaultRealm( (AuthenticationMethod) mockAuthenticationMethod.proxy()
);
+        mockAuthenticationMethod.stubs().method( "matcher" ).will( returnValue( new AlwaysMatch()
) );
+        realm = new DefaultRealm( ( AuthenticationMethod ) mockAuthenticationMethod.proxy()
);
 
         assertNull( "Principal was returned but realm contains no entry",
                 realm.validateCredentials( johnCredentials() ) );
@@ -60,9 +59,9 @@
     public void testValidationFailsIfCredentialsAreNotMatched()
     {
         Mock mockAuthenticationMethod = createMockAuthenticationMethod();
-        mockAuthenticationMethod.matchAndReturn( "matcher", C.ANY_ARGS, new NeverMatch()
);
+        mockAuthenticationMethod.stubs().method( "matcher" ).will( returnValue( new NeverMatch()
) );
 
-        realm = new DefaultRealm( (AuthenticationMethod) mockAuthenticationMethod.proxy()
);
+        realm = new DefaultRealm( ( AuthenticationMethod ) mockAuthenticationMethod.proxy()
);
 
         assertNull( "Principal was returned but credentials are invalid",
                 realm.validateCredentials( johnCredentials() ) );
@@ -72,10 +71,10 @@
     public void testValidationSucceedsIfOneEntryIsMatched()
     {
         Mock mockAuthenticationMethod = createMockAuthenticationMethod();
-        mockAuthenticationMethod.matchAndReturn( "matcher", C.ANY_ARGS, new EqualCredentials(
janeCredentials() ) );
-        mockAuthenticationMethod.matchAndReturn( "getPrincipal", janeCredentials(), jane()
);
+        mockAuthenticationMethod.stubs().method( "matcher" ).will( returnValue( new EqualCredentials(
janeCredentials() ) ) );
+        mockAuthenticationMethod.stubs().method( "getPrincipal" ).with( eq( janeCredentials()
) ).will( returnValue( jane() ) );
 
-        realm = new DefaultRealm( (AuthenticationMethod) mockAuthenticationMethod.proxy()
);
+        realm = new DefaultRealm( ( AuthenticationMethod ) mockAuthenticationMethod.proxy()
);
 
         try
         {
@@ -96,9 +95,9 @@
     public void testRejectsNewEntryIfCredentialSetIsNotSupported()
     {
         Mock mockAuthenticationMethod = new Mock( AuthenticationMethod.class );
-        realm = new DefaultRealm( (AuthenticationMethod) mockAuthenticationMethod.proxy()
);
+        realm = new DefaultRealm( ( AuthenticationMethod ) mockAuthenticationMethod.proxy()
);
 
-        mockAuthenticationMethod.matchAndReturn( "supports", joeCredentials(), false );
+        mockAuthenticationMethod.stubs().method( "supports" ).with( eq( joeCredentials()
) ).will( returnValue( false ) );
 
         try
         {
@@ -114,8 +113,8 @@
     public void testIdentityIsNotAddedIfAlreadyInRealm()
     {
         Mock mockAuthenticationMethod = createMockAuthenticationMethod();
-        realm = new DefaultRealm( (AuthenticationMethod) mockAuthenticationMethod.proxy()
);
-        mockAuthenticationMethod.matchAndReturn( "matcher", C.ANY_ARGS, new EqualCredentials(
joeCredentials() ) );
+        realm = new DefaultRealm( ( AuthenticationMethod ) mockAuthenticationMethod.proxy()
);
+        mockAuthenticationMethod.stubs().method( "matcher" ).will( returnValue( new EqualCredentials(
joeCredentials() ) ) );
 
         realm.addIdentity( joeCredentials() );
         assertFalse( "Identity reported as added twice", realm.addIdentity( joeCredentials()
) );
@@ -153,7 +152,7 @@
     public Mock createMockAuthenticationMethod()
     {
         Mock mockAuthenticationMethod = new Mock( AuthenticationMethod.class );
-        mockAuthenticationMethod.matchAndReturn( "supports", C.ANY_ARGS, true );
+        mockAuthenticationMethod.stubs().method( "supports" ).will( returnValue( true ) );
         return mockAuthenticationMethod;
     }
 }

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
Wed Jun  2 21:02:51 2004
@@ -16,19 +16,18 @@
  */
 package org.apache.janus.authorization;
 
-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.policy.PolicyContext;
 import org.apache.janus.authorization.role.RoleManager;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
 
 import javax.security.auth.Subject;
 
 /**
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  */
-public class DefaultAuthorizerTest extends TestCase
+public class DefaultAuthorizerTest extends MockObjectTestCase
 {
     private DefaultAuthorizer m_authorizer;
     private Mock m_mockPolicyContext;
@@ -43,15 +42,14 @@
     {
         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_authorizer = new DefaultAuthorizer( ( PolicyContext ) m_mockPolicyContext.proxy(),
+                ( org.apache.janus.authorization.role.RoleManager ) m_mockRoleManager.proxy()
);
 
     }
 
     public void testUncheckedPermissionsAreGrantedToAnyone()
     {
-        m_mockPolicyContext.matchAndReturn( "requiresPriviledges",
-                new UncheckedPermission(), false );
+        m_mockPolicyContext.stubs().method( "requiresPriviledges" ).with( eq( new UncheckedPermission()
) ).will( returnValue( false ) );
         assertTrue( "Unchecked permission was not granted",
                 m_authorizer.checkAuthorization( user( "johnDoe" ),
                         new UncheckedPermission() ) );
@@ -59,8 +57,7 @@
 
     public void testSubjectWithoutPrincipalIsNotAuthorized()
     {
-        m_mockPolicyContext.matchAndReturn( "requiresPriviledges",
-                new CheckedPermission(), true );
+        m_mockPolicyContext.stubs().method( "requiresPriviledges" ).with( eq( new CheckedPermission()
) ).will( returnValue( true ) );
 
         assertFalse( "Authorization given to subject with no role",
                 m_authorizer.checkAuthorization( new Subject(),
@@ -69,33 +66,24 @@
 
     public void testSubjectWithASinglePrincipalIsAuthorizedIfPrincipalIsInRole()
     {
-        m_mockPolicyContext.matchAndReturn( "requiresPriviledges",
-                new CheckedPermission(), true );
-        m_mockRoleManager.matchAndReturn( "isPrincipalGranted",
-                C.args( C.eq( new UsernamePrincipal( "johnDoe" ) ), C.isA( PermissionGrant.class
) ),
-                true );
-        m_mockRoleManager.matchAndReturn( "isPrincipalGranted",
-                C.args( C.eq( new UsernamePrincipal( "janeDoe" ) ), C.isA( PermissionGrant.class
) ),
-                false );
-
+        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() ) );
-        assertFalse( "Principal not in role did get authorization",
-                m_authorizer.checkAuthorization( user( "janeDoe" ),
-                        new CheckedPermission() ) );
     }
 
     public void testSubjectWithSeveralPrincipalsIsAuthorizedIfOnePrincipalIsInRole()
     {
-        m_mockPolicyContext.matchAndReturn( "requiresPriviledges",
-                new CheckedPermission(), true );
-        m_mockRoleManager.matchAndReturn( "isPrincipalGranted",
-                C.args( C.eq( new SSNPrincipal( "123-456-789" ) ), C.isA( PermissionGrant.class
) ),
-                false );
-        m_mockRoleManager.matchAndReturn( "isPrincipalGranted",
-                C.args( C.eq( new UsernamePrincipal( "janeDoe" ) ), C.isA( PermissionGrant.class
) ),
-                true );
+        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 ) );
 
         assertTrue( "Subject with principal in role did not get authorization",
                 m_authorizer.checkAuthorization( member( "janeDoe", "123-456-789" ),

Modified: incubator/directory/janus/trunk/maven.xml
==============================================================================
--- incubator/directory/janus/trunk/maven.xml	(original)
+++ incubator/directory/janus/trunk/maven.xml	Wed Jun  2 21:02:51 2004
@@ -1,4 +1,4 @@
-<project default="install-jars"
+<project default="all"
     xmlns:maven="jelly:maven"
     xmlns:deploy="deploy">
 
@@ -12,6 +12,17 @@
           <include name="**"/>
         </fileset>
       </copy>
+    </goal>
+    
+    <goal name="all"
+        description="Builds all the sub-projects.">
+
+        <maven:reactor
+            basedir="${basedir}"
+            includes="core/*/project.xml,script/project.xml"
+            goals=""
+            banner="Building sub-project:"
+            ignoreFailures="false"/>
     </goal>
 
     <goal name="install-jars"

Modified: incubator/directory/janus/trunk/project.xml
==============================================================================
--- incubator/directory/janus/trunk/project.xml	(original)
+++ incubator/directory/janus/trunk/project.xml	Wed Jun  2 21:02:51 2004
@@ -23,9 +23,11 @@
     <distributionDirectory>/home/akarasulu/public_html/dist</distributionDirectory>
 
     <repository>
-        <connection>
+        <connection/>
+        <!--
           scm:svn:http://cvs.apache.org/repos/asf/incubator/directory/janus/trunk
         </connection>
+        -->
 
         <url>
         http://cvs.apache.org/viewcvs.cgi/incubator/directory/janus/trunk?root=Apache-SVN
@@ -144,6 +146,11 @@
             <groupId>mockobjects</groupId>
             <artifactId>mockobjects-core</artifactId>
             <version>0.09</version>
+        </dependency>
+        <dependency>
+            <groupId>jmock</groupId>
+            <artifactId>jmock</artifactId>
+            <version>1.0.0</version>
         </dependency>
     </dependencies>
 

Modified: incubator/directory/janus/trunk/xdocs/index.xml
==============================================================================
--- incubator/directory/janus/trunk/xdocs/index.xml	(original)
+++ incubator/directory/janus/trunk/xdocs/index.xml	Wed Jun  2 21:02:51 2004
@@ -1,17 +1,59 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <document>
-  <properties>
-    <author email="vtence@apache.org">Vincent Tence</author>
-    <title>Apache Directory Project: Janus Security Framework</title>
-  </properties>
-
-  <body>
-    <section name="Overview">
-      <p>Welcome to the Janus Framework Homepage!</p>
-
-      <p>
-        Introduce Janus here ...
-      </p>
-    </section>
-  </body>
+    <properties>
+        <author email="vtence@apache.org">Vincent Tence</author>
+        <title>Apache Directory Project: Janus Security Framework</title>
+    </properties>
+
+    <body>
+        <section name="Overview">
+        <p>
+        Janus is an Authentication, Authorization and Accounting framework for
+        building security infrastructures.
+        </p>
+        <p>
+        The Janus sub-project defines the Janus security framework and provides default implementations:
+            <ul>
+                <li>A XML file based implementation</li>
+                <li>A RDMS implementation (work in progress)</li>
+                <li>A LDAP implementation (to come)</li>
+            </ul>
+        </p>
+        </section>
+        
+        <section name="Authentication">
+        <p>
+        Authentication is about finding out if someone is who he/she claims to
+        be. This is done by presenting some proof of identity, which usually can
+        take the form of username/password, digital signature, etc.
+        </p>
+        </section>
+        
+        <section name="Authorization">
+        <p>
+        Authorization is about, once a user has been identified, determining if
+        hs/she is authorized to do something. A successful authorization results in the user
+        being granted the permission to perform an operation on a resource.
+        </p>
+
+            <subsection name="Role-Based Access Control">
+            </subsection>
+
+            <subsection name="Users and Roles"></subsection>
+
+            <subsection name="Roles and Permissions"></subsection>
+
+            <subsection name="Traditional Access Control Technologies">
+            </subsection>
+
+            <subsection name="Advantages of Role-Based Access Control"></subsection>
+        </section>
+
+        <section name="Accounting">
+        <p>
+        Accounting is the concern of collecting resource access/consumption data for the
purposes of auditing.
+        </p>
+        </section>
+
+    </body>
 </document>

Mime
View raw message