directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: r280223 - in /directory/authx/trunk: core/src/java/org/apache/authx/authentication/ core/src/java/org/apache/authx/authentication/realm/ core/src/test/org/apache/authx/authentication/ core/src/test/org/apache/authx/authentication/realm/ exa...
Date Mon, 12 Sep 2005 00:35:56 GMT
Author: vtence
Date: Sun Sep 11 17:35:27 2005
New Revision: 280223

URL: http://svn.apache.org/viewcvs?rev=280223&view=rev
Log:
Refactored JDBC code towards a more flexible instanciation mechanism. It is now possible to pull any type of object from the database using custom Mapping and Persister implementations. It is also possible to filter objects loaded from the database - for instance, discarding expired password entries. Finally, Realms can through exceptions during authentications, allowing SPI code to be more specific about the reason of a failed authentication.

Added:
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationException.java
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationFailureException.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/AuthenticationFilter.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Mapping.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PassThroughFilter.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionException.java   (with props)
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionPersister.java   (with props)
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/ReflectionPersisterTest.java   (with props)
Modified:
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/Authenticator.java
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/Credential.java
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/DefaultAuthenticator.java
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/PasswordCredential.java
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Realm.java
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Selector.java
    directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernameCredential.java
    directory/authx/trunk/core/src/test/org/apache/authx/authentication/DefaultAuthenticatorTest.java
    directory/authx/trunk/core/src/test/org/apache/authx/authentication/realm/UsernamePasswordAuthenticationTest.java
    directory/authx/trunk/example/src/webapp/WEB-INF/nanocontainer.groovy
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/EqExpression.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCRealm.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLExpressionBuilder.java
    directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java
    directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java

Added: directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationException.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationException.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationException.java (added)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationException.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,25 @@
+package org.apache.authx.authentication;
+
+import org.apache.authx.AuthXException;
+
+public class AuthenticationException extends AuthXException
+{
+    public AuthenticationException()
+    {
+    }
+
+    public AuthenticationException( String message )
+    {
+        super( message );
+    }
+
+    public AuthenticationException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public AuthenticationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

Added: directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationFailureException.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationFailureException.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationFailureException.java (added)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/AuthenticationFailureException.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,21 @@
+package org.apache.authx.authentication;
+
+public class AuthenticationFailureException extends AuthenticationException
+{
+    private final CredentialSet m_creds;
+
+    public AuthenticationFailureException( CredentialSet creds )
+    {
+        m_creds = creds;
+    }
+
+    public CredentialSet getCreds()
+    {
+        return m_creds;
+    }
+
+    public String getMessage()
+    {
+        return "Invalid credentials";
+    }
+}

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/Authenticator.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/Authenticator.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/Authenticator.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/Authenticator.java Sun Sep 11 17:35:27 2005
@@ -25,6 +25,10 @@
  * security-related attributes that may be used to render
  * authorization decisions.
  *
+ * <p>
+ * <i>Note</i>: instead of returning null, consider using an AuthenticationException
+ * to allow distinction between invalid and expired/locked identities.
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public interface Authenticator
@@ -35,8 +39,9 @@
      * for which permissions may be associated.
      *
      * @param credentials A collection of credential objects provided as proof of identity
-     * @return a Subject populated with appropriate principals or null if authentication fails
+     * @return a Subject populated with appropriate principals
+     * @throws AuthenticationException if authentication fails or cannot be performed 
      */
-    Subject authenticate( CredentialSet credentials );
+    Subject authenticate( CredentialSet credentials ) throws AuthenticationException;
 }
 

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/Credential.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/Credential.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/Credential.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/Credential.java Sun Sep 11 17:35:27 2005
@@ -22,8 +22,10 @@
  * <p>
  * A {@link CredentialSet} groups together related <code>Credential</code>s
  * for subject authentication purposes.
+ *
+ * <p>
+ * <b>Warning</b>: This interface is due to disappear soon.
  */
 public interface Credential
 {
-    Object getValue();
 }

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/DefaultAuthenticator.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/DefaultAuthenticator.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/DefaultAuthenticator.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/DefaultAuthenticator.java Sun Sep 11 17:35:27 2005
@@ -26,25 +26,30 @@
 import java.util.Iterator;
 
 /**
- * An implementation of an authenticator that uses a single realm to perform authentication.
+ * An implementation of an authenticator that iterates through a set of realms and attempts authentication.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class DefaultAuthenticator implements Authenticator
 {
-    private final Realm m_realm;
+    private final Collection m_realms;
     private final Collection m_providers;
 
-    public DefaultAuthenticator( Realm realm )
+    public DefaultAuthenticator()
     {
-        m_realm = realm;
+        m_realms = new ArrayList();
         m_providers = new ArrayList();
     }
 
+    public void addRealm( Realm realm )
+    {
+        m_realms.add( realm );
+    }
+
     public Subject authenticate( CredentialSet credentials )
     {
-        Principal p = m_realm.validateCredentials( credentials );
-        if ( p == null ) return null;
+        Principal p = validateAgainsAllRealms( credentials );
+        if ( p == null ) throw new AuthenticationFailureException( credentials );
 
         Subject subject = new Subject();
         subject.getPrincipals().add( p );
@@ -56,6 +61,18 @@
         }
 
         return subject;
+    }
+
+    private Principal validateAgainsAllRealms( CredentialSet credentials )
+    {
+        for ( Iterator it = m_realms.iterator(); it.hasNext(); )
+        {
+            Realm realm = (Realm) it.next();
+            Principal p = realm.validateCredentials( credentials );
+            if ( p != null ) return p;
+        }
+        
+        return null;
     }
 
     /**

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/PasswordCredential.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/PasswordCredential.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/PasswordCredential.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/PasswordCredential.java Sun Sep 11 17:35:27 2005
@@ -30,7 +30,7 @@
         m_password = password;
     }
 
-    public Object getValue()
+    public String getPassword()
     {
         return m_password;
     }

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Realm.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Realm.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Realm.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Realm.java Sun Sep 11 17:35:27 2005
@@ -43,6 +43,8 @@
      * @param credentials The proof of identity
      * @return the Principal identity or null if the given credential set
      * is not matched in the realm
+     * @throws org.apache.authx.authentication.AuthenticationException if the credential set could
+     * not be validated 
      */
     Principal validateCredentials( CredentialSet credentials );
 }

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Selector.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Selector.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Selector.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/Selector.java Sun Sep 11 17:35:27 2005
@@ -20,5 +20,5 @@
 
 public interface Selector
 {
-    Selector eq( Class type, Credential c );
+    Selector eq( Object key, Credential c );
 }

Modified: directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernameCredential.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernameCredential.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernameCredential.java (original)
+++ directory/authx/trunk/core/src/java/org/apache/authx/authentication/realm/UsernameCredential.java Sun Sep 11 17:35:27 2005
@@ -30,11 +30,6 @@
         m_username = name;
     }
 
-    public Object getValue()
-    {
-        return m_username;
-    }
-
     public String getUsername()
     {
         return m_username;

Modified: directory/authx/trunk/core/src/test/org/apache/authx/authentication/DefaultAuthenticatorTest.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/test/org/apache/authx/authentication/DefaultAuthenticatorTest.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/test/org/apache/authx/authentication/DefaultAuthenticatorTest.java (original)
+++ directory/authx/trunk/core/src/test/org/apache/authx/authentication/DefaultAuthenticatorTest.java Sun Sep 11 17:35:27 2005
@@ -29,6 +29,7 @@
 import javax.security.auth.Subject;
 import java.util.Collection;
 import java.util.HashSet;
+import java.security.Principal;
 
 /**
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -41,17 +42,19 @@
     protected void setUp() throws Exception
     {
         m_mockRealm = new Mock( Realm.class );
-        m_authenticator = new DefaultAuthenticator( ( Realm ) m_mockRealm.proxy() );
+        m_authenticator = new DefaultAuthenticator();
+        m_authenticator.addRealm( new EmptyRealm() );
+        m_authenticator.addRealm( (Realm) m_mockRealm.proxy() );
     }
 
-    public void testAuthenticatesEntityAgainstRealm() throws Exception
+    public void testAuthenticationSucceedsIfAtLeastARealmValidatesProvidedCredentials() throws Exception
     {
         m_mockRealm.expects( once() ).method( "validateCredentials" ).with( eq( Creds.banana() ) ).will( returnValue( Fruits.banana() ) );
         m_authenticator.authenticate( Creds.banana() );
         m_mockRealm.verify();
     }
 
-    public void testBuildsUpSubjectWithEntityPrincipal()
+    public void testValidatedPrincipalIsAddedToSubject()
     {
         m_mockRealm.stubs().method( "validateCredentials" ).with( eq( Creds.banana() ) ).will( returnValue( Fruits.banana() ) );
 
@@ -61,12 +64,19 @@
                 subject.getPrincipals().contains( Fruits.banana() ) );
     }
 
-    public void testReturnsNullSubjectIfAuthenticationFails()
+    public void testAuthenticationFailesIfNoRealmValidateCredentials()
     {
         m_mockRealm.stubs().method( "validateCredentials" ).will( returnValue( null ) );
 
-        Subject s = m_authenticator.authenticate( new CredentialSet() );
-        assertNull( s );
+        try
+        {
+            m_authenticator.authenticate( new CredentialSet() );
+            fail();
+        }
+        catch ( AuthenticationFailureException expected )
+        {
+            assertTrue( true );
+        }
     }
 
     public void testBuildsUpSubjectWithEntityAttributes() throws Exception
@@ -89,6 +99,14 @@
         expectedAttributes.add( Attributes.yellow() );
 
         assertTrue( CollectionUtils.isProperSubCollection( expectedAttributes, s.getPrincipals() ) );
+    }
+
+    private static class EmptyRealm implements Realm {
+
+        public Principal validateCredentials( CredentialSet credentials )
+        {
+            return null;
+        }
     }
 
     public static void main( String[] args )

Modified: directory/authx/trunk/core/src/test/org/apache/authx/authentication/realm/UsernamePasswordAuthenticationTest.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/core/src/test/org/apache/authx/authentication/realm/UsernamePasswordAuthenticationTest.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/core/src/test/org/apache/authx/authentication/realm/UsernamePasswordAuthenticationTest.java (original)
+++ directory/authx/trunk/core/src/test/org/apache/authx/authentication/realm/UsernamePasswordAuthenticationTest.java Sun Sep 11 17:35:27 2005
@@ -16,17 +16,19 @@
  */
 package org.apache.authx.authentication.realm;
 
-import junit.framework.TestCase;
 import org.apache.authx.authentication.CredentialSet;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
 
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
+import java.security.Principal;
 
 /**
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class UsernamePasswordAuthenticationTest extends TestCase
+public class UsernamePasswordAuthenticationTest extends MockObjectTestCase
 {
     private UsernamePasswordAuthentication m_auth;
 
@@ -55,22 +57,22 @@
 
     public void testCredentialsWithNoUsernameAreNotSupported()
     {
-        assertFalse( "Reports it supports credentials with no username", m_auth.supports( new CredentialSet( Collections.singleton( new PasswordCredential( "password" ) ) ) ) );
+        assertFalse( m_auth.supports( new CredentialSet( Collections.singleton( new PasswordCredential( "password" ) ) ) ) );
     }
 
     public void testCredentialsWithNoPasswordAreNotSupported()
     {
-        assertFalse( "Reports it supports credentials with no password", m_auth.supports( new CredentialSet( Collections.singleton( new UsernameCredential( "username" ) ) ) ) );
+        assertFalse( m_auth.supports( new CredentialSet( Collections.singleton( new UsernameCredential( "username" ) ) ) ) );
     }
 
     public void testSetsWithAllValidCredentialsPlusExtraOnesAreNotSupported()
     {
-        assertFalse( "Reports it supports extra credentials", m_auth.supports( extraCredentials() ) );
+        assertFalse( m_auth.supports( extraCredentials() ) );
     }
 
     public void testAUsernameAndAPaswordIsAValidCredentialSet()
     {
-        assertTrue( "Reports it does not support credentials with a username and a password", m_auth.supports( validCredentials() ) );
+        assertTrue( m_auth.supports( validCredentials() ) );
     }
 
     public void testCredentialsMatchIfEqual()
@@ -81,6 +83,33 @@
 
     public void testPrincipalsCreatedAreUsernamePrincipals()
     {
-        assertEquals( "Created wrong principal", new UsernamePrincipal( "john" ), m_auth.principal( validCredentials() ) );
+        Principal principal = m_auth.principal( validCredentials() );
+        assertEquals( principal.getClass().getName(), new UsernamePrincipal( "john" ), principal );
+    }
+
+    public void testSelectsPrincipalWithSameUsernameAndSamePassword()
+    {
+        CredentialSet creds = validCredentials();
+        SelectorBuilder builder = m_auth.getAuthenticationBuilder( creds );
+        Mock selector = mock( Selector.class );
+        selector.expects( once() ).method( "eq" ).with( eq( UsernameCredential.class ), eq( username( creds ) ) );
+        selector.expects( once() ).method( "eq" ).with( eq( PasswordCredential.class ), eq( password( creds ) ) );
+
+        builder.build( selector( selector ) );
+    }
+
+    private Selector selector( Mock selector )
+    {
+        return (Selector) selector.proxy();
+    }
+
+    private Object password( CredentialSet creds )
+    {
+        return creds.getUniqueCredential( PasswordCredential.class);
+    }
+
+    private Object username( CredentialSet creds )
+    {
+        return creds.getUniqueCredential( UsernameCredential.class);
     }
 }

Modified: directory/authx/trunk/example/src/webapp/WEB-INF/nanocontainer.groovy
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/example/src/webapp/WEB-INF/nanocontainer.groovy?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/example/src/webapp/WEB-INF/nanocontainer.groovy (original)
+++ directory/authx/trunk/example/src/webapp/WEB-INF/nanocontainer.groovy Sun Sep 11 17:35:27 2005
@@ -6,21 +6,22 @@
     realm = new org.apache.authx.authentication.realm.MemoryRealm()
     // A nasty groovy bug prevents us from using servlet context to get the file real path
     // See http://jira.codehaus.org/browse/GROOVY-210
-    users = new java.io.FileReader( "c:/tools/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/users.xml" )
+    users = new java.io.FileReader( "/opt/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/users.xml" )
     realmBuilder = org.apache.authx.script.xml.Dom4JRealmBuilder.fromReader( users )
     realmBuilder.buildRealm( realm )
 
     // Our authenticator will use the realm we've just defined
-    authenticator = new org.apache.authx.authentication.DefaultAuthenticator( realm )
+    authenticator = new org.apache.authx.authentication.DefaultAuthenticator()
+    authenticator.addRealm( realm )
 
     // Users in our system can have groups and roles
     // Let's build the respective providers from their XML definitions
     roleProvider = new org.apache.authx.authentication.attribute.AttributeProvider()
-    roles = new java.io.FileReader( "c:/tools/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/roles.xml" )
+    roles = new java.io.FileReader( "/opt/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/roles.xml" )
     roleBuilder = org.apache.authx.script.xml.Dom4JRoleBuilder.fromReader( roles )
     roleBuilder.buildProvider( roleProvider )
     groupProvider = new org.apache.authx.authentication.attribute.AttributeProvider()
-    groups = new java.io.FileReader( "c:/tools/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/groups.xml" )
+    groups = new java.io.FileReader( "/opt/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/groups.xml" )
     groupBuilder = org.apache.authx.script.xml.Dom4JGroupBuilder.fromReader( groups )
     groupBuilder.buildProvider( groupProvider )
 
@@ -32,13 +33,13 @@
     // Next we have to define the system policy
     // Let's first read some rules from an XML file - notice the custom condition builder used
     policy = new org.apache.authx.authorization.Policy( new org.apache.authx.authorization.effect.PermitOverridesEffect() )
-    permissions = new java.io.FileReader( "c:/tools/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/permissions.xml" )
+    permissions = new java.io.FileReader( "/opt/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/permissions.xml" )
     policyBuilder = org.apache.authx.script.xml.Dom4JRuleSetBuilder.fromReader( permissions )
     policyBuilder.registerBuilder( new org.apache.authx.example.web.CanPurchaseConditionBuilder() )
     policyBuilder.buildRuleSet( policy )
 
     // Rules can also be defined in groovy
-    specials = new java.io.File( "c:/tools/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/treasure.groovy" )
+    specials = new java.io.File( "/opt/jakarta-tomcat-5.0.28/webapps/authx-example/WEB-INF/treasure.groovy" )
     // Rule classes can have dependencies that will be pulled out from the pico container
     pico.registerComponentInstance( new org.apache.authx.example.web.Treasure( 500 ) )
 

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/AuthenticationFilter.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/AuthenticationFilter.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/AuthenticationFilter.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/AuthenticationFilter.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,8 @@
+package org.apache.authx.authentication.realm;
+
+import org.apache.authx.authentication.CredentialSet;
+
+public interface AuthenticationFilter
+{
+    CredentialSet filter( Object instance );
+}

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Column.java Sun Sep 11 17:35:27 2005
@@ -16,8 +16,6 @@
  */
 package org.apache.authx.authentication.realm;
 
-import org.apache.authx.authentication.Credential;
-
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
@@ -26,10 +24,10 @@
     private final String m_name;
     private final Persister m_persister;
 
-    public Column( String name, Persister converter )
+    public Column( String name, Persister persister )
     {
         m_name = name;
-        m_persister = converter;
+        m_persister = persister;
     }
 
     public String getName()
@@ -39,12 +37,26 @@
 
     public Class getMappedType()
     {
-        return m_persister.getCredentialType();
+        return m_persister.getPersistentType();
+    }
+
+    public void setProperty( SQLStatement statement, Object property )
+    {
+        m_persister.setProperty( statement, property );
     }
 
-    public void setCredential( SQLStatement statement, Credential c )
+    public Object getProperty( ResultSet rs ) throws JDBCException
     {
-        m_persister.setCredential( statement, c );
+        Object property;
+        try
+        {
+            property = m_persister.getProperty( rs, m_name );
+        }
+        catch ( SQLException e )
+        {
+            throw new JDBCException( e );
+        }
+        return property;
     }
 
     public boolean equals( Object o )
@@ -67,20 +79,6 @@
 
     public String toString()
     {
-        return "m_name=" + m_name + ", m_type=" + m_persister.getCredentialType();
-    }
-
-    public Credential getCredential( ResultSet rs ) throws JDBCException
-    {
-        Credential credential = null;
-        try
-        {
-            credential = m_persister.getCredential( rs, m_name );
-        }
-        catch ( SQLException e )
-        {
-            throw new JDBCException( e );
-        }
-        return credential;
+        return "m_name=" + m_name + ", m_type=" + m_persister.getPersistentType();
     }
 }

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/CredentialSetMapping.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,29 @@
+package org.apache.authx.authentication.realm;
+
+import org.apache.authx.authentication.CredentialSet;
+
+import java.sql.ResultSet;
+import java.util.Iterator;
+import java.util.Map;
+
+public class CredentialSetMapping implements Mapping
+{
+    public Class getMappedType()
+    {
+        return CredentialSet.class;
+    }
+
+    public Object instanciate( Map columns, ResultSet rs )
+    {
+        CredentialSet creds = new CredentialSet();
+        for ( Iterator it = columns.keySet().iterator(); it.hasNext(); )
+        {
+            Object key = it.next();
+            Column column = (Column) columns.get( key );
+            creds.add( column.getProperty( rs ) );
+        }
+
+        return creds;
+    }
+
+}

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/EqExpression.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/EqExpression.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/EqExpression.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/EqExpression.java Sun Sep 11 17:35:27 2005
@@ -21,20 +21,19 @@
 public class EqExpression implements SQLExpression
 {
     private final Column m_column;
-    private final Credential m_value;
+    private final Credential m_credential;
 
-    // TODO: check that column supports credential type
     public EqExpression( Column column, Credential c )
     {
         m_column = column;
-        m_value = c;
+        m_credential = c;
     }
 
     public void prepare( SQLStatement statement )
     {
         statement.append( m_column.getName() );
         statement.append( operator() );
-        m_column.setCredential( statement, m_value );
+        m_column.setProperty( statement, m_credential );
     }
 
     protected String operator()

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCRealm.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCRealm.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCRealm.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCRealm.java Sun Sep 11 17:35:27 2005
@@ -28,6 +28,7 @@
     private final DataSource m_ds;
     private final Table m_table;
     private final AuthenticationMethod m_authenticationMethod;
+    private AuthenticationFilter m_filter;
 
     public JDBCRealm( DataSource ds, Table table )
     {
@@ -39,6 +40,12 @@
         m_ds = ds;
         m_table = table;
         m_authenticationMethod = authenticationMethod;
+        m_filter = new PassThroughFilter();
+    }
+
+    public void setCredentialFilter( AuthenticationFilter filter )
+    {
+        m_filter = filter;
     }
 
     public Principal validateCredentials( CredentialSet credentialSet )
@@ -56,8 +63,7 @@
         JDBCSelector selector = new JDBCSelector( m_table );
         selectorBuilder.build( selector );
 
-        CredentialSet creds = find( selector );
-        return creds;
+        return find( selector );
     }
 
     private CredentialSet find( JDBCSelector selector ) throws JDBCException
@@ -67,7 +73,7 @@
         try
         {
             conn = m_ds.getConnection();
-            creds = selector.select( conn );
+            creds = m_filter.filter( selector.select( conn ) );
         }
         catch ( SQLException e )
         {

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/JDBCSelector.java Sun Sep 11 17:35:27 2005
@@ -16,7 +16,6 @@
  */
 package org.apache.authx.authentication.realm;
 
-import org.apache.authx.authentication.CredentialSet;
 import org.apache.authx.authentication.Credential;
 
 import java.sql.Connection;
@@ -40,9 +39,9 @@
         m_builder = new SQLExpressionBuilder( table );
     }
 
-    public Selector eq( Class type, Credential c )
+    public Selector eq( Object key, Credential c )
     {
-        addExpression( m_builder.eq( type, c ) );
+        addExpression( m_builder.eq( key, c ) );
         return this;
     }
 
@@ -51,10 +50,10 @@
         m_expressions.add( expression );
     }
 
-    public CredentialSet select( Connection c ) throws SQLException
+    public Object select( Connection c ) throws SQLException
     {
         PreparedStatement st = null;
-        CredentialSet creds = null;
+        Object result = null;
         try
         {
             PreparedSQLStatement statement = new PreparedSQLStatement( "select * from " );
@@ -65,7 +64,7 @@
             ResultSet rs = st.executeQuery();
             if ( rs.next() )
             {
-                creds = m_table.instantiate( rs );
+                result = m_table.instantiate( rs );
             }
             rs.close();
         }
@@ -74,7 +73,7 @@
             if (st != null) st.close();
         }
 
-        return creds;
+        return result;
     }
 
     private void prepare( SQLStatement statement )

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Mapping.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Mapping.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Mapping.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Mapping.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,11 @@
+package org.apache.authx.authentication.realm;
+
+import java.util.Map;
+import java.sql.ResultSet;
+
+public interface Mapping
+{
+    Class getMappedType();
+
+    Object instanciate( Map columns, ResultSet rs );
+}

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PassThroughFilter.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PassThroughFilter.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PassThroughFilter.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/PassThroughFilter.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,11 @@
+package org.apache.authx.authentication.realm;
+
+import org.apache.authx.authentication.CredentialSet;
+
+public class PassThroughFilter implements AuthenticationFilter
+{
+    public CredentialSet filter( Object instance )
+    {
+        return (CredentialSet) instance;
+    }
+}

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Persister.java Sun Sep 11 17:35:27 2005
@@ -16,16 +16,14 @@
  */
 package org.apache.authx.authentication.realm;
 
-import org.apache.authx.authentication.Credential;
-
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
 public interface Persister
 {
-    Class getCredentialType();
+    Class getPersistentType();
 
-    Credential getCredential( ResultSet rs, String columnName ) throws SQLException;
+    Object getProperty( ResultSet rs, String columnName ) throws SQLException;
 
-    void setCredential( SQLStatement st, Credential c );
+    void setProperty( SQLStatement st, Object property );
 }

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionException.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionException.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionException.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionException.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,27 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.apache.authx.authentication.realm;
+
+import org.apache.authx.AuthXException;
+
+public class ReflectionException extends AuthXException
+{
+    public ReflectionException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

Propchange: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionException.java
------------------------------------------------------------------------------
    svn:executable = *

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionPersister.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionPersister.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionPersister.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionPersister.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,72 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.apache.authx.authentication.realm;
+
+import org.apache.authx.authentication.Credential;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class ReflectionPersister implements Persister
+{
+    private final Method m_accessor;
+    private final SQLType m_sqlType;
+
+    public ReflectionPersister( Method accessor )
+    {
+        m_accessor = accessor;
+        m_sqlType = SQLTypes.get( accessor.getReturnType() );
+    }
+
+    public Class getPersistentType()
+    {
+        return m_accessor.getDeclaringClass();
+    }
+
+    public void setProperty( SQLStatement st, Object property )
+    {
+        if (!getPersistentType().isInstance( property ))
+            throw new IllegalArgumentException( "Invalid property type: " + property.getClass().getName());
+        try
+        {
+            m_sqlType.setValue( st, m_accessor.invoke( property, null ) );
+        }
+        catch ( Exception e )
+        {
+            throw new ReflectionException( "Cannot access method: " + m_accessor, e );
+        }
+    }
+
+    public Object getProperty( ResultSet rs, String columnName ) throws SQLException
+    {
+        Credential c;
+        try
+        {
+            Constructor constructor = getPersistentType().getConstructor( new Class[] { m_sqlType.getJavaType() } );
+            Object value = m_sqlType.getValue( rs, columnName );
+            c = ((Credential) constructor.newInstance( new Object[] { value } ));
+        }
+        catch ( Exception e )
+        {
+            throw new ReflectionException( "Cannot create instance of type: " + getPersistentType(), e );
+        }
+
+        return c;
+    }
+}

Propchange: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/ReflectionPersister.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLExpressionBuilder.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLExpressionBuilder.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLExpressionBuilder.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLExpressionBuilder.java Sun Sep 11 17:35:27 2005
@@ -27,8 +27,8 @@
         m_table = table;
     }
 
-    public SQLExpression eq( Class type, Credential c )
+    public SQLExpression eq( Object key, Credential c )
     {
-        return new EqExpression( m_table.getColumn( type ), c );
+        return new EqExpression( m_table.getColumn( key ), c );
     }
 }

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SQLTypes.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,21 @@
+package org.apache.authx.authentication.realm;
+
+public class SQLTypes
+{
+    public static final SQLStringType STRING = new SQLStringType();
+
+    public static final SQLType[] ALL_TYPES = { STRING };
+
+    private SQLTypes() {};
+
+    public static SQLType get(Class javaType)
+    {
+        for ( int i = 0; i < ALL_TYPES.length; i++ )
+        {
+            SQLType type = ALL_TYPES[ i ];
+            if (type.getJavaType().isAssignableFrom( javaType ) ) return type;
+        }
+
+        throw new IllegalArgumentException( "Type not supported: " + javaType.getName() );
+    }
+}

Added: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java (added)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/SimpleTypePersister.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,47 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.apache.authx.authentication.realm;
+
+import org.apache.authx.authentication.realm.*;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class SimpleTypePersister implements Persister
+{
+    private final SQLType m_sqlType;
+
+    public SimpleTypePersister( SQLType sqlType )
+    {
+        m_sqlType = sqlType;
+    }
+
+    public Class getPersistentType()
+    {
+        return m_sqlType.getJavaType();
+    }
+
+    public void setProperty( SQLStatement st, Object property )
+    {
+        m_sqlType.setValue( st, property );
+    }
+
+    public Object getProperty( ResultSet rs, String columnName ) throws SQLException
+    {
+        return m_sqlType.getValue( rs, columnName );
+    }
+}

Modified: directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java (original)
+++ directory/authx/trunk/jdbc/src/java/org/apache/authx/authentication/realm/Table.java Sun Sep 11 17:35:27 2005
@@ -16,24 +16,28 @@
  */
 package org.apache.authx.authentication.realm;
 
-import org.apache.authx.authentication.CredentialSet;
-
+import java.sql.ResultSet;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Iterator;
-import java.sql.ResultSet;
 
 public class Table
 {
     private final String m_name;
     private final Map m_columns;
+    private final Mapping m_mapping;
 
     public Table( String name )
     {
+        this( name, new CredentialSetMapping() );
+    }
+
+    public Table( String name, Mapping mapping )
+    {
         m_name = name;
         m_columns = new HashMap();
+        m_mapping = mapping;
     }
 
     public String getName()
@@ -46,33 +50,25 @@
         return Collections.unmodifiableCollection( m_columns.values() );
     }
 
-    public void addColumn( Column column )
+    public String getColumnName( Object key )
     {
-        m_columns.put( column.getMappedType(), column );
+        Column column = getColumn( key );
+        return column != null ? column.getName() : null;
     }
 
-    public String getColumnName( Class type )
+    public Column getColumn( Object key )
     {
-        Column column = getColumn( type );
-        return column != null ? column.getName() : null;
+        return ( Column ) m_columns.get( key );
     }
 
-    public Column getColumn( Class type )
+    public Object instantiate( ResultSet rs )
     {
-        Column column = ( Column ) m_columns.get( type );
-        return column;
+        return m_mapping.instanciate( Collections.unmodifiableMap( m_columns ), rs );
     }
 
-    public CredentialSet instantiate( ResultSet rs )
+    public void addColumn( Object key, Column column )
     {
-        CredentialSet creds = new CredentialSet();
-        for ( Iterator it = m_columns.values().iterator(); it.hasNext(); )
-        {
-            Column column = ( Column ) it.next();
-            creds.add( column.getCredential( rs ) );
-        }
-
-        return creds;
+        m_columns.put( key, column );
     }
 }
 

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Columns.java Sun Sep 11 17:35:27 2005
@@ -16,17 +16,29 @@
  */
 package org.apache.authx.authentication.realm;
 
+import java.lang.reflect.Method;
+
 public class Columns
 {
     private Columns() {}
 
-    public static Column username()
+    public static Column username() throws NoSuchMethodException
+    {
+        return new Column( "USERNAME", new ReflectionPersister( getUsernameMethod() ) );
+    }
+
+    private static Method getUsernameMethod() throws NoSuchMethodException
+    {
+        return UsernameCredential.class.getMethod( "getUsername", null );
+    }
+
+    public static Column password() throws NoSuchMethodException
     {
-        return new Column( "USERNAME", new ConstructorInstantiationPersister( UsernameCredential.class, new SQLStringType() ) );
+        return new Column( "PASSWORD", new ReflectionPersister( getPasswordMethod() ) );
     }
 
-    public static Column password()
+    private static Method getPasswordMethod() throws NoSuchMethodException
     {
-        return new Column( "PASSWORD", new ConstructorInstantiationPersister( PasswordCredential.class, new SQLStringType() ) );
+        return PasswordCredential.class.getMethod( "getPassword", null );
     }
 }

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCRealmTest.java Sun Sep 11 17:35:27 2005
@@ -17,6 +17,7 @@
 package org.apache.authx.authentication.realm;
 
 import junit.framework.TestCase;
+import org.apache.authx.authentication.CredentialSet;
 
 public class JDBCRealmTest extends TestCase
 {
@@ -48,24 +49,38 @@
         assertEquals( new UsernamePrincipal( "joe" ), m_realm.validateCredentials( Creds.joe() ) );
     }
 
-    public void testAuthenticationFailsIfSelectionYieldsEmptyResult() throws Exception
+    public void testAuthenticationFailsIfSelectionYieldsAnEmptyResult() throws Exception
     {
         assertNull( m_realm.validateCredentials( Creds.jane() ) );
     }
 
-    public void testValidationFailsIfCredentialSetNotSupported()
+    public void testAuthenticationFailsIfCredentialSetNotSupported()
     {
-        assertNull( "Unsupported credential set was validated", m_realm.validateCredentials( Creds.unsupported() ) );
+        assertNull( m_realm.validateCredentials( Creds.unsupported() ) );
     }
 
-    public void testThrowsJDBCExceptionIfSQLExceptionOccurs()
+    public void testProvidesAHookToFilterAuthenticationResults()
+    {
+        m_realm.setCredentialFilter( new AuthenticationFilter()
+        {
+            public CredentialSet filter( Object instance )
+            {
+                return null;
+            }
+        } );
+
+        assertNull( m_realm.validateCredentials( Creds.joe() ) );
+    }
+
+    public void testThrowsJDBCExceptionIfSQLExceptionOccurs() throws NoSuchMethodException
     {
         m_realm = new JDBCRealm( m_db.getDataSource(), Tables.undefined() );
         try
         {
             m_realm.validateCredentials( Creds.joe() );
-            fail( "JDBCException expected" );
-        } catch ( JDBCException expected )
+            fail( "Authentication did not fail" );
+        }
+        catch ( JDBCException expected )
         {
             assertTrue( true );
         }

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/JDBCSelectorTest.java Sun Sep 11 17:35:27 2005
@@ -44,13 +44,13 @@
         m_db.dropAll();
     }
 
-    public void testFindsDataBasedOnCredentialExpression() throws Exception
+    public void testSelectsFromTableBasedOnExpression() throws Exception
     {
         m_selector.eq( UsernameCredential.class, new UsernameCredential( "joe" ) );
         assertEquals( Creds.joe(), m_selector.select( m_connection ) );
     }
 
-    public void testSupportsMultipleCredentialExpressions() throws Exception
+    public void testMultipleExpressionsAreCombinedUsingAnAndOperation() throws Exception
     {
         m_selector.eq( UsernameCredential.class, new UsernameCredential( "joe" ) );
         m_selector.eq( PasswordCredential.class, new PasswordCredential( "foo" ) );

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/MemoryDatabase.java Sun Sep 11 17:35:27 2005
@@ -97,7 +97,7 @@
         for ( Iterator it = creds.elements().iterator(); it.hasNext(); )
         {
             Credential credential = ( Credential ) it.next();
-            table.getColumn( credential.getClass() ).setCredential( statement, credential );
+            table.getColumn( credential.getClass() ).setProperty( statement, credential );
             if ( it.hasNext() ) statement.append( "," );
         }
         statement.append( ")" );

Added: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/ReflectionPersisterTest.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/ReflectionPersisterTest.java?rev=280223&view=auto
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/ReflectionPersisterTest.java (added)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/ReflectionPersisterTest.java Sun Sep 11 17:35:27 2005
@@ -0,0 +1,71 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.apache.authx.authentication.realm;
+
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+import java.sql.ResultSet;
+import java.lang.reflect.Method;
+
+public class ReflectionPersisterTest extends MockObjectTestCase
+{
+    public static void main( String[] args )
+    {
+        junit.textui.TestRunner.run( ReflectionPersisterTest.class );
+    }
+
+    public void testSetsPropertyValueByReflection() throws NoSuchMethodException
+    {
+        Mock mockStatement = mock( SQLStatement.class );
+        mockStatement.expects( once() ).method( "setString" ).with( eq( "jblow" ) );
+
+        UsernameCredential joe = new UsernameCredential( "jblow" );
+        ReflectionPersister persiser = new ReflectionPersister( getUsername() );
+        persiser.setProperty( sqlStatement( mockStatement ), joe );
+    }
+
+    private Method getUsername() throws NoSuchMethodException
+    {
+        return UsernameCredential.class.getMethod( "getUsername", null );
+    }
+
+    private SQLStatement sqlStatement( Mock mockStatement )
+    {
+        return (SQLStatement) mockStatement.proxy();
+    }
+
+    public void testInstantiatesClassUsingConstructorWithSingleArgument() throws Exception
+    {
+        String columnName = "username";
+        UsernameCredential expected = new UsernameCredential( "jblow" );
+
+        ReflectionPersister converter = new ReflectionPersister( getUsername() );
+
+        Mock mockResultSet = mock( ResultSet.class );
+        mockResultSet.stubs().method( "getString" ).with( eq( columnName ) ).will( returnValue( expected.getUsername() ) );
+
+        Object actual = converter.getProperty( resultSet( mockResultSet ), columnName );
+        assertEquals( expected, actual );
+    }
+
+    private ResultSet resultSet( Mock mockResultSet )
+    {
+        return (ResultSet) mockResultSet.proxy();
+    }
+
+}

Propchange: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/ReflectionPersisterTest.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java
URL: http://svn.apache.org/viewcvs/directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java?rev=280223&r1=280222&r2=280223&view=diff
==============================================================================
--- directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java (original)
+++ directory/authx/trunk/jdbc/src/test/org/apache/authx/authentication/realm/Tables.java Sun Sep 11 17:35:27 2005
@@ -20,19 +20,19 @@
 {
     public Tables() {}
 
-    public static Table users()
+    public static Table users() throws NoSuchMethodException
     {
         Table table = new Table( "USERS" );
-        table.addColumn( Columns.username() );
-        table.addColumn( Columns.password() );
+        table.addColumn( UsernameCredential.class, Columns.username() );
+        table.addColumn( PasswordCredential.class, Columns.password() );
         return table;
     }
 
-    public static Table undefined()
+    public static Table undefined() throws NoSuchMethodException
     {
         Table table = new Table( "UNDEFINED" );
-        table.addColumn( Columns.username() );
-        table.addColumn( Columns.password() );
+        table.addColumn( UsernameCredential.class, Columns.username() );
+        table.addColumn( PasswordCredential.class, Columns.password() );
         return table;
     }
 }



Mime
View raw message