public class DatabaseAuthenticator extends AbstractCookieAuthenticator
The default table schema looks something like:
CREATE TABLE LOGIN ( username VARCHAR(250) NOT NULL, password VARCHAR(250), cookie VARCHAR(250), PRIMARY KEY (username) );
<security:DatabaseAuthenticator data-source="jdbc/user"/>
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
_cookieDomain |
protected long |
_cookieMaxAge |
protected int |
_cookieVersion |
protected boolean |
_useCookie |
_passwordDigest, _passwordDigestAlgorithm, _passwordDigestRealm, NULL_USER
Constructor and Description |
---|
DatabaseAuthenticator() |
Modifier and Type | Method and Description |
---|---|
protected void |
addAuthCookie(java.security.Principal user,
HttpServletRequest request)
Adds a cookie to store authentication.
|
boolean |
associateCookie(java.security.Principal user,
java.lang.String cookieValue)
Associates a user with a persistent cookie.
|
protected java.security.Principal |
authenticate(java.security.Principal principal,
PasswordCredentials cred,
java.lang.Object details)
Main authenticator API.
|
java.security.Principal |
authenticate(java.lang.String username,
java.lang.String password,
HttpServletRequest request)
Authenticates the user given the request.
|
java.security.Principal |
authenticateByCookie(java.lang.String cookieValue)
Authenticate based on a cookie.
|
java.lang.String |
getCookieAuthQuery()
Gets the cookie auth query.
|
java.lang.String |
getCookieAuthUpdate()
Gets the cookie update query.
|
java.lang.String |
getCookieDomain()
Returns the domain for a login cookie.
|
long |
getCookieMaxAge()
Returns the max-age for a login cookie.
|
int |
getCookieVersion()
Returns the version for a login cookie.
|
javax.sql.DataSource |
getDataSource()
Gets the database
|
java.lang.String |
getPasswordQuery()
Gets the password query.
|
protected PasswordUser |
getPasswordUser(java.lang.String username)
Returns the password for authenticators too lazy to calculate the
digest.
|
java.lang.String |
getRoleQuery()
Gets the role query.
|
boolean |
getUseCookie()
Returns true if Resin should generate the resinauth cookie by default.
|
void |
init()
Initialize the authenticator.
|
boolean |
isCookieSupported(java.lang.String jUseCookieAuth)
Returns the authentication cookie
|
boolean |
isUserInRole(java.security.Principal principal,
java.lang.String role)
Returns true if the user plays the named role.
|
java.security.Principal |
loginImpl(java.lang.String username,
java.lang.String password)
Authenticates the user given the request.
|
void |
setCookieAuthQuery(java.lang.String query)
Sets the cookie auth query.
|
void |
setCookieAuthUpdate(java.lang.String query)
Sets the cookie update query.
|
void |
setCookieDomain(java.lang.String cookieDomain)
Sets the domain for a login cookie.
|
void |
setCookieLogout(boolean cookieLogout)
If true, the cookie is removed on logout
|
void |
setCookieMaxAge(Period cookieMaxAge)
Sets the max age for a login cookie.
|
void |
setCookieVersion(int version)
Sets the version for a login cookie.
|
void |
setDataSource(javax.sql.DataSource dataSource)
Sets the database pool name.
|
void |
setPasswordQuery(java.lang.String query)
Sets the password query.
|
void |
setRoleQuery(java.lang.String query)
Sets the role query.
|
void |
setUseCookie(boolean useCookie)
Set true if Resin should generate the resinauth cookie by default.
|
addRoleMapping, authenticate, authenticate, authenticate, authenticate, digest, getAlgorithm, getDigest, getDigestSecret, getDigestSecret, getLogoutOnSessionTimeout, getPasswordDigest, getPasswordDigest, getPasswordDigestAlgorithm, getPasswordDigestRealm, getPasswordUser, getSingleSignon, logout, setLogoutOnSessionTimeout, setPasswordDigest, setPasswordDigestAlgorithm, setPasswordDigestRealm, setSerializationHandle, stringToDigest, toString, writeReplace
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
authenticate, getAlgorithm, logout
protected boolean _useCookie
protected int _cookieVersion
protected java.lang.String _cookieDomain
protected long _cookieMaxAge
public javax.sql.DataSource getDataSource()
public void setDataSource(javax.sql.DataSource dataSource)
public java.lang.String getPasswordQuery()
Example:
SELECT password FROM LOGIN WHERE username=?
public void setPasswordQuery(java.lang.String query)
public java.lang.String getCookieAuthQuery()
public void setCookieAuthQuery(java.lang.String query)
public java.lang.String getCookieAuthUpdate()
public void setCookieAuthUpdate(java.lang.String query)
public void setCookieLogout(boolean cookieLogout)
public java.lang.String getRoleQuery()
public void setRoleQuery(java.lang.String query)
public boolean getUseCookie()
public void setUseCookie(boolean useCookie)
public int getCookieVersion()
public void setCookieVersion(int version)
public java.lang.String getCookieDomain()
public void setCookieDomain(java.lang.String cookieDomain)
public long getCookieMaxAge()
public void setCookieMaxAge(Period cookieMaxAge)
@PostConstruct public void init() throws ServletException
init
in class AbstractAuthenticator
ServletException
protected java.security.Principal authenticate(java.security.Principal principal, PasswordCredentials cred, java.lang.Object details)
authenticate
in class AbstractAuthenticator
public java.security.Principal authenticate(java.lang.String username, java.lang.String password, HttpServletRequest request)
username
- the user name for the loginpassword
- the password for the loginpublic boolean isCookieSupported(java.lang.String jUseCookieAuth)
isCookieSupported
in interface CookieAuthenticator
isCookieSupported
in class AbstractCookieAuthenticator
protected void addAuthCookie(java.security.Principal user, HttpServletRequest request)
public java.security.Principal loginImpl(java.lang.String username, java.lang.String password)
username
- the user name for the loginpassword
- the password for the loginprotected PasswordUser getPasswordUser(java.lang.String username)
getPasswordUser
in class AbstractAuthenticator
username
- the string user namepublic java.security.Principal authenticateByCookie(java.lang.String cookieValue)
authenticateByCookie
in interface CookieAuthenticator
authenticateByCookie
in class AbstractCookieAuthenticator
cookieValue
- the value of the resin-auth cookiepublic boolean associateCookie(java.security.Principal user, java.lang.String cookieValue)
associateCookie
in interface CookieAuthenticator
associateCookie
in class AbstractCookieAuthenticator
user
- the user for the cookiecookieValue
- the value of the resin-auth cookiepublic boolean isUserInRole(java.security.Principal principal, java.lang.String role)
AbstractAuthenticator
isUserInRole
in interface Authenticator
isUserInRole
in class AbstractAuthenticator
principal
- the user to testrole
- the role to test