Class UserDatabase
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.auth.AbstractUserDatabase
AbstractUserDatabase.Transaction
-
Constructor Summary
ConstructorDescriptionUserDatabase
(javax.persistence.EntityManager entityManager) ConstructorUserDatabase
(javax.persistence.EntityManager entityManager, AuthService authService) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAuthToken
(User user, Token token) Adds an authentication token to a user.void
addIdentity
(User user, String provider, String identity) Adds an identify for the user.findWithAuthToken
(String hash) Finds a user with an authentication token.findWithEmail
(String address) Finds a user with a given email address.findWithEmailToken
(String token) Finds a user with a given email token.findWithId
(String id) Finds a user with a given id.findWithIdentity
(String provider, String identity) Finds a user with a given identity.Returns a user's email address.getEmailToken
(User user) Returns an email token.getEmailTokenRole
(User user) Returns the role of the current email token.int
getFailedLoginAttempts
(User user) Returns the number of consecutive authentication failures.getIdentity
(User user, String provider) Returns a user identity.getLastLoginAttempt
(User user) Returns the time of the last login.getPassword
(User user) Returns a user password.Returns the status for a user.getUnverifiedEmail
(User user) Returns a user's unverified email address.Registers a new user.void
removeAuthToken
(User user, String hash) Deletes an authentication token.void
removeIdentity
(User user, String provider) Removes a user identity.boolean
Sets a user's email address.void
setEmailToken
(User user, Token token, EmailTokenRole role) Sets a new email token for a user.void
setFailedLoginAttempts
(User user, int count) Sets the number of consecutive authentication failures.void
setLastLoginAttempt
(User user, WDate d) Sets the time of the last login attempt.void
setPassword
(User user, PasswordHash password) Sets a new user password.void
setUnverifiedEmail
(User user, String address) Sets a user's unverified email address.Creates a new database transaction.Methods inherited from class eu.webtoolkit.jwt.auth.AbstractUserDatabase
deleteUser, idpClientAdd, idpClientAuthMethod, idpClientConfidential, idpClientFindWithId, idpClientId, idpClientRedirectUris, idpClientSecret, idpJsonClaim, idpTokenAdd, idpTokenExpirationTime, idpTokenFindWithValue, idpTokenOAuthClient, idpTokenPurpose, idpTokenRedirectUri, idpTokenRemove, idpTokenScope, idpTokenUser, idpTokenValue, idpVerifySecret, setIdentity, setStatus, updateAuthToken
-
Constructor Details
-
UserDatabase
public UserDatabase(javax.persistence.EntityManager entityManager) Constructor -
UserDatabase
Constructor
-
-
Method Details
-
startTransaction
Description copied from class:AbstractUserDatabase
Creates a new database transaction.If the underlying database does not support transactions, you can return
null
.Ownership of the transaction is transferred, and the transaction must be deleted after it has been committed or rolled back.
The default implementation returns
null
(no transaction support).- Overrides:
startTransaction
in classAbstractUserDatabase
-
find
-
find
-
findWithId
Description copied from class:AbstractUserDatabase
Finds a user with a given id.The id uniquely identifies a user.
This should find the user with the given
id
, or return an invalid user if no user with that id exists.- Specified by:
findWithId
in classAbstractUserDatabase
-
findWithIdentity
Description copied from class:AbstractUserDatabase
Finds a user with a given identity.The
identity
uniquely identifies the user by theprovider
.This should find the user with the given
identity
, or return an invalid user if no user with that identity exists.- Specified by:
findWithIdentity
in classAbstractUserDatabase
-
getIdentity
Description copied from class:AbstractUserDatabase
Returns a user identity.Returns a user identity for the given provider, or an empty string if the user has no identitfy set for this provider.
- Specified by:
getIdentity
in classAbstractUserDatabase
- See Also:
-
removeIdentity
Description copied from class:AbstractUserDatabase
Removes a user identity.This removes all identities of a
provider
from theuser
.- Specified by:
removeIdentity
in classAbstractUserDatabase
- See Also:
-
registerNew
Description copied from class:AbstractUserDatabase
Registers a new user.This adds a new user.
This method is only used by view classes involved with registration (
RegistrationWidget
).- Overrides:
registerNew
in classAbstractUserDatabase
-
getStatus
Description copied from class:AbstractUserDatabase
Returns the status for a user.If there is support for suspending accounts, then this method may be implemented to return whether a user account is disabled.
The default implementation always returns
AccountStatus.Normal
.- Overrides:
getStatus
in classAbstractUserDatabase
-
setPassword
Description copied from class:AbstractUserDatabase
Sets a new user password.This updates the password for a user.
This is used only by
PasswordService
.- Overrides:
setPassword
in classAbstractUserDatabase
-
getPassword
Description copied from class:AbstractUserDatabase
Returns a user password.This returns the stored password for a user, or a default constructed password hash if the user does not yet have password credentials.
This is used only by
PasswordService
.- Overrides:
getPassword
in classAbstractUserDatabase
-
addIdentity
Description copied from class:AbstractUserDatabase
Adds an identify for the user.This adds an identity to the user.
You are free to support only one identity per user, e.g. if you only use password-based authentication. But you may also want to support more than one if you allow the user to login using multiple methods (e.g. name/password, OAuth from one or more providers, LDAP, ...).
- Specified by:
addIdentity
in classAbstractUserDatabase
-
setEmail
Description copied from class:AbstractUserDatabase
Sets a user's email address.This is used only when email verification is enabled, or as a result of a 3rd party
Identity
Provider based registration process, if the provider also provides email address information with the identiy.Returns whether the user's email address could be set. This may fail when there is already a user registered that email address.
- Overrides:
setEmail
in classAbstractUserDatabase
- See Also:
-
getEmail
Description copied from class:AbstractUserDatabase
Returns a user's email address.This may be an unverified or verified email address, depending on whether email address verification is enabled in the model classes.
This is an optional method, and currently not used by any of the included models or views.
- Overrides:
getEmail
in classAbstractUserDatabase
-
setUnverifiedEmail
Description copied from class:AbstractUserDatabase
Sets a user's unverified email address.This is only used when email verification is enabled. It holds the currently unverified email address, while a mail is being sent for the user to confirm this email address.
- Overrides:
setUnverifiedEmail
in classAbstractUserDatabase
-
getUnverifiedEmail
Description copied from class:AbstractUserDatabase
Returns a user's unverified email address.This is an optional method, and currently not used by any of the included models or views.
- Overrides:
getUnverifiedEmail
in classAbstractUserDatabase
-
findWithEmail
Description copied from class:AbstractUserDatabase
Finds a user with a given email address.This is used to verify that a email addresses are unique, and to implement lost password functionality.
- Overrides:
findWithEmail
in classAbstractUserDatabase
-
setEmailToken
Description copied from class:AbstractUserDatabase
Sets a new email token for a user.This is only used when email verification is enabled or for lost password functionality.
- Overrides:
setEmailToken
in classAbstractUserDatabase
-
getEmailToken
Description copied from class:AbstractUserDatabase
Returns an email token.This is only used when email verification is enabled and for lost password functionality. It should return the email token previously set with
setEmailToken()
- Overrides:
getEmailToken
in classAbstractUserDatabase
-
getEmailTokenRole
Description copied from class:AbstractUserDatabase
Returns the role of the current email token.This is only used when email verification is enabled or for lost password functionality. It should return the role previously set with setEailToken().
- Overrides:
getEmailTokenRole
in classAbstractUserDatabase
-
findWithEmailToken
Description copied from class:AbstractUserDatabase
Finds a user with a given email token.This is only used when email verification is enabled or for lost password functionality.
- Overrides:
findWithEmailToken
in classAbstractUserDatabase
-
addAuthToken
Description copied from class:AbstractUserDatabase
Adds an authentication token to a user.Unless you want a user to only have remember-me support from a single computer at a time, you should support multiple authentication tokens per user.
- Overrides:
addAuthToken
in classAbstractUserDatabase
-
removeAuthToken
Description copied from class:AbstractUserDatabase
Deletes an authentication token.Deletes an authentication token previously added with
addAuthToken()
- Overrides:
removeAuthToken
in classAbstractUserDatabase
-
findWithAuthToken
Description copied from class:AbstractUserDatabase
Finds a user with an authentication token.Returns a user with an authentication token.
This should find the user associated with a particular token hash, or return an invalid user if no user with that token hash exists.
- Overrides:
findWithAuthToken
in classAbstractUserDatabase
-
setFailedLoginAttempts
Description copied from class:AbstractUserDatabase
Sets the number of consecutive authentication failures.This sets the number of consecutive authentication failures since the last valid login.
This is used by the throttling logic to determine how much time a user needs to wait before he can do a new login attempt.
- Overrides:
setFailedLoginAttempts
in classAbstractUserDatabase
-
getFailedLoginAttempts
Description copied from class:AbstractUserDatabase
Returns the number of consecutive authentication failures.- Overrides:
getFailedLoginAttempts
in classAbstractUserDatabase
-
setLastLoginAttempt
Description copied from class:AbstractUserDatabase
Sets the time of the last login attempt.This sets the time at which the user attempted to login.
- Overrides:
setLastLoginAttempt
in classAbstractUserDatabase
-
getLastLoginAttempt
Description copied from class:AbstractUserDatabase
Returns the time of the last login.- Overrides:
getLastLoginAttempt
in classAbstractUserDatabase
- See Also:
-