public abstract class AbstractLogin extends java.lang.Object implements Login
The Login is primarily responsible for extracting the credentials from the request (typically username and password) and passing those to the ServletAuthenticator.
The Servlet API calls the Login in two contexts: directly from
ServletRequest.getUserPrincipal(), and during
security checking. When called from the Servlet API, the login class
can't change the response. In other words, if an application
calls getUserPrincipal(), the Login class can't return a forbidden
error page. When the servlet engine calls authenticate(), the login class
can return an error page (or forward internally.)
Normally, Login implementations will defer the actual authentication to a ServletAuthenticator class. That way, both "basic" and "form" login can use the same DatabaseAuthenticator. Some applications, like SSL client certificate login, may want to combine the Login and authentication into one class.
Login instances are configured through bean introspection. Adding
a public setFoo(String foo) method will be configured with
the following login-config:
<myfoo:CustomLogin xmlns:myfoo="urn:java:com.foo.myfoo">
<foo>bar</foo>
</myfoo:CustomLogin>
| Modifier and Type | Field and Description |
|---|---|
protected Authenticator |
_auth
The configured authenticator for the login.
|
protected SingleSignon |
_singleSignon |
LOGIN_PASSWORD, LOGIN_USER, LOGIN_USER_NAME| Modifier | Constructor and Description |
|---|---|
protected |
AbstractLogin() |
| Modifier and Type | Method and Description |
|---|---|
protected java.security.Principal |
findSavedUser(HttpServletRequest request)
Looks up the user based on session or single signon.
|
Authenticator |
getAuthenticator()
Gets the authenticator.
|
java.lang.String |
getAuthType()
Returns the authentication type.
|
protected java.security.Principal |
getLoginPrincipalImpl(HttpServletRequest request)
Gets the user from a persistent cookie, using authenticateCookie
to actually look the cookie up.
|
protected SingleSignon |
getSingleSignon() |
java.security.Principal |
getUserPrincipal(HttpServletRequest request)
Returns the Principal associated with the current request.
|
protected java.security.Principal |
getUserPrincipalImpl(HttpServletRequest request)
Gets the user from a persistent cookie, using authenticateCookie
to actually look the cookie up.
|
void |
init()
Initialize the login.
|
boolean |
isLoginUsedForRequest(HttpServletRequest request)
Returns true if the login can be used for this request.
|
boolean |
isLogoutOnSessionTimeout()
Returns true if the user should be logged out on a session timeout.
|
boolean |
isPasswordBased()
Returns true if username and password based authentication is supported.
|
protected boolean |
isSavedUserValid(HttpServletRequest request,
java.security.Principal savedUser)
Returns the non-authenticated principal for the user request
|
boolean |
isSessionSaveLogin()
Sets true if the user should be saved in the session.
|
boolean |
isUserInRole(java.security.Principal user,
java.lang.String role)
Returns true if the current user plays the named role.
|
protected java.security.Principal |
login(HttpServletRequest request,
HttpServletResponse response)
Attempts to login the user if the user cannot be found in the
session or the single-signon.
|
java.security.Principal |
login(HttpServletRequest request,
HttpServletResponse response,
boolean isFail)
Logs a user in.
|
protected void |
loginChallenge(HttpServletRequest request,
HttpServletResponse response)
Implementation of the login challenge
|
protected void |
loginSuccessResponse(java.security.Principal user,
HttpServletRequest request,
HttpServletResponse response)
HTTP updates after a successful login
|
void |
logout(java.security.Principal user,
HttpServletRequest request,
HttpServletResponse response)
Logs the user out from the given request.
|
protected void |
logoutImpl(java.security.Principal user,
HttpServletRequest request,
HttpServletResponse response)
Logs the user out from the given request.
|
protected void |
saveUser(HttpServletRequest request,
java.security.Principal user)
Saves the user based on session or single signon.
|
void |
sessionInvalidate(HttpSession session,
boolean isTimeout)
Called when the session invalidates.
|
void |
setAuthenticator(Authenticator auth)
Sets the authenticator.
|
void |
setLogoutOnSessionTimeout(boolean logout)
Sets true if the principal should logout when the session times out.
|
void |
setSessionSaveLogin(boolean isSave)
Sets true if the user should be saved in the session.
|
java.lang.String |
toString()
Logs the user out from the session.
|
protected Authenticator _auth
protected SingleSignon _singleSignon
public void setAuthenticator(Authenticator auth)
public Authenticator getAuthenticator()
getAuthenticator in interface Loginprotected SingleSignon getSingleSignon()
public boolean isLogoutOnSessionTimeout()
public void setLogoutOnSessionTimeout(boolean logout)
public void setSessionSaveLogin(boolean isSave)
public boolean isSessionSaveLogin()
@PostConstruct public void init() throws ServletException
init() will be called after all
the bean parameters have been set.ServletExceptionpublic java.lang.String getAuthType()
getAuthType is called
by HttpServletRequest.getAuthType.getAuthType in interface Loginpublic boolean isLoginUsedForRequest(HttpServletRequest request)
isLoginUsedForRequest in interface Loginpublic java.security.Principal getUserPrincipal(HttpServletRequest request)
getUserPrincipal in interface Loginrequest - servlet requestpublic java.security.Principal login(HttpServletRequest request, HttpServletResponse response, boolean isFail)
authenticate
sets the reponse error page and returns null.protected java.security.Principal login(HttpServletRequest request, HttpServletResponse response)
protected java.security.Principal findSavedUser(HttpServletRequest request)
protected void saveUser(HttpServletRequest request, java.security.Principal user)
public boolean isPasswordBased()
LoginisPasswordBased in interface LoginBasicLoginprotected java.security.Principal getUserPrincipalImpl(HttpServletRequest request)
protected boolean isSavedUserValid(HttpServletRequest request, java.security.Principal savedUser)
protected java.security.Principal getLoginPrincipalImpl(HttpServletRequest request)
protected void loginChallenge(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
ServletExceptionjava.io.IOExceptionprotected void loginSuccessResponse(java.security.Principal user,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException,
java.io.IOException
ServletExceptionjava.io.IOExceptionpublic boolean isUserInRole(java.security.Principal user,
java.lang.String role)
isUserInRole is called in response to the
HttpServletRequest.isUserInRole call.isUserInRole in interface Loginuser - UserPrincipal object associated with requestrole - to be testedpublic void logout(java.security.Principal user,
HttpServletRequest request,
HttpServletResponse response)
Since there is no servlet API for logout, this must be called directly from user code. Resin stores the web-app's login object in the ServletContext attribute "caucho.login".
public void sessionInvalidate(HttpSession session, boolean isTimeout)
sessionInvalidate in interface Loginprotected void logoutImpl(java.security.Principal user,
HttpServletRequest request,
HttpServletResponse response)
Since there is no servlet API for logout, this must be called directly from user code. Resin stores the web-app's login object in the ServletContext attribute "caucho.login".
public java.lang.String toString()
toString in class java.lang.Objectuser - the logged in user