Class Login

java.lang.Object
rife.authentication.elements.Identified
rife.authentication.elements.Login
All Implemented Interfaces:
SessionAttributes, Element

public class Login extends Identified implements SessionAttributes
Provides a login form so that the user can start a valid authentication session.

To customize the behavior of the authentication, it's the easiest to override one of the hook methods.

Since:
1.0
  • Constructor Details

    • Login

      protected Login()
      This constructor is meant to be used when extending the Login element with your custom login class.

      Don't forget to also override the `getAuthConfig()` and `getTemplate()` methods.

      Since:
      1.0
    • Login

      public Login(AuthConfig config, Template template)
      This constructor is meant to be used when the Login element is used directly as a route in your site.

      When extending this element, use the default constructor instead and override the `getAuthConfig()` and `getTemplate()` methods.

      Parameters:
      config - the auth config to use
      template - the template instance blueprint to use
      Since:
      1.0
  • Method Details

    • initializeLogin

      protected void initializeLogin(Context c)
      Hook method that is called at the start of the element's processing.
      Parameters:
      c - the element processing context
      Since:
      1.0
    • getTemplate

      protected Template getTemplate()
      Hook method that is called to create the template instance.
      Returns:
      the template to use for login
      Since:
      1.0
    • unvalidatedCredentials

      protected void unvalidatedCredentials(Template template, Credentials credentials)
      Hook method that is called on login form submission when validation of the credentials produces validation errors.
      Parameters:
      template - this authentication element's template
      credentials - the credentials object that was invalid
      Since:
      1.0
    • validatedCredentials

      protected void validatedCredentials(Credentials credentials)
      Hook method that is called on login form submission when the credentials are validated without errors
      Parameters:
      credentials - the credentials object that was valid
      Since:
      1.0
    • acceptedCredentials

      protected void acceptedCredentials(Credentials credentials)
      Hook method that is called when valid credentials have been accepted by the CredentialsManager that backs this authentication element.
      Parameters:
      credentials - the credentials object that was accepted
      Since:
      1.0
    • authenticated

      protected void authenticated(long userId)
      Hook method that is called after a new authentication session has been successfully created.
      Parameters:
      userId - the user ID of the user that was successfully authenticated
      Since:
      1.0
    • refusedCredentials

      protected void refusedCredentials(Template template, Credentials credentials)
      Hook method that is called when valid credentials have been rejected by the CredentialsManager that backs this authentication element.

      This can for example happen when the password is not correct.

      Note that there is already a default implementation of this hook method that simply adds a validation error to the credentials object. If you want to preserve this when you implement your own hook method, you need to call the super class's method in your implementation.

      Parameters:
      template - this authentication element's template
      credentials - the credentials object that was rejected
      Since:
      1.0
    • sessionCreationError

      protected void sessionCreationError(Template template, Credentials credentials)
      Hook method that is called when the SessionManager couldn't create a new authentication session of valid and accepted credentials.

      Note that there is already a default implementation of this hook method that simply adds a validation error to the credentials object. If you want to preserve this when you implement your own hook method, you need to call the super class's method in your implementation.

      Parameters:
      template - this authentication element's template
      credentials - the credentials object that was used when creating the authentication session
      Since:
      1.0
    • process

      public void process(Context c) throws Exception
      Description copied from interface: Element
      Process the provided Context with this element.
      Specified by:
      process in interface Element
      Overrides:
      process in class Identified
      Parameters:
      c - the provided request/response context
      Throws:
      Exception - when an error occurs
    • hasAttribute

      public boolean hasAttribute(String key)
      Description copied from interface: SessionAttributes
      Checks if a certain attribute is present.
      Specified by:
      hasAttribute in interface SessionAttributes
      Parameters:
      key - The key that identifies the attribute.
      Returns:
      true if the attribute was present; or

      false otherwise.

      See Also:
    • getAttribute

      public String getAttribute(String key)
      Description copied from interface: SessionAttributes
      Retrieves the value of a particular attribute.
      Specified by:
      getAttribute in interface SessionAttributes
      Parameters:
      key - The key that identifies the attribute.
      Returns:
      A String instance with the value of the requested attribute; or

      null if the attribute couldn't be found.

      See Also: