FileDocCategorySizeDatePackage
JDBCAuthenticator.javaAPI DocExample3583Thu Aug 24 19:27:08 BST 2000com.imaginary.lwp.jdbc

JDBCAuthenticator

public class JDBCAuthenticator extends Object implements com.imaginary.lwp.Authenticator
Implements the Authenticator interface to authenticate a user ID/password against values stored in a database. This class expects the following table structure:
LWP_USER
USER_ID (VARCHAR(25))
PASSWORD (VARCHAR(25))
If you want a more complex authentication scheme, you should write your own Authenticator implementation.

This implementation ignores all role information and just authenticates base on UID/PW.
Last modified $Date: 1999/11/07 19:32:30 $

version
$Revision: 1.1 $
author
George Reese (borg@imaginary.com)

Fields Summary
public static final String
SELECT
The SQL SELECT statement.
Constructors Summary
Methods Summary
public voidauthenticate(java.lang.String uid, java.lang.String pw)
Authenticates the specified user ID against the specified password.

param
uid the user ID to authenticate
param
pw the password to use for authentication
throws
com.imaginary.lwp.AuthenticationException the user ID failed to authenticate against the specified password

    
                                             
         
          
        Connection conn = null;
        
        try {
            PreparedStatement stmt;
            String actual;
            ResultSet rs;
            
            conn = JDBCTransactionImpl.getJDBCConnection();
            stmt = conn.prepareStatement(SELECT);
            stmt.setString(1, uid);
            rs = stmt.executeQuery();
            if( !rs.next() ) {
                throw new AuthenticationException("Invalid user ID or " +
                                                  "password.");
            }
            actual = rs.getString(1);
            if( rs.wasNull() ) {
                throw new AuthenticationException("No password specified for "+
                                                  uid);
            }
            if( !actual.equals(pw) ) {
                throw new AuthenticationException("Invalid user ID or " +
                                                  "password.");
            }
            conn.commit();
        }
        catch( SQLException e ) {
            e.printStackTrace();
            throw new AuthenticationException(e);
        }
        finally {
            if( conn != null ) {
                try { conn.close(); }
                catch( SQLException e ) { }
            }
        }
    
public voidauthenticate(java.lang.String uid, java.lang.String pw, com.imaginary.lwp.AuthenticationRole r)
Authenticates the specified user ID against the specified password.

param
uid the user ID to authenticate
param
pw the password to use for authentication
param
r this is ignored
throws
com.imaginary.lwp.AuthenticationException the user ID failed to authenticate against the specified password

        authenticate(uid, pw);