Class Authentication

java.lang.Object
io.mangoo.routing.bindings.Authentication

public class Authentication extends Object
Convenient class for handling authentication
Author:
svenkubiak
  • Constructor Details

    • Authentication

      public Authentication()
  • Method Details

    • create

      public static Authentication create()
    • withExpires

      public Authentication withExpires(LocalDateTime expires)
    • withSubject

      public Authentication withSubject(String subject)
    • getSubject

      public String getSubject()
      Retrieves the current subject
      Returns:
      The subject of the current authentication or null if not set
    • invalidate

      public void invalidate()
      Invalidates the authentication by sending expiring the client cookie
    • getExpires

      public LocalDateTime getExpires()
      Returns the LocalDateTime when the authentication expires
      Returns:
      A LocalDateTime object or null if not set
    • isLogout

      public boolean isLogout()
      Returns:
      True if the user wants to log out, false otherwise
    • isRememberMe

      public boolean isRememberMe()
      Returns:
      True if the user wants to stay logged in, false otherwise
    • isTwoFactor

      public boolean isTwoFactor()
      Returns:
      True if two-factor authentication is enabled for this user
    • validLogin

      public boolean validLogin(String identifier, String password, String salt, String hash)
      Creates a hashed value of a given clear text password and checks if the value matches a given, already hashed password
      Parameters:
      identifier - The identifier to authenticate
      password - The clear text password
      salt - The salt to use for hashing
      hash - The previously hashed password to check
      Returns:
      True if the new hashed password matches the hash, false otherwise
    • login

      public Authentication login(String subject)
      Performs a login by setting the authentication to the given identifier Please note, that calling validLogin is mandatory before this call!
      Parameters:
      subject - The subject to login
      Returns:
      Authentication object
    • rememberMe

      public Authentication rememberMe(boolean remember)
      Sets remember me functionality, default is false
      Parameters:
      remember - The state of remember to set
      Returns:
      Authentication object
    • rememberMe

      public Authentication rememberMe()
      Sets remember me functionality to true, default is false
      Returns:
      Authentication object
    • twoFactorAuthentication

      public Authentication twoFactorAuthentication(boolean twoFactor)
      Sets the requirement of the two-factor authentication, default is false
      Parameters:
      twoFactor - True for enabling two-factor authentication, false otherwise
      Returns:
      Authentication object
    • userHasLock

      public boolean userHasLock(String username)
      Checks if a username is locked because of to many failed login attempts
      Parameters:
      username - The username to check
      Returns:
      true if the user has a lock, false otherwise
    • validSecondFactor

      public boolean validSecondFactor(String secret, String number)
      Checks if a given number for 2FA is valid for the given secret
      Parameters:
      secret - The plaintext secret to use for checking
      number - The number entered by the user
      Returns:
      True if number is valid, false otherwise
    • logout

      public void logout()
      Performs a logout of the currently authenticated user
    • isValid

      public boolean isValid()
      Checks if the authentication class contains an authentication
      Returns:
      True if authentication contains an authentication, false otherwise
    • isInvalid

      public boolean isInvalid()