Class AuthConfig

java.lang.Object
rife.authentication.elements.AuthConfig

public class AuthConfig extends Object
Configuration class that determines how the authentication element implementations should behave. Each authenticated section usually has one 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 Details

    • DEFAULT_IDENTITY_ATTRIBUTE_NAME

      public static final String DEFAULT_IDENTITY_ATTRIBUTE_NAME
    • 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

      public static final Class<RoleUser> DEFAULT_CREDENTIALS_CLASS
  • Constructor Details

    • AuthConfig

      public AuthConfig(SessionValidator<?,?,?> sessionValidator)
      Create an AuthConfig instance for a specific SessionValidator.
      Parameters:
      sessionValidator - the session validator to use for authentication
      Since:
      1.0
      See Also:
  • Method Details

    • sessionValidator

      public AuthConfig sessionValidator(SessionValidator<?,?,?> 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

      public SessionValidator<?,?,?> sessionValidator()
      Retrieve the session validator for this config.
      Returns:
      the session validator for this config.
      Since:
      1.0
    • loginRoute

      public AuthConfig loginRoute(Route route)
      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

      public Route loginRoute()
      Retrieves the route that is used when user login is necessary.
      Returns:
      this config's user login route
      Since:
      1.0
    • landingRoute

      public AuthConfig landingRoute(Route route)
      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

      public Route 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

      public AuthConfig identityAttributeName(String name)
      Sets the name of the request attribute to use to store the instance of RoleUserIdentity 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

      public String identityAttributeName()
      Retrieves the name of the request attribute in which the RoleUserIdentity of a successfully identified user will be stored.
      Returns:
      the name of the request attribute
      Since:
      1.0
    • identityAttribute

      public RoleUserIdentity identityAttribute(Context c)
      Retrieves the RoleUserIdentity request attribute from a Context.
      Parameters:
      c - the context to look the request attribute up in
      Returns:
      the stored RoleUserIdentity; or null 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

      public AuthConfig authCookieName(String name)
      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

      public String authCookieName()
      Retrieves the name of the authentication ID cookie.
      Returns:
      the name of the authentication ID cookie.
      Since:
      1.0
    • rememberCookieName

      public AuthConfig rememberCookieName(String name)
      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

      public String rememberCookieName()
      Retrieves the name of the remember ID cookie.
      Returns:
      the name of the remember ID cookie.
      Since:
      1.0
    • rememberMaxAge

      public AuthConfig 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.

      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

      public AuthConfig allowRemember(boolean allowRemember)
      Sets whether remembering an authentication session is allowed or not.

      Defaults to DEFAULT_ALLOW_REMEMBER

      Parameters:
      allowRemember - true to allow remembering a session; or false 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; or false otherwise
      Since:
      1.0
    • enforceAuthentication

      public AuthConfig enforceAuthentication(boolean enforceAuthentication)
      Sets whether authentication should be enforced in the element.

      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; or false otherwise
      Returns:
      this config instance
      Since:
      1.0
    • enforceAuthentication

      public boolean enforceAuthentication()
      Retrieves whether authentication should be enforced in the Authenticated element.
      Returns:
      true when authentication should be enforced; or false otherwise
      Since:
      1.0
    • credentialsClass

      public AuthConfig credentialsClass(Class<? extends Credentials> credentialsClass)
      Sets the credentials class that will be used by the Login element.

      Defaults to DEFAULT_CREDENTIALS_CLASS.

      Parameters:
      credentialsClass - the crendentials class to use
      Returns:
      this config instance
      Since:
      1.0
    • credentialsClass

      public Class<? extends Credentials> credentialsClass()
      Retrieves the credentials class that will be used by the Login element.
      Returns:
      the credentials class to use
      Since:
      1.0
    • role

      public AuthConfig role(String 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; or null if no role is required
      Returns:
      this config instance
      Since:
      1.0
    • role

      public String 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

      public String generateAuthData(Context c)
      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

      public AuthConfig staticAuthData(String authData)
      Sets static authentication data to be associated with the sessions that are initiated with this AuthConfig.

      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

      public String 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