Class User
java.lang.Object
com.erudika.para.core.User
- All Implemented Interfaces:
Linkable, ParaObject, Votable, Serializable
The core user object. Stores information about users.
- Author:
- Alex Bogdanovski [[email protected]]
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSimple groups enum.static enumSimple user roles enum.Nested classes/interfaces inherited from interface Votable
Votable.VoteValue -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanactivateWithEmailToken(String token) Activates a user if a given token matches the one stored.voidattachIdentifier(String identifier) Attaches a new identifier to this user.booleancanModify(ParaObject obj) Note: this method assumes that child objects can be modified by their parents.countChildren(String type) Counts the number of children of a certain type.countLinks(String type2) Counts the number of links to other objects of a certain type.create()Stores this object in the data store.voiddelete()Deletes the object permanently by removing it from the data store.voiddeleteChildren(String type) Deletes all children of a certain type.voiddetachIdentifier(String identifier) Detaches a secondary identifier which is not already used by this user.booleanReturns true if this object is equal to another.booleanexists()Returns true if the object exists in the database.<P extends ParaObject>
List<P> findChildren(String type, String query, Pager... pager) Finds children of a certain type that match a specific query.<P extends ParaObject>
List<P> findLinkedObjects(String type, String field, String query, Pager... pager) Finds linked objects of a certain type that match a specific field and query.Generates a new email confirmation token.final StringGenerates a new password reset token.Returns true if this account is active.getAppid()Returns the app identifier.Returns true if the object is cached.<P extends ParaObject>
List<P> getChildren(String type, Pager... pager) Returns a list of children of a certain type.<P extends ParaObject>
List<P> getChildren(String type, String field, String term, Pager... pager) Returns a list of children of a certain type that match a specific field and term.Returns the creator ID.The user's currency preference.getEmail()The user's email.Returns the security groups for this user.final StringgetId()Returns the object ID.Returns the main identifier for this user.Returns the name of the identity provider.Used for storing the access token from an OpenID Connect/OAuth 2.0 identity provider.Returns the JWT payload for the access token coming from the IDP.Used for storing the ID token from an OpenID Connect/OAuth 2.0 identity provider.Returns the JWT payload for the ID token coming from the IDP.Stores the refresh token from the identity provider.Returns true if the object is indexed.<P extends ParaObject>
List<P> getLinkedObjects(String type, Pager... pager) Returns a list of linked objects of a certain type.Returns a list of links to other objects of a certain type.final StringgetName()Returns the object name.Returns the object URI.Returns the parent ID.The password.The profile picture URL.Returns the plural form of the object type.Returns true if the object is stored in the database.getTags()Returns the tags.Returns the timestamp.Token secret - used for generating JWT tokens.getTwoFA()Returns true if 2FA is enabled.Returns the hashed backup key (shown only once).Returns the 2FA secret key.final StringgetType()Returns the object type.Returns the updated timestamp.Returns the version of the object.getVotes()Returns the number of votes.inthashCode()Returns the hash code for this object.booleanValidates the identifier property value.booleanisAdmin()Checks for admin rights.booleanIs the main identifier a Amazon account id.booleanIs the main identifier a Facebook id.booleanIs the main identifier a GitHub id.booleanIs the main identifier a Google+ id.booleanIs the main identifier a LDAP account.booleanisLinked(ParaObject toObj) Returns true if the object is linked to another object.booleanReturns true if the object is linked to another object of a certain type and ID.booleanIs the main identifier a LinkedIn id.booleanIs the main identifier a Mattermost account id.booleanIs the main identifier a Microsoft/Windows account id.booleanChecks for moderator rights.booleanIs the main identifier from a generic OAuth 2.0/OpenID Connect provider.booleanIs the main identifier a custom SSO account.booleanIs the main identifier a SAML account.booleanIs the main identifier a Slack account id.booleanIs the main identifier a Twitter id.final booleanValidates a token sent for email confirmation.final booleanisValidPasswordResetToken(String token) Validates a token sent via email for password reset.Links the object to another object of a certain type and ID.static final booleanChecks if a user has entered the correct password.static final UserReturns a user object for a given identifier.final booleanresetPassword(String token, String newpass) Changes the user password permanently.voidGenerates a new token secret.voidSets the account active.voidSets the app identifier.voidSets the cached flag.voidsetCreatorid(String creatorid) Sets the creator ID.voidsetCurrency(String currency) Sets a preferred currency.voidSets the email.voidSets the security groups for this user.final voidSets the object ID.voidsetIdentifier(String identifier) Sets the main identifier.voidsetIdpAccessToken(String idpAccessToken) Sets the IDP access token.voidsetIdpIdToken(String idpIdToken) Sets the IDP ID token.voidsetIdpRefreshToken(String idpRefreshToken) Sets the refresh token.voidsetIndexed(Boolean indexed) Sets the indexed flag.final voidSets the object name.voidsetParentid(String parentid) Sets the parent ID.voidsetPassword(String password) Sets a password.voidsetPicture(String picture) Sets the profile picture URL.voidSets the stored flag.voidSets the tags.voidsetTimestamp(Long timestamp) Sets the timestamp.voidsetTokenSecret(String tokenSecret) Sets the token secret.voidSets 2FA enabled/disabled.voidsetTwoFAbackupKeyHash(String twoFAbackupKeyHash) Sets the 2FA backup key hash.voidsetTwoFAkey(String twoFAkey) Sets the 2FA secret key.final voidSets the object type.voidsetUpdated(Long updated) Sets the updated timestamp.voidsetVersion(Long version) Sets the version of the object.voidSets the number of votes.toString()Returns a JSON string representation of this object.voidUnlinks the object from another object of a certain type and ID.voidUnlinks the object from all other objects.voidupdate()Updates the object in the database.booleanVotes down for the object.booleanVotes up for the object.
-
Field Details
-
MAX_PASSWORD_LENGTH
public static final int MAX_PASSWORD_LENGTHMaximum password length.- See Also:
-
-
Constructor Details
-
User
public User()No-args constructor. -
User
-
-
Method Details
-
getTokenSecret
Token secret - used for generating JWT tokens. Changing this secret would invalidate all existing user tokens. A kind of global "logout".- Returns:
- a random string
-
setTokenSecret
Sets the token secret.- Parameters:
tokenSecret- a random string
-
getPicture
-
setPicture
Sets the profile picture URL.- Parameters:
picture- the picture URL.
-
getActive
-
setActive
-
getTwoFA
-
setTwoFA
Sets 2FA enabled/disabled.- Parameters:
twoFA- true if 2FA is enabled
-
getTwoFAkey
Returns the 2FA secret key. Used for checking the TOTP code.- Returns:
- the 2FA secret key. Used for checking the TOTP code.
-
setTwoFAkey
-
getTwoFAbackupKeyHash
Returns the hashed backup key (shown only once). Used for disabling 2FA.- Returns:
- the hashed backup key (shown only once). Used for disabling 2FA.
-
setTwoFAbackupKeyHash
Sets the 2FA backup key hash.- Parameters:
twoFAbackupKeyHash- bcrypt hash
-
getGroups
-
setGroups
Sets the security groups for this user.- Parameters:
groups- the groups string
-
getIdentifier
Returns the main identifier for this user. An identifier is basically a unique username that identifies a user.- Returns:
- the main identifier
-
setIdentifier
Sets the main identifier.- Parameters:
identifier- the main identifier
-
getEmail
-
setEmail
-
getCurrency
The user's currency preference.- Returns:
- a currency 3-letter code in uppercase
-
setCurrency
Sets a preferred currency. Default is "EUR".- Parameters:
currency- a 3-letter currency code
-
resetTokenSecret
public void resetTokenSecret()Generates a new token secret. This is whould be equivalent to "logout everywhere". -
canModify
Note: this method assumes that child objects can be modified by their parents. This might not work for special cases where a parent has no rights over a child.- Parameters:
obj- an object- Returns:
- true if the user is the creator or parent of this object or an admin user
-
create
Description copied from interface:ParaObjectStores this object in the data store.- Specified by:
createin interfaceParaObject- Returns:
- the id of the object (a new id if object is new)
- See Also:
-
delete
public void delete()Description copied from interface:ParaObjectDeletes the object permanently by removing it from the data store.- Specified by:
deletein interfaceParaObject- See Also:
-
attachIdentifier
Attaches a new identifier to this user.- Parameters:
identifier- a new identifier
-
detachIdentifier
Detaches a secondary identifier which is not already used by this user.- Parameters:
identifier- an attached identifier
-
isFacebookUser
public boolean isFacebookUser()Is the main identifier a Facebook id.- Returns:
- true if user is signed in with Facebook
-
isGooglePlusUser
public boolean isGooglePlusUser()Is the main identifier a Google+ id.- Returns:
- true if user is signed in with Google+
-
isLinkedInUser
public boolean isLinkedInUser()Is the main identifier a LinkedIn id.- Returns:
- true if user is signed in with LinkedIn
-
isTwitterUser
public boolean isTwitterUser()Is the main identifier a Twitter id.- Returns:
- true if user is signed in with Twitter
-
isGitHubUser
public boolean isGitHubUser()Is the main identifier a GitHub id.- Returns:
- true if user is signed in with GitHub
-
isMicrosoftUser
public boolean isMicrosoftUser()Is the main identifier a Microsoft/Windows account id.- Returns:
- true if user is signed in with a Microsoft account
-
isSlackUser
public boolean isSlackUser()Is the main identifier a Slack account id.- Returns:
- true if user is signed in with a Slack account
-
isMattermostUser
public boolean isMattermostUser()Is the main identifier a Mattermost account id.- Returns:
- true if user is signed in with a Mattermost account
-
isAmazonUser
public boolean isAmazonUser()Is the main identifier a Amazon account id.- Returns:
- true if user is signed in with a Amazon account
-
isLDAPUser
public boolean isLDAPUser()Is the main identifier a LDAP account.- Returns:
- true if user is signed in with a LDAP account
-
isSAMLUser
public boolean isSAMLUser()Is the main identifier a SAML account.- Returns:
- true if user is signed in with a SAML account
-
isPasswordlessUser
public boolean isPasswordlessUser()Is the main identifier a custom SSO account.- Returns:
- true if user is signed in with a custom SSO JWT token
-
isOAuth2User
public boolean isOAuth2User()Is the main identifier from a generic OAuth 2.0/OpenID Connect provider.- Returns:
- true if user is signed in with a generic OAauth 2.0 account
-
isAdmin
public boolean isAdmin()Checks for admin rights.- Returns:
- true if user has admin rights
-
isModerator
public boolean isModerator()Checks for moderator rights.- Returns:
- true if user has mod rights
-
getIdentityProvider
Returns the name of the identity provider.- Returns:
- "facebook", "google"... etc.
-
hasValidIdentifier
public boolean hasValidIdentifier()Validates the identifier property value.- Returns:
- true if the user identifier has valid syntax.
-
getPassword
The password. A transient field used for validation.- Returns:
- the password.
-
setPassword
-
getIdpIdToken
Used for storing the ID token from an OpenID Connect/OAuth 2.0 identity provider.- Returns:
- an ID token (JWT is always assumed to be the format)
-
setIdpIdToken
Sets the IDP ID token.- Parameters:
idpIdToken- a token
-
getIdpAccessToken
Used for storing the access token from an OpenID Connect/OAuth 2.0 identity provider.- Returns:
- a JWT access token (JWT is always assumed to be the format)
-
setIdpAccessToken
Sets the IDP access token.- Parameters:
idpAccessToken- a token
-
getIdpRefreshToken
Stores the refresh token from the identity provider.- Returns:
- a JWT refresh token
-
setIdpRefreshToken
Sets the refresh token.- Parameters:
idpRefreshToken- a refresh token
-
getIdpIdTokenPayload
Returns the JWT payload for the ID token coming from the IDP. Used for delegating user attributes data to clients. This must be a Base64-encoded JSON string.- Returns:
- the payload part in Base64
-
getIdpAccessTokenPayload
Returns the JWT payload for the access token coming from the IDP. Used for delegating user attributes data to clients. This must be a Base64-encoded JSON string.- Returns:
- the payload part in Base64
-
readUserForIdentifier
-
passwordMatches
Checks if a user has entered the correct password. Compares password hashes.- Parameters:
u- a user with a set password- Returns:
- true if password matches the one in the data store
- Throws:
RateLimitException- if rate limit is exceeded when password doesn't match.
-
generatePasswordResetToken
Generates a new password reset token. Sent via email for pass reset.- Returns:
- the pass reset token
-
resetPassword
Changes the user password permanently.- Parameters:
token- the reset token. seegeneratePasswordResetToken()newpass- the new password- Returns:
- true if successful
-
generateEmailConfirmationToken
Generates a new email confirmation token. Sent via email for user activation.- Returns:
- a Base64 encoded UUID
-
activateWithEmailToken
Activates a user if a given token matches the one stored.- Parameters:
token- the email confirmation token. seegenerateEmailConfirmationToken()- Returns:
- true if successful
-
isValidPasswordResetToken
Validates a token sent via email for password reset.- Parameters:
token- a token- Returns:
- true if valid
-
isValidEmailConfirmationToken
Validates a token sent for email confirmation.- Parameters:
token- a token- Returns:
- true if valid
-
getId
Returns the object ID.- Specified by:
getIdin interfaceParaObject- Returns:
- the id
-
setId
Sets the object ID.- Specified by:
setIdin interfaceParaObject- Parameters:
id- the id
-
getType
Returns the object type.- Specified by:
getTypein interfaceParaObject- Returns:
- the type
-
setType
Sets the object type.- Specified by:
setTypein interfaceParaObject- Parameters:
type- the type
-
getAppid
Returns the app identifier.- Specified by:
getAppidin interfaceParaObject- Returns:
- the appid
-
setAppid
Sets the app identifier.- Specified by:
setAppidin interfaceParaObject- Parameters:
appid- the appid
-
getObjectURI
Returns the object URI.- Specified by:
getObjectURIin interfaceParaObject- Returns:
- the URI
- See Also:
-
getTags
Returns the tags.- Specified by:
getTagsin interfaceParaObject- Returns:
- the tags
- See Also:
-
setTags
Sets the tags.- Specified by:
setTagsin interfaceParaObject- Parameters:
tags- the tags
-
getStored
Returns true if the object is stored in the database.- Specified by:
getStoredin interfaceParaObject- Returns:
- true if stored
-
setStored
Sets the stored flag.- Specified by:
setStoredin interfaceParaObject- Parameters:
stored- the stored flag
-
getIndexed
Returns true if the object is indexed.- Specified by:
getIndexedin interfaceParaObject- Returns:
- true if indexed
-
setIndexed
Sets the indexed flag.- Specified by:
setIndexedin interfaceParaObject- Parameters:
indexed- the indexed flag
-
getCached
Returns true if the object is cached.- Specified by:
getCachedin interfaceParaObject- Returns:
- true if cached
-
setCached
Sets the cached flag.- Specified by:
setCachedin interfaceParaObject- Parameters:
cached- the cached flag
-
getTimestamp
Returns the timestamp.- Specified by:
getTimestampin interfaceParaObject- Returns:
- the timestamp
-
setTimestamp
Sets the timestamp.- Specified by:
setTimestampin interfaceParaObject- Parameters:
timestamp- the timestamp
-
getCreatorid
Returns the creator ID.- Specified by:
getCreatoridin interfaceParaObject- Returns:
- the creatorid
-
setCreatorid
Sets the creator ID.- Specified by:
setCreatoridin interfaceParaObject- Parameters:
creatorid- the creatorid
-
getName
Returns the object name.- Specified by:
getNamein interfaceParaObject- Returns:
- the name
-
setName
Sets the object name.- Specified by:
setNamein interfaceParaObject- Parameters:
name- the name
-
getPlural
Returns the plural form of the object type.- Specified by:
getPluralin interfaceParaObject- Returns:
- the plural name
-
getParentid
Returns the parent ID.- Specified by:
getParentidin interfaceParaObject- Returns:
- the parentid
-
setParentid
Sets the parent ID.- Specified by:
setParentidin interfaceParaObject- Parameters:
parentid- the parentid
-
getUpdated
Returns the updated timestamp.- Specified by:
getUpdatedin interfaceParaObject- Returns:
- the updated timestamp
-
setUpdated
Sets the updated timestamp.- Specified by:
setUpdatedin interfaceParaObject- Parameters:
updated- the updated timestamp
-
update
public void update()Updates the object in the database.- Specified by:
updatein interfaceParaObject- See Also:
-
exists
public boolean exists()Returns true if the object exists in the database.- Specified by:
existsin interfaceParaObject- Returns:
- true if exists
- See Also:
-
voteUp
-
voteDown
-
getVotes
-
setVotes
-
getVersion
Returns the version of the object.- Specified by:
getVersionin interfaceParaObject- Returns:
- the version
-
setVersion
Sets the version of the object.- Specified by:
setVersionin interfaceParaObject- Parameters:
version- the version
-
countLinks
Counts the number of links to other objects of a certain type.- Specified by:
countLinksin interfaceLinkable- Parameters:
type2- the other type- Returns:
- the number of links
-
getLinks
-
getLinkedObjects
Returns a list of linked objects of a certain type.- Specified by:
getLinkedObjectsin interfaceLinkable- Type Parameters:
P- the type of linked objects- Parameters:
type- the other typepager- a pager- Returns:
- a list of linked objects
-
findLinkedObjects
public <P extends ParaObject> List<P> findLinkedObjects(String type, String field, String query, Pager... pager) Finds linked objects of a certain type that match a specific field and query.- Specified by:
findLinkedObjectsin interfaceLinkable- Type Parameters:
P- the type of linked objects- Parameters:
type- the other typefield- the field to search inquery- the search querypager- a pager- Returns:
- a list of linked objects
-
isLinked
-
isLinked
Returns true if the object is linked to another object. -
link
-
unlink
-
unlinkAll
-
countChildren
Counts the number of children of a certain type.- Specified by:
countChildrenin interfaceLinkable- Parameters:
type- the child type- Returns:
- the number of children
-
getChildren
Returns a list of children of a certain type.- Specified by:
getChildrenin interfaceLinkable- Type Parameters:
P- the type of children- Parameters:
type- the child typepager- a pager- Returns:
- a list of children
-
getChildren
public <P extends ParaObject> List<P> getChildren(String type, String field, String term, Pager... pager) Returns a list of children of a certain type that match a specific field and term.- Specified by:
getChildrenin interfaceLinkable- Type Parameters:
P- the type of children- Parameters:
type- the child typefield- the field to search interm- the search termpager- a pager- Returns:
- a list of children
-
findChildren
Finds children of a certain type that match a specific query.- Specified by:
findChildrenin interfaceLinkable- Type Parameters:
P- the type of children- Parameters:
type- the child typequery- the search querypager- a pager- Returns:
- a list of children
-
deleteChildren
Deletes all children of a certain type.- Specified by:
deleteChildrenin interfaceLinkable- Parameters:
type- the child type
-
hashCode
-
equals
-
toString
-