public class CookieAuthenticator extends ChallengeAuthenticator
ChallengeScheme.HTTP_BASIC
.getLoginPath()
URI. The request entity should contain an HTML form
with two fields, the first one named getIdentifierFormName()
and the
second one named getSecretFormName()
.getLogoutPath()
URI.getRedirectQueryName()
.challenge(Response, boolean)
method is invoked by the parent class,
and its default behavior is to redirect the user's browser to the
getLoginFormPath()
URI, adding the URI of the target resource as a
query parameter of name getRedirectQueryName()
.setEncryptAlgorithm(String)
. It is also strongly
recommended toConstructor and Description |
---|
CookieAuthenticator(Context context,
boolean optional,
java.lang.String realm,
byte[] encryptSecretKey)
Constructor.
|
CookieAuthenticator(Context context,
java.lang.String realm,
byte[] encryptSecretKey)
Constructor for mandatory cookie authenticators.
|
Modifier and Type | Method and Description |
---|---|
protected void |
attemptRedirect(Request request,
Response response)
Attempts to redirect the user's browser to the URI provided in a query
parameter named by
getRedirectQueryName() . |
protected boolean |
authenticate(Request request,
Response response)
Restores credentials from the cookie named
getCookieName() if
available. |
protected int |
authenticated(Request request,
Response response)
Sets or updates the credentials cookie.
|
protected int |
beforeHandle(Request request,
Response response)
Optionally handles the login and logout actions by intercepting the HTTP
calls to the
getLoginPath() and getLogoutPath() URIs. |
void |
challenge(Response response,
boolean stale)
This method should be overridden to return a login form representation.
By default, it redirects the user's browser to the getLoginFormPath() URI, adding the URI of the target resource as
a query parameter of name getRedirectQueryName() .In case the getLoginFormPath() is not set, it calls the parent's method. |
java.lang.String |
formatCredentials(ChallengeResponse challenge)
Formats the raws credentials to store in the cookie.
|
java.lang.String |
getCookieName()
Returns the cookie name to use for the authentication credentials.
|
protected CookieSetting |
getCredentialsCookie(Request request,
Response response)
Returns the credentials cookie setting.
|
java.lang.String |
getEncryptAlgorithm()
Returns the name of the algorithm used to encrypt the log info cookie
value.
|
byte[] |
getEncryptSecretKey()
Returns the secret key for the algorithm used to encrypt the log info
cookie value.
|
java.lang.String |
getIdentifierFormName()
Returns the name of the HTML login form field containing the identifier.
|
java.lang.String |
getLoginFormPath()
Returns the URI path of the HTML login form to use to challenge the user.
|
java.lang.String |
getLoginPath()
Returns the login URI path to intercept.
|
java.lang.String |
getLogoutPath()
Returns the logout URI path to intercept.
|
int |
getMaxCookieAge()
Returns the maximum age of the log info cookie.
|
java.lang.String |
getRedirectQueryName()
Returns the name of the query parameter containing the URI to redirect
the browser to after login or logout.
|
java.lang.String |
getSecretFormName()
Returns the name of the HTML login form field containing the secret.
|
boolean |
isInterceptingLogin()
Indicates if the login requests should be intercepted.
|
boolean |
isInterceptingLogout()
Indicates if the logout requests should be intercepted.
|
protected boolean |
isLoggingIn(Request request,
Response response)
Indicates if the request is an attempt to log in and should be
intercepted.
|
protected boolean |
isLoggingOut(Request request,
Response response)
Indicates if the request is an attempt to log out and should be
intercepted.
|
protected void |
login(Request request,
Response response)
Processes the login request.
|
protected int |
logout(Request request,
Response response)
Processes the logout request.
|
protected ChallengeResponse |
parseCredentials(java.lang.String cookieValue)
Decodes the credentials stored in a cookie into a proper
ChallengeResponse object. |
void |
setCookieName(java.lang.String cookieName)
Sets the cookie name to use for the authentication credentials.
|
void |
setEncryptAlgorithm(java.lang.String secretAlgorithm)
Sets the name of the algorithm used to encrypt the log info cookie value.
|
void |
setEncryptSecretKey(byte[] secretKey)
Sets the secret key for the algorithm used to encrypt the log info cookie
value.
|
void |
setIdentifierFormName(java.lang.String loginInputName)
Sets the name of the HTML login form field containing the identifier.
|
void |
setInterceptingLogin(boolean intercepting)
Indicates if the login requests should be intercepted.
|
void |
setInterceptingLogout(boolean intercepting)
Indicates if the logout requests should be intercepted.
|
void |
setLoginFormPath(java.lang.String loginFormPath)
Sets the URI path of the HTML login form to use to challenge the user.
|
void |
setLoginPath(java.lang.String loginPath)
Sets the login URI path to intercept.
|
void |
setLogoutPath(java.lang.String logoutPath)
Sets the logout URI path to intercept.
|
void |
setMaxCookieAge(int timeout)
Sets the maximum age of the log info cookie.
|
void |
setRedirectQueryName(java.lang.String redirectQueryName)
Sets the name of the query parameter containing the URI to redirect the
browser to after login or logout.
|
void |
setSecretFormName(java.lang.String passwordInputName)
Sets the name of the HTML login form field containing the secret.
|
createChallengeRequest, forbid, getRealm, getScheme, getVerifier, isRechallenging, setRealm, setRechallenging, setVerifier
getEnroler, isMultiAuthenticating, isOptional, setEnroler, setMultiAuthenticating, setOptional, unauthenticated
afterHandle, doHandle, getNext, handle, hasNext, setNext, setNext, start, stop
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner
public CookieAuthenticator(Context context, boolean optional, java.lang.String realm, byte[] encryptSecretKey)
ChallengeScheme.HTTP_COOKIE
pseudo-scheme.context
- The parent context.optional
- Indicates if this authenticator is optional so alternative
authenticators down the chain can be attempted.realm
- The name of the security realm.encryptSecretKey
- The secret key used to encrypt the cookie value.public CookieAuthenticator(Context context, java.lang.String realm, byte[] encryptSecretKey)
context
- The parent context.realm
- The name of the security realm.encryptSecretKey
- The secret key used to encrypt the cookie value.protected void attemptRedirect(Request request, Response response)
getRedirectQueryName()
.request
- The current request.response
- The current response.protected boolean authenticate(Request request, Response response)
getCookieName()
if
available. The usual processing is the followed.authenticate
in class ChallengeAuthenticator
protected int authenticated(Request request, Response response)
authenticated
in class Authenticator
protected int beforeHandle(Request request, Response response)
getLoginPath()
and getLogoutPath()
URIs.beforeHandle
in class Authenticator
public void challenge(Response response, boolean stale)
getLoginFormPath()
URI, adding the URI of the target resource as
a query parameter of name getRedirectQueryName()
.challenge
in class ChallengeAuthenticator
public java.lang.String formatCredentials(ChallengeResponse challenge) throws java.security.GeneralSecurityException
challenge
- The challenge response to format.java.security.GeneralSecurityException
public java.lang.String getCookieName()
protected CookieSetting getCredentialsCookie(Request request, Response response)
request
- The current request.response
- The current response.public java.lang.String getEncryptAlgorithm()
public byte[] getEncryptSecretKey()
public java.lang.String getIdentifierFormName()
public java.lang.String getLoginFormPath()
public java.lang.String getLoginPath()
public java.lang.String getLogoutPath()
public int getMaxCookieAge()
CookieSetting.getMaxAge()
public java.lang.String getRedirectQueryName()
public java.lang.String getSecretFormName()
public boolean isInterceptingLogin()
public boolean isInterceptingLogout()
protected boolean isLoggingIn(Request request, Response response)
request
- The current request.response
- The current response.protected boolean isLoggingOut(Request request, Response response)
request
- The current request.response
- The current response.protected void login(Request request, Response response)
request
- The current request.response
- The current response.protected int logout(Request request, Response response)
request
- The current request.response
- The current response.protected ChallengeResponse parseCredentials(java.lang.String cookieValue)
ChallengeResponse
object.cookieValue
- The credentials to decode from cookie value.public void setCookieName(java.lang.String cookieName)
cookieName
- The cookie name to use for the authentication credentials.public void setEncryptAlgorithm(java.lang.String secretAlgorithm)
secretAlgorithm
- The name of the algorithm used to encrypt the log info cookie
value.public void setEncryptSecretKey(byte[] secretKey)
secretKey
- The secret key for the algorithm used to encrypt the log info
cookie value.public void setIdentifierFormName(java.lang.String loginInputName)
loginInputName
- The name of the HTML login form field containing the
identifier.public void setInterceptingLogin(boolean intercepting)
intercepting
- True if the login requests should be intercepted.public void setInterceptingLogout(boolean intercepting)
intercepting
- True if the logout requests should be intercepted.public void setLoginFormPath(java.lang.String loginFormPath)
loginFormPath
- The URI path of the HTML login form to use to challenge the
user.public void setLoginPath(java.lang.String loginPath)
loginPath
- The login URI path to intercept.public void setLogoutPath(java.lang.String logoutPath)
logoutPath
- The logout URI path to intercept.public void setMaxCookieAge(int timeout)
timeout
- The maximum age of the log info cookie.CookieSetting.setMaxAge(int)
public void setRedirectQueryName(java.lang.String redirectQueryName)
redirectQueryName
- The name of the query parameter containing the URI to redirect
the browser to after login or logout.public void setSecretFormName(java.lang.String passwordInputName)
passwordInputName
- The name of the HTML login form field containing the secret.Copyright © 2005-2020 Restlet.