| net.homeip.donaldm.httpdbase4j.JdbcBasicAuthenticator
JdbcBasicAuthenticator | public class JdbcBasicAuthenticator extends BasicAuthenticator (Code) | | Implements a Basic Authenticator for authentication from a JDBC
source.
author: Donald Munro |
Constructor Summary | |
public | JdbcBasicAuthenticator(String realm, String jdbcUrl, String sql) Create a JdbcBasicAuthenticator from a JDBC source.
Parameters: realm - The authorisation realm. Parameters: jdbcUrl - The URL to connect to the database (assumes that theJDBC driver has already been loaded. Parameters: sql - The SQL statement to validate the user. | public | JdbcBasicAuthenticator(String realm, String jdbcUrl, String sql, BasicAuthenticator nextAuthenticator) Create a JdbcBasicAuthenticator from a JDBC source.
Parameters: realm - The authorisation realm. Parameters: jdbcUrl - The URL to connect to the database (assumes that theJDBC driver has already been loaded). Parameters: sql - The SQL statement to validate the user. |
Method Summary | |
public boolean | checkCredentials(String userEntered, String passwordEntered) | protected String | hashPassword(String password) Overiding classes can overide this method if the database does not
have a password hashing function or they wish to implement their own
hashing.
Parameters: password - The password entered by the user The hashed password. | protected Connection | openConnection(String jdbcUrl) Overiding classes can overide this method to open a JDBC
connection. |
m_nextAuthenticator | BasicAuthenticator m_nextAuthenticator(Code) | | |
JdbcBasicAuthenticator | public JdbcBasicAuthenticator(String realm, String jdbcUrl, String sql)(Code) | | Create a JdbcBasicAuthenticator from a JDBC source.
Parameters: realm - The authorisation realm. Parameters: jdbcUrl - The URL to connect to the database (assumes that theJDBC driver has already been loaded. Parameters: sql - The SQL statement to validate the user. Parameters should be placed in the SQL in the form of a ? character ie as for a PreparedStatement. The SQL should read :
SELECT HASH_FUNCTION(Entered-Password), Hashed-Password FROM Users-Table WHERE USER = Entered-User
where HASH_FUNCTION is the databases password hashing function. For example for MySQL you could have:SELECT PASSWORD(?), PasswdFROM UsersWHERE User = ?The row should have been inserted using the hashing function egINSERT INTO Users(User, Passwd) VALUES ('idiot', PASSWORD('moron')) |
JdbcBasicAuthenticator | public JdbcBasicAuthenticator(String realm, String jdbcUrl, String sql, BasicAuthenticator nextAuthenticator)(Code) | | Create a JdbcBasicAuthenticator from a JDBC source.
Parameters: realm - The authorisation realm. Parameters: jdbcUrl - The URL to connect to the database (assumes that theJDBC driver has already been loaded). Parameters: sql - The SQL statement to validate the user. Parameters should be placed in the SQL in the form of a ? character ie as for a PreparedStatement. The SQL should read :
SELECT HASH_FUNCTION(Entered-Password), Hashed-Password FROM Users-Table WHERE USER = Entered-User
where HASH_FUNCTION is the databases password hashing function. For example for MySQL you could have:SELECT PASSWORD(?), PasswdFROM UsersWHERE User = ?The row should have been inserted using the hashing function egINSERT INTO Users(User, Passwd) VALUES ('idiot', PASSWORD('moron')) Parameters: nextAuthenticator - If authorization fails (in the sense of not beingfound or an exception occurring, but not in the case of the user being found but having entered the incorrect password) then forward theauthentication onto this authenticator. |
checkCredentials | public boolean checkCredentials(String userEntered, String passwordEntered)(Code) | | |
hashPassword | protected String hashPassword(String password)(Code) | | Overiding classes can overide this method if the database does not
have a password hashing function or they wish to implement their own
hashing.
Parameters: password - The password entered by the user The hashed password. The default implementation simply returnsthe incoming password parameter |
openConnection | protected Connection openConnection(String jdbcUrl) throws SQLException(Code) | | Overiding classes can overide this method to open a JDBC
connection.
Parameters: jdbcUrl - The URL to connect to the database A java.sql.Connection to the database. The default implementation returns DriverManager.getConnection(jdbcUrl) throws: java.sql.SQLException - |
|
|