Package io.mangoo.routing.bindings
Class Authentication
java.lang.Object
io.mangoo.routing.bindings.Authentication
Convenient class for handling authentication
- Author:
- svenkubiak
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Authenticationcreate()Returns the LocalDateTime when the authentication expiresRetrieves the current subjectvoidInvalidates the authentication by sending expiring the client cookiebooleanbooleanisLogout()booleanbooleanbooleanisValid()Checks if the authentication class contains an authenticationPerforms a login by setting the authentication to the given identifier Please note, that calling validLogin is mandatory before this call!voidlogout()Performs a logout of the currently authenticated userSets remember me functionality to true, default is falserememberMe(boolean remember) Sets remember me functionality, default is falsetwoFactorAuthentication(boolean twoFactor) Sets the requirement of the two-factor authentication, default is falsebooleanuserHasLock(String username) Checks if a username is locked because of to many failed login attemptsbooleanvalidLogin(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 passwordbooleanvalidSecondFactor(String secret, String number) Checks if a given number for 2FA is valid for the given secretwithExpires(LocalDateTime expires) withSubject(String subject)
-
Constructor Details
-
Authentication
public Authentication()
-
-
Method Details
-
create
-
withExpires
-
withSubject
-
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
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
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 authenticatepassword- The clear text passwordsalt- The salt to use for hashinghash- The previously hashed password to check- Returns:
- True if the new hashed password matches the hash, false otherwise
-
login
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
Sets remember me functionality, default is false- Parameters:
remember- The state of remember to set- Returns:
- Authentication object
-
rememberMe
Sets remember me functionality to true, default is false- Returns:
- Authentication object
-
twoFactorAuthentication
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
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
Checks if a given number for 2FA is valid for the given secret- Parameters:
secret- The plaintext secret to use for checkingnumber- 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()
-