Class AuthConfig
AuthConfig
instance
that is shared in order to agree upon how to work together for a coherent authentication
flow.
Most of the configuration options have defaults, except for loginRoute
and
landingRoute
. Without specifying those two routes, the authentication system
will not work properly.
- Since:
- 1.0
-
Field Summary
-
Constructor Summary
ConstructorDescriptionAuthConfig
(SessionValidator<?, ?, ?> sessionValidator) Create anAuthConfig
instance for a specificSessionValidator
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Retrieves whether an authentication session can be remembered.allowRemember
(boolean allowRemember) Sets whether remembering an authentication session is allowed or not.Retrieves the name of the authentication ID cookie.authCookieName
(String name) Sets the name of the cookie to use for the authentication ID.Class<? extends Credentials>
Retrieves the credentials class that will be used by theLogin
element.credentialsClass
(Class<? extends Credentials> credentialsClass) Sets the credentials class that will be used by theLogin
element.boolean
Retrieves whether authentication should be enforced in theAuthenticated
element.enforceAuthentication
(boolean enforceAuthentication) Sets whether authentication should be enforced in theelement
.Generate data that will be associated with each authentication session.Retrieves theRoleUserIdentity
request attribute from aContext
.Retrieves the name of the request attribute in which theRoleUserIdentity
of a successfully identified user will be stored.identityAttributeName
(String name) Sets the name of the request attribute to use to store the instance ofRoleUserIdentity
when a user was successfully identified.Retrieves the route that is used as the landing page when login is successful.landingRoute
(Route route) Sets the route that should be used as the landing page when login is successful.Retrieves the route that is used when user login is necessary.loginRoute
(Route route) Sets the route that should be used when user login is necessary.Retrieves the name of the remember ID cookie.rememberCookieName
(String name) Sets the name of the cookie to use for the remember ID.int
Retrieves the maximum age the remember cookie can have.rememberMaxAge
(int maxAge) Sets the maximum age the remember cookie can have, when exceeded the full login logic will have to be used again to authenticate a user.role()
Retrieves the role that is expected for authentication.Sets the role that the user is expecting to be in when validating the credentials.SessionValidator<?,
?, ?> Retrieve the session validator for this config.sessionValidator
(SessionValidator<?, ?, ?> sessionValidator) Sets the session validator for this config.Retrieves the static authentication data that will be associated with this config's authentication sessions.staticAuthData
(String authData) Sets static authentication data to be associated with the sessions that are initiated with thisAuthConfig
.
-
Field Details
-
DEFAULT_IDENTITY_ATTRIBUTE_NAME
-
DEFAULT_AUTH_COOKIE_NAME
- See Also:
-
DEFAULT_REMEMBER_COOKIE_NAME
- See Also:
-
DEFAULT_REMEMBER_MAX_AGE
public static final int DEFAULT_REMEMBER_MAX_AGE- See Also:
-
DEFAULT_ALLOW_REMEMBER
public static final boolean DEFAULT_ALLOW_REMEMBER- See Also:
-
DEFAULT_ENFORCE_AUTHENTICATION
public static final boolean DEFAULT_ENFORCE_AUTHENTICATION- See Also:
-
DEFAULT_CREDENTIALS_CLASS
-
-
Constructor Details
-
AuthConfig
Create anAuthConfig
instance for a specificSessionValidator
.- Parameters:
sessionValidator
- the session validator to use for authentication- Since:
- 1.0
- See Also:
-
-
Method Details
-
sessionValidator
Sets the session validator for this config.- Parameters:
sessionValidator
- the session validator to use.- Returns:
- the instance of this config
- Since:
- 1.0
-
sessionValidator
Retrieve the session validator for this config.- Returns:
- the session validator for this config.
- Since:
- 1.0
-
loginRoute
Sets the route that should be used when user login is necessary.- Parameters:
route
- the user login route to use- Returns:
- this config instance
- Since:
- 1.0
-
loginRoute
Retrieves the route that is used when user login is necessary.- Returns:
- this config's user login route
- Since:
- 1.0
-
landingRoute
Sets the route that should be used as the landing page when login is successful.- Parameters:
route
- the landing route to use- Returns:
- this config instance
- Since:
- 1.0
-
landingRoute
Retrieves the route that is used as the landing page when login is successful.- Returns:
- this config's login landing route
- Since:
- 1.0
-
identityAttributeName
Sets the name of the request attribute to use to store the instance ofRoleUserIdentity
when a user was successfully identified.Defaults to
DEFAULT_IDENTITY_ATTRIBUTE_NAME
.- Parameters:
name
- the name of the request attribute to use- Returns:
- this config instance since 1.0
-
identityAttributeName
Retrieves the name of the request attribute in which theRoleUserIdentity
of a successfully identified user will be stored.- Returns:
- the name of the request attribute
- Since:
- 1.0
-
identityAttribute
Retrieves theRoleUserIdentity
request attribute from aContext
.- Parameters:
c
- the context to look the request attribute up in- Returns:
- the stored
RoleUserIdentity
; ornull
if the context doesn't contain an identity with that attribute name, or if no user is identified in this request. - Since:
- 1.0
-
authCookieName
Sets the name of the cookie to use for the authentication ID.Defaults to
DEFAULT_AUTH_COOKIE_NAME
.- Parameters:
name
- the authentication ID cookie name- Returns:
- this config instance
- Since:
- 1.0
-
authCookieName
Retrieves the name of the authentication ID cookie.- Returns:
- the name of the authentication ID cookie.
- Since:
- 1.0
-
rememberCookieName
Sets the name of the cookie to use for the remember ID.Defaults to
DEFAULT_REMEMBER_COOKIE_NAME
.- Parameters:
name
- the remember ID cookie name- Returns:
- this config instance
- Since:
- 1.0
-
rememberCookieName
Retrieves the name of the remember ID cookie.- Returns:
- the name of the remember ID cookie.
- Since:
- 1.0
-
rememberMaxAge
Sets the maximum age the remember cookie can have, when exceeded the full login logic will have to be used again to authenticate a user.Defaults to
DEFAULT_REMEMBER_MAX_AGE
- Parameters:
maxAge
- the maximum age in seconds- Returns:
- this config instance
- Since:
- 1.0
-
rememberMaxAge
public int rememberMaxAge()Retrieves the maximum age the remember cookie can have.- Returns:
- the maximum age in seconds
- Since:
- 1.0
-
allowRemember
Sets whether remembering an authentication session is allowed or not.Defaults to
DEFAULT_ALLOW_REMEMBER
- Parameters:
allowRemember
-true
to allow remembering a session; orfalse
of remembering a session is prohibited- Returns:
- this config instance
- Since:
- 1.0
-
allowRemember
public boolean allowRemember()Retrieves whether an authentication session can be remembered.- Returns:
true
when the session can be remembered; orfalse
otherwise- Since:
- 1.0
-
enforceAuthentication
Sets whether authentication should be enforced in theelement
.When authentication is enforced, the client will be redirected to the login page when no valid authentication session could be found.
Defaults to
DEFAULT_ENFORCE_AUTHENTICATION
.- Parameters:
enforceAuthentication
-true
to enforce authentication; orfalse
otherwise- Returns:
- this config instance
- Since:
- 1.0
-
enforceAuthentication
public boolean enforceAuthentication()Retrieves whether authentication should be enforced in theAuthenticated
element.- Returns:
true
when authentication should be enforced; orfalse
otherwise- Since:
- 1.0
-
credentialsClass
Sets the credentials class that will be used by theLogin
element.Defaults to
DEFAULT_CREDENTIALS_CLASS
.- Parameters:
credentialsClass
- the crendentials class to use- Returns:
- this config instance
- Since:
- 1.0
-
credentialsClass
Retrieves the credentials class that will be used by theLogin
element.- Returns:
- the credentials class to use
- Since:
- 1.0
-
role
Sets the role that the user is expecting to be in when validating the credentials.This only works when the credentials class implements the
RoleUserCredentials
interface.Defaults to
null
.- Parameters:
role
- the role that is expected for authentication; ornull
if no role is required- Returns:
- this config instance
- Since:
- 1.0
-
role
Retrieves the role that is expected for authentication.- Returns:
- the role that is expected for authentication; or
null
if no role is required - Since:
- 1.0
-
generateAuthData
Generate data that will be associated with each authentication session.By default, this will return the remote address of the client.
This data can be used to only allow authentication sessions to be retrieved when the associated data corresponds, for instance to only limit the session to the IP address that it was initiated from. This feature is by default disabled, but it can be enabled in
RifeConfig.AuthenticationConfig.setSessionRestrictAuthData(boolean)
.- Parameters:
c
- the current element processing context- Returns:
- the associated data for an authentication session
- Since:
- 1.0
-
staticAuthData
Sets static authentication data to be associated with the sessions that are initiated with thisAuthConfig
.When setting static data, it will be returned by
generateAuthData(rife.engine.Context)
instead of the client's IP address.Setting different static authentication data in authentication configs that share the same
SessionValidator
, makes it possible to store different types of sessions in the same structure with it being possible for the authentication IDs to be interchanged- Parameters:
authData
- the static authentication data to associated with sessions- Returns:
- this config instance
- Since:
- 1.0
-
staticAuthData
Retrieves the static authentication data that will be associated with this config's authentication sessions.- Returns:
- the static authentication data for this config; or
null
if no static authentication data is set up - Since:
- 1.0
-