directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: r109273 - in incubator/directory/janus/trunk/jdbc: . src/java/org/apache/janus/authentication/realm src/test/org/apache/janus/authentication/realm
Date Wed, 01 Dec 2004 03:50:30 GMT
Author: vtence
Date: Tue Nov 30 19:50:29 2004
New Revision: 109273

URL: http://svn.apache.org/viewcvs?view=rev&rev=109273
Log:
Selector will now detect unsupported expression
Modified:
   incubator/directory/janus/trunk/jdbc/project.xml
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java
   incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java
   incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java

Modified: incubator/directory/janus/trunk/jdbc/project.xml
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/project.xml?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/project.xml&r1=109272&p2=incubator/directory/janus/trunk/jdbc/project.xml&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/project.xml	(original)
+++ incubator/directory/janus/trunk/jdbc/project.xml	Tue Nov 30 19:50:29 2004
@@ -23,5 +23,10 @@
             <artifactId>janus-impl</artifactId>
             <version>${pom.currentVersion}</version>
         </dependency>
+        <dependency>
+            <groupId>hsqldb</groupId>
+            <artifactId>hsqldb</artifactId>
+            <version>1.7.2.2</version>
+        </dependency>
     </dependencies>
 </project>

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java&r1=109272&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/AndExpression.java
Tue Nov 30 19:50:29 2004
@@ -55,6 +55,11 @@
         return ( String[] ) parameters.toArray( new String[parameters.size()] );
     }
 
+    public boolean supports( Table table )
+    {
+        return m_left.supports( table ) && m_right.supports( table );
+    }
+
     protected String operand()
     {
         return "and";

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java&r1=109272&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/EqExpression.java
Tue Nov 30 19:50:29 2004
@@ -47,6 +47,11 @@
         return new String[] { table.getColumnValue( m_value ) };
     }
 
+    public boolean supports( Table table )
+    {
+        return table.supports( m_type ) ;
+    }
+
     protected String operand()
     {
         return "=";

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java&r1=109272&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Expression.java
Tue Nov 30 19:50:29 2004
@@ -23,4 +23,6 @@
     int getParameterCount();
 
     String[] getParameterValues( Table table );
+
+    boolean supports( Table table );
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java&r1=109272&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/JDBCSelector.java
Tue Nov 30 19:50:29 2004
@@ -18,8 +18,8 @@
 
 import java.sql.Connection;
 import java.sql.PreparedStatement;
-import java.sql.SQLException;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -37,13 +37,14 @@
 
     public void addExpression( Expression expression )
     {
+        if ( !expression.supports( m_table ) ) throw new IllegalArgumentException( "Expression
does not support table metadata" );
         m_expressions.add( expression );
     }
 
     public boolean select( Connection c ) throws SQLException
     {
         PreparedStatement statement = c.prepareStatement( buildQueryString() );
-        bindParameterValues ( statement );
+        bindParameterValues( statement );
         ResultSet rs = statement.executeQuery();
         boolean found = rs.next();
         statement.close();
@@ -51,7 +52,7 @@
         return found;
     }
 
-    protected String buildQueryString()
+    private String buildQueryString()
     {
         StringBuffer statement = new StringBuffer();
         statement.append( "select * from " ).append( m_table.getName() ).append( " where
" );
@@ -66,33 +67,33 @@
         return statement.toString();
     }
 
-    protected void bindParameterValues( PreparedStatement statement ) throws SQLException
+    private void bindParameterValues( PreparedStatement statement ) throws SQLException
     {
-        int index = 1;
+        Parameters parameters = new Parameters( statement );
         for ( Iterator it = m_expressions.iterator(); it.hasNext(); )
         {
             Expression expression = ( Expression ) it.next();
-            index += bindExpressionParameters( statement, index, expression );
+            parameters.bind( expression );
         }
-
     }
 
-    private int bindExpressionParameters( PreparedStatement statement, int startIndex, Expression
expression )
-            throws SQLException
+    private class Parameters
     {
-        String[] values = expression.getParameterValues( m_table );
-        for ( int i = 0; i < values.length; i++ )
+        private final PreparedStatement m_statement;
+        private int m_index = 1;
+
+        public Parameters( PreparedStatement statement )
         {
-            statement.setString( startIndex + i, values[i] );
+            m_statement = statement;
         }
 
-        return values.length;
-    }
-
-    protected String[] getParameterValues()
-    {
-        Collection parameters = new ArrayList();
-
-        return ( String[] ) parameters.toArray( new String[parameters.size()] );
+        public void bind( Expression expression ) throws SQLException
+        {
+            String[] values = expression.getParameterValues( m_table );
+            for ( int i = 0; i < values.length; i++ )
+            {
+                m_statement.setString( m_index++, values[i] );
+            }
+        }
     }
 }

Modified: incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java&r1=109272&p2=incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/java/org/apache/janus/authentication/realm/Table.java
Tue Nov 30 19:50:29 2004
@@ -16,11 +16,10 @@
  */
 package org.apache.janus.authentication.realm;
 
-import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Collections;
 
 public class Table
 {
@@ -50,21 +49,27 @@
         m_columns.put( column.getMappedType(), column );
     }
 
-    public String getColumnName( Class credentialType )
+    public String getColumnName( Class type )
     {
-        return column( credentialType ).getName();
+        Column column = column( type );
+        return column != null ? column.getName() : null;
     }
 
-    public String getColumnValue( Object credential )
+    public String getColumnValue( Object object )
     {
-        Converter converter = ( Converter ) m_converters.get( credential.getClass() );
-        return converter != null ? converter.convert( credential ) : credential.toString();
+        Converter converter = ( Converter ) m_converters.get( object.getClass() );
+        return converter != null ? converter.convert( object ) : object.toString();
     }
 
-    private Column column( Class credentialType )
+    private Column column( Class type )
     {
-        Column column = ( Column ) m_columns.get( credentialType );
+        Column column = ( Column ) m_columns.get( type );
         return column;
+    }
+
+    public boolean supports( Class type )
+    {
+        return m_columns.containsKey( type );
     }
 }
 

Modified: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java&r1=109272&p2=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCRealmTest.java
Tue Nov 30 19:50:29 2004
@@ -44,12 +44,6 @@
         m_db.dropAll();
     }
 
-    /**
-     * o several same credential -> should be caught by authentication method
-     * o parametrize credential type -> column name
-     * <p/>
-     * undefined column for credential type?
-     */
     public void testExecutesSelectionQueriesAgainstDatabase() throws Exception
     {
         JDBCSelector selector = new JDBCSelector( Tables.users() );

Modified: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java&r1=109272&p2=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/JDBCSelectorTest.java
Tue Nov 30 19:50:29 2004
@@ -18,11 +18,8 @@
 
 import junit.framework.TestCase;
 
-import java.util.Arrays;
 import java.sql.Connection;
 
-import org.jmock.Mock;
-
 public class JDBCSelectorTest extends TestCase
 {
     private JDBCSelector m_selector;
@@ -48,13 +45,8 @@
     }
 
     /**
-     *
-     * run selection on JDBC connection
-     *
      * conversion of credential object values to string values
-     * expression not a JDBC expression?
      */
-
     public void testFindsDataBasedOnCredentialExpression() throws Exception
     {
         m_selector.addExpression( new EqExpression( UsernameCredential.class, "joe" ) );
@@ -74,5 +66,18 @@
         m_selector.addExpression( new AndExpression( new EqExpression( UsernameCredential.class,
"joe" ),
                 new EqExpression( PasswordCredential.class, "foo" ) ) );
         assertTrue( m_selector.select( m_connection ) );
+    }
+
+    public void testValidatesExpressionAgainstTableMetadata()
+    {
+        try
+        {
+            m_selector.addExpression( new EqExpression( Object.class, new Object() ) );
+            fail( "IllegalArgumentException expected" );
+        }
+        catch ( IllegalArgumentException expected )
+        {
+            assertTrue( true );
+        }
     }
 }

Modified: incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java?view=diff&rev=109273&p1=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java&r1=109272&p2=incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java&r2=109273
==============================================================================
--- incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java
(original)
+++ incubator/directory/janus/trunk/jdbc/src/test/org/apache/janus/authentication/realm/MemoryDatabase.java
Tue Nov 30 19:50:29 2004
@@ -99,7 +99,6 @@
         for ( int i = 0; i < tables.length; i++ )
         {
             drop( tables[i] );
-
         }
     }
 }

Mime
View raw message