Class User
This class represents a user. It is a value class that stores only the user id and a reference
to an AbstractUserDatabase
to 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 AbstractUserDatabase
for a discussion.
- See Also:
-
Constructor Summary
ConstructorDescriptionUser()
Default constructor.User
(String id, AbstractUserDatabase userDatabase) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAuthToken
(Token token) Adds an authentication token.void
addIdentity
(String provider, String identity) Adds an identity.void
Clears the email token.boolean
Indicates whether some other object is "equal to" this one.Returns the user database.getEmail()
Returns the email address.Returns the email token.Returns the email token role.int
Returns the number of consecutive unsuccessful login attempts.getId()
Returns the user id.getIdentity
(String provider) Returns an identity.Returns the last login attempt.Returns the password.Returns the account status.Returns the unverified email address.boolean
isValid()
Returns whether the user is valid.void
removeAuthToken
(String token) Removes an authentication token.void
removeIdentity
(String provider) Removes an identity.void
setAuthenticated
(boolean success) Logs the result of an authentication attempt.void
Sets the email address.void
setEmailToken
(Token token, EmailTokenRole role) Sets an email token.void
setIdentity
(String provider, String identity) Sets an identity.void
setPassword
(PasswordHash password) Sets a password.void
setStatus
(AccountStatus status) Sets the account status.void
setUnverifiedEmail
(String address) Sets the unverified email address.int
updateAuthToken
(String hash, String newHash) Updates an authentication token.
-
Constructor Details
-
User
public User()Default constructor.Creates an invalid user.
- See Also:
-
User
Constructor.Creates a user with id
id
, and whose information is stored in thedatabase
.
-
-
Method Details
-
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
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
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:
-
getIdentity
Returns an identity. -
addIdentity
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
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
Removes an identity. -
setPassword
Sets a password.This also clears the email token.
-
getPassword
Returns the password. -
setEmail
Sets the email address. -
getEmail
Returns the email address.- See Also:
-
setUnverifiedEmail
Sets the unverified email address. -
getUnverifiedEmail
Returns the unverified email address. -
getStatus
Returns the account status. -
setStatus
Sets the account status. -
getEmailToken
Returns the email token. -
getEmailTokenRole
Returns the email token role. -
setEmailToken
Sets an email token. -
clearEmailToken
public void clearEmailToken()Clears the email token. -
addAuthToken
Adds an authentication token. -
removeAuthToken
Removes an authentication token. -
updateAuthToken
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.
-
getFailedLoginAttempts
public int getFailedLoginAttempts()Returns the number of consecutive unsuccessful login attempts.- See Also:
-
getLastLoginAttempt
Returns the last login attempt.- See Also:
-