Interface AuthenticationInterface


public interface AuthenticationInterface

The methods used during the Login and Logout. These methods must be implemented in the login and logout implementation Any custom implementation can be specified. This implementation must be passed, during the login, as a parameter of the JBStrap.loginUser(Client, CurrentUser) method. During the logout operation, the JBStrap.logoutUser(Client) method doesn't need the implementation passed.

During the login, the logged in user must be returned, which will then be placed in the Client object. Later, when requesting users from the client, this is the user that will be returned. The CurrentUser object can be expanded, if more data needs to be stored.

During the logout the logged in user will be removed from the Client. Thus, the user won't be accessible through the client. After logging out, the page specified in the ENTRY_POINT parameter will be displayed, this cannot be overwritten.

Since:
4.0
Author:
JBStrap
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    initUser(String username, String password)
    Checks the user's data, and creates the POJO class that represents the user.
    default boolean
    logout(Client client, CurrentUser currentUser)
    Handles the user logout event.
    default void
    setTargetPageId(Client client, String pageId)
    Overwrites which page will be opened after a successful login.
  • Method Details

    • initUser

      CurrentUser initUser(String username, String password)

      Checks the user's data, and creates the POJO class that represents the user.

      In this method, the authentication of the username and password must be implemented. If successful, a CurrentUser object must be created, that has to have the data of the logged in user. The method must return this user object. If either the username or password are incorrect (the user couldn't sign in), the method must return with a null value.

      Parameters:
      username - The username
      password - The user's password
      Returns:
      The created user object if the user signs in, or null, if the login was unsuccessful.
      See Also:
    • logout

      default boolean logout(Client client, CurrentUser currentUser)

      Handles the user logout event.

      When the user logs out, this method is called. If this is not implemented, then the user will be logged out automatically. If we want to log the logouts, or want to add additional requirements for the logout procedure, it can be implemented here. If the method returns with true, the user has logged out successfully. If it returns with false, the procedure was interrupted, and the user did not log out.

      Parameters:
      client - The client instance, from which the user wants to log out of.
      currentUser - The POJO class, that represents the user who wants to log out.
      Returns:
      If true, the logout procedure can continue, if false, it is interrupted, and the user will stay logged in.
      See Also:
    • setTargetPageId

      default void setTargetPageId(Client client, String pageId)
      Overwrites which page will be opened after a successful login. By default, the page specified in JBStrapParamType.ENTRY_POINT will be used.
      Parameters:
      client - The client object
      pageId - The ID of the page where the user will be directed to. If specified as null, the default page will be used.
      Throws:
      NullPointerException - If the client is null or if the page specified by its ID is not found.