Class User
- java.lang.Object
-
- eu.webtoolkit.jwt.auth.User
-
public class User extends java.lang.ObjectA user.This class represents a user. It is a value class that stores only the user id and a reference to an
AbstractUserDatabaseto access its properties.An object can point to a valid user, or be invalid. Invalid users are typically used as return value for database queries which did not match with an existing user.
Not all methods are valid or applicable to your authentication system. See
AbstractUserDatabasefor a discussion.- See Also:
AbstractUserDatabase
-
-
Constructor Summary
Constructors Constructor Description User()Default constructor.User(java.lang.String id, AbstractUserDatabase userDatabase)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAuthToken(Token token)Adds an authentication token.voidaddIdentity(java.lang.String provider, java.lang.String identity)Adds an identity.voidclearEmailToken()Clears the email token.booleanequals(User other)Indicates whether some other object is "equal to" this one.AbstractUserDatabasegetDatabase()Returns the user database.java.lang.StringgetEmail()Returns the email address.TokengetEmailToken()Returns the email token.EmailTokenRolegetEmailTokenRole()Returns the email token role.intgetFailedLoginAttempts()Returns the number of consecutive unsuccessful login attempts.java.lang.StringgetId()Returns the user id.java.lang.StringgetIdentity(java.lang.String provider)Returns an identity.WDategetLastLoginAttempt()Returns the last login attempt.PasswordHashgetPassword()Returns the password.AccountStatusgetStatus()Returns the account status.java.lang.StringgetUnverifiedEmail()Returns the unverified email address.booleanisValid()Returns whether the user is valid.voidremoveAuthToken(java.lang.String token)Removes an authentication token.voidremoveIdentity(java.lang.String provider)Removes an identity.voidsetAuthenticated(boolean success)Logs the result of an authentication attempt.voidsetEmail(java.lang.String address)Sets the email address.voidsetEmailToken(Token token, EmailTokenRole role)Sets an email token.voidsetIdentity(java.lang.String provider, java.lang.String identity)Sets an identity.voidsetPassword(PasswordHash password)Sets a password.voidsetStatus(AccountStatus status)Sets the account status.voidsetUnverifiedEmail(java.lang.String address)Sets the unverified email address.intupdateAuthToken(java.lang.String hash, java.lang.String newHash)Updates an authentication token.
-
-
-
Constructor Detail
-
User
public User()
Default constructor.Creates an invalid user.
- See Also:
isValid()
-
User
public User(java.lang.String id, AbstractUserDatabase userDatabase)Constructor.Creates a user with id
id, and whose information is stored in thedatabase.
-
-
Method Detail
-
getDatabase
public AbstractUserDatabase getDatabase()
Returns the user database.This returns the user database passed in the constructor, or 0 if the user is invalid, and was constructed using the default constructor.
-
equals
public boolean equals(User other)
Indicates whether some other object is "equal to" this one.Two users are equal if they have the same identity and the same database.
-
isValid
public boolean isValid()
Returns whether the user is valid.A invalid user is a sentinel value returned by methods that query the database but could not identify a matching user.
-
getId
public java.lang.String getId()
Returns the user id.This returns the id that uniquely identifies the user, and acts as a "primary key" to obtain other information for the user in the database.
- See Also:
AbstractUserDatabase
-
getIdentity
public java.lang.String getIdentity(java.lang.String provider)
Returns an identity.
-
addIdentity
public void addIdentity(java.lang.String provider, java.lang.String identity)Adds an identity.Depending on whether the database supports multiple identities per provider, this may change (like
setIdentity()), or add another identity to the user. For some identity providers (e.g. a 3rd party identity provider), it may be sensible to have more than one identity of the same provider for a single user (e.g. multiple email accounts managed by the same provider, that in fact identify the same user).
-
setIdentity
public void setIdentity(java.lang.String provider, java.lang.String identity)Sets an identity.Unlike
addIdentity()this overrides any other identity of the given provider, in case the underlying database supports multiple identities per user.
-
removeIdentity
public void removeIdentity(java.lang.String provider)
Removes an identity.
-
setPassword
public void setPassword(PasswordHash password)
Sets a password.This also clears the email token.
-
getPassword
public PasswordHash getPassword()
Returns the password.
-
setEmail
public void setEmail(java.lang.String address)
Sets the email address.
-
getEmail
public java.lang.String getEmail()
Returns the email address.- See Also:
AbstractUserDatabase.getEmail(User user)
-
setUnverifiedEmail
public void setUnverifiedEmail(java.lang.String address)
Sets the unverified email address.
-
getUnverifiedEmail
public java.lang.String getUnverifiedEmail()
Returns the unverified email address.
-
getStatus
public AccountStatus getStatus()
Returns the account status.
-
setStatus
public void setStatus(AccountStatus status)
Sets the account status.
-
getEmailToken
public Token getEmailToken()
Returns the email token.
-
getEmailTokenRole
public EmailTokenRole getEmailTokenRole()
Returns the email token role.
-
setEmailToken
public void setEmailToken(Token token, EmailTokenRole role)
Sets an email token.
-
clearEmailToken
public void clearEmailToken()
Clears the email token.
-
addAuthToken
public void addAuthToken(Token token)
Adds an authentication token.
-
removeAuthToken
public void removeAuthToken(java.lang.String token)
Removes an authentication token.
-
updateAuthToken
public int updateAuthToken(java.lang.String hash, java.lang.String newHash)Updates an authentication token.
-
setAuthenticated
public void setAuthenticated(boolean success)
Logs the result of an authentication attempt.This changes the number of failed login attempts, and stores the current date as the last login attempt time.
- See Also:
getFailedLoginAttempts(),getLastLoginAttempt()
-
getFailedLoginAttempts
public int getFailedLoginAttempts()
Returns the number of consecutive unsuccessful login attempts.- See Also:
setAuthenticated(boolean success)
-
getLastLoginAttempt
public WDate getLastLoginAttempt()
Returns the last login attempt.- See Also:
setAuthenticated(boolean success)
-
-