|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.caucho.http.security.AbstractAuthenticator com.boylesoftware.cb2.auth.servlet.resin.JdbcAuthenticator
Authenticator implementation for Caucho Resin servlet engine, which uses database as the user accounts storage.
Resin already has an authenticator implementation called
com.caucho.http.security.JdbcAuthenticator
. However,
that imlpementation is virtually unusable since it queries
the database for each isUserInRole
call, which is
exteremely inefficient. Our implementation fetches the whole
list of user roles at the user login and caches it in the
session. It also means that any updates to a user roles will
be reflected only with the next login.
In order to use this authenticator for servlet container
managed authentication you should add it to the
resin.conf
file. Here is an example:
<caucho.com> ... <resource-ref> <res-ref-name>jdbc/dataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> ... </resource-ref> ... <http-server> ... <host id=""> ... <authenticator id="com.boylesoftware.cb2.auth.servlet.resin.JdbcAuthenticator"> <pool-name>jdbc/dataSource</pool-name> <password-query> SELECT password FROM tbUser WHERE loginName = ? </password-query> SELECT roleName FROM tbUserRole INNER JOIN tbUser ON tbUserRole.userId = tbUser.userId WHERE loginName = ? <roles-query> </roles-query> </authenticator> ... </host> </http-server> </caucho.com>
Note that Resin requires authenticator implementation class to be
in the startup class path, so this class is included in the
cb2-auth.jar
, which has to be added to the Resin's
startup class path.
Nested Class Summary |
Nested classes inherited from class com.caucho.http.security.AbstractAuthenticator |
com.caucho.http.security.AbstractAuthenticator.LoginPrincipal |
Field Summary | |
protected javax.sql.DataSource |
dataSource
The datasource for database connections. |
Fields inherited from class com.caucho.http.security.AbstractAuthenticator |
LOGIN_NAME, passwordDigest, passwordDigestName, principalCache, principalCacheSize |
Constructor Summary | |
JdbcAuthenticator()
|
Method Summary | |
protected java.lang.String |
getDigestPassword(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.ServletContext application,
java.lang.String username,
java.lang.String realm)
Returns the password from the database. |
protected java.lang.String |
getPassword(java.lang.String username)
Gets a user's password from the database, |
java.lang.String |
getPasswordQuery()
Gets the password query. |
java.lang.String |
getPoolName()
Gets the database connection pool name. |
protected java.util.Set |
getRoles(java.lang.String username)
Gets a collection of user's security roles from the database. |
java.lang.String |
getRolesQuery()
Gets the role query. |
void |
init()
Initialize the authenticator. |
boolean |
isUserInRole(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.ServletContext application,
java.security.Principal principal,
java.lang.String role)
Checks if a user plays a security role. |
java.security.Principal |
loginImpl(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.ServletContext application,
java.lang.String username,
java.lang.String password)
Authenticates the user given the request. |
void |
setPasswordQuery(java.lang.String passwordQuery)
Sets the password query. |
void |
setPoolName(java.lang.String poolName)
Sets the database connection pool name. |
void |
setRolesQuery(java.lang.String rolesQuery)
Sets the role query. |
Methods inherited from class com.caucho.http.security.AbstractAuthenticator |
digest, getDigestSecret, getLogoutOnSessionTimeout, getPasswordDigest, getPrincipalCacheSize, getUserPrincipal, getUserPrincipalImpl, login, loginDigest, loginDigestImpl, logout, setLogoutOnSessionTimeout, setPasswordDigest, setPrincipalCacheSize |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected javax.sql.DataSource dataSource
Constructor Detail |
public JdbcAuthenticator()
Method Detail |
public java.lang.String getPoolName()
public void setPoolName(java.lang.String poolName)
poolName
- the pool name in the JNDI.public java.lang.String getPasswordQuery()
public void setPasswordQuery(java.lang.String passwordQuery)
passwordQuery
- the SQL query, which fetches user's
password by login name.public java.lang.String getRolesQuery()
public void setRolesQuery(java.lang.String rolesQuery)
rolesQuery
- the SQL query, which fetches the list of
roles for a user by the user's login name.public void init() throws javax.servlet.ServletException
javax.servlet.ServletException
- if an error happened.public java.security.Principal loginImpl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application, java.lang.String username, java.lang.String password) throws javax.servlet.ServletException
request
- the HTTP request.response
- the HTTP response.application
- the Servlet context.username
- the user name for the login.password
- the password for the login.
null
for a failure.
javax.servlet.ServletException
- if an error happened.protected java.lang.String getDigestPassword(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application, java.lang.String username, java.lang.String realm) throws javax.servlet.ServletException
request
- the HTTP request.response
- the HTTP response.application
- the Servlet context.username
- the user's login name.realm
- the realm.
null
for a failure.
javax.servlet.ServletException
- if an error happened.protected java.lang.String getPassword(java.lang.String username) throws javax.servlet.ServletException
username
- the user's login name.
null
if no such user.
javax.servlet.ServletException
- if an error happened.protected java.util.Set getRoles(java.lang.String username) throws javax.servlet.ServletException
username
- the user's login name.
String
). Mat return an empty set, but never
a null
.
javax.servlet.ServletException
- if an error happened.public boolean isUserInRole(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application, java.security.Principal principal, java.lang.String role)
request
- the HTTP request.response
- the HTTP response.application
- the Servlet context.principal
- the user principal, must be
PrincipalWithRoles
instance.role
- the role to check.
true
if the user plays the role.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |