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
Modifier and TypeClassDescriptionstatic enum
Simple groups enum.static enum
Simple user roles enum.Nested classes/interfaces inherited from interface com.erudika.para.core.Votable
Votable.VoteValue
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
activateWithEmailToken
(String token) Activates a user if a given token matches the one stored.void
attachIdentifier
(String identifier) Attaches a new identifier to this user.boolean
canModify
(ParaObject obj) Note: this method assumes that child objects can be modified by their parents.countChildren
(String type) Count the total number of child objects for this object.countLinks
(String type2) Count the total number of links between this object and another type of object.create()
Stores this object in the data store.void
delete()
Deletes the object permanently by removing it from the data store.void
deleteChildren
(String type) Deletes all child objects permanently.void
detachIdentifier
(String identifier) Detaches a secondary identifier which is not already used by this user.boolean
boolean
exists()
Checks if an object is stored in the data store.<P extends ParaObject>
List<P> findChildren
(String type, String query, Pager... pager) Search through all child objects.<P extends ParaObject>
List<P> findLinkedObjects
(String type, String field, String query, Pager... pager) Similar toLinkable.findChildren(java.lang.String, java.lang.String, com.erudika.para.core.utils.Pager...)
but for many-to-many relationships.Generates a new email confirmation token.final String
Generates a new password reset token.Returns true if this account is active.getAppid()
The application name.Boolean flag which controls whether this object is cached.<P extends ParaObject>
List<P> getChildren
(String type, Pager... pager) Returns all child objects linked to this object.<P extends ParaObject>
List<P> getChildren
(String type, String field, String term, Pager... pager) Returns all child objects linked to this object.The id of the user who created this.The user's currency preference.getEmail()
The user's email.Returns the security groups for this user.final String
getId()
The id of an object.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.Boolean flag which controls whether this object is indexed by the search engine.<P extends ParaObject>
List<P> getLinkedObjects
(String type, Pager... pager) Similar toLinkable.getChildren(java.lang.String, com.erudika.para.core.utils.Pager...)
but for many-to-many relationships.Returns all links between this type object and another type of object.final String
getName()
The name of the object.The URI of this object.The id of the parent object.The password.The profile picture URL.The plural name of the object.Boolean flag which controls whether this object is stored in the database or not.getTags()
The tags associated with this object.The time when the object was created, in milliseconds.Token secret - used for generating JWT tokens.getTwoFA()
final String
getType()
The name of the object's class.The last time this object was updated.Returns the version number for this object.getVotes()
Returns the total sum of all votes for this object.int
hashCode()
boolean
Validates the identifier property value.boolean
isAdmin()
Checks for admin rights.boolean
Is the main identifier a Amazon account id.boolean
Is the main identifier a Facebook id.boolean
Is the main identifier a GitHub id.boolean
Is the main identifier a Google+ id.boolean
Is the main identifier a LDAP account.boolean
isLinked
(ParaObject toObj) Checks if a given object is linked to this one.boolean
Checks if this object is linked to another.boolean
Is the main identifier a LinkedIn id.boolean
Is the main identifier a Mattermost account id.boolean
Is the main identifier a Microsoft/Windows account id.boolean
Checks for moderator rights.boolean
Is the main identifier from a generic OAuth 2.0/OpenID Connect provider.boolean
Is the main identifier a custom SSO account.boolean
Is the main identifier a SAML account.boolean
Is the main identifier a Slack account id.boolean
Is the main identifier a Twitter id.final boolean
Validates a token sent for email confirmation.final boolean
isValidPasswordResetToken
(String token) Validates a token sent via email for password reset.Links an object to this one in a many-to-many relationship.static final boolean
Checks if a user has entered the correct password.static final User
Returns a user object for a given identifier.final boolean
resetPassword
(String token, String newpass) Changes the user password permanently.void
Generates a new token secret.void
Sets the account active.void
Sets a new app name.void
Sets the "isCached" flag.void
setCreatorid
(String creatorid) Sets a new creator id.void
setCurrency
(String currency) Sets a preferred currency.void
Sets the email.void
Sets the security groups for this user.final void
Sets a new id.void
setIdentifier
(String identifier) Sets the main identifier.void
setIdpAccessToken
(String idpAccessToken) Sets the IDP access token.void
setIdpIdToken
(String idpIdToken) Sets the IDP ID token.void
setIdpRefreshToken
(String idpRefreshToken) Sets the refresh token.void
setIndexed
(Boolean indexed) Sets the "isIndexed" flag.final void
Sets a new name.void
setParentid
(String parentid) Sets a new parent id.void
setPassword
(String password) Sets a password.void
setPicture
(String picture) Sets the profile picture URL.void
Sets the "isStored" flag.void
Merges the given tags with existing tags.void
setTimestamp
(Long timestamp) Sets the timestamp.void
setTokenSecret
(String tokenSecret) Sets the token secret.void
Sets 2FA enabled/disabled.void
setTwoFAbackupKeyHash
(String twoFAbackupKeyHash) Sets the 2FA backup key hash.void
setTwoFAkey
(String twoFAkey) Sets the 2FA secret key.final void
Sets a new object type.void
setUpdated
(Long updated) Sets the last updated timestamp.void
setVersion
(Long version) Sets the version of this object.void
Sets the total votes for this object.toString()
void
Unlinks an object from this one.void
Unlinks all objects that are linked to this one.void
update()
Updates the object permanently.boolean
Downvotes the object.boolean
Upvotes 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
- Returns:
- true if 2FA is enabled
-
setTwoFA
Sets 2FA enabled/disabled.- Parameters:
twoFA
- true if 2FA is enabled
-
getTwoFAkey
- 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.
-
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:ParaObject
Stores this object in the data store.- Specified by:
create
in interfaceParaObject
- Returns:
- the id of the object (a new id if object is new)
- See Also:
-
delete
public void delete()Description copied from interface:ParaObject
Deletes the object permanently by removing it from the data store.- Specified by:
delete
in 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:
LimitExceededException
- 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
Description copied from interface:ParaObject
The id of an object. Usually an autogenerated unique string of numbers.- Specified by:
getId
in interfaceParaObject
- Returns:
- the id
-
setId
Description copied from interface:ParaObject
Sets a new id. Must not be null or empty.- Specified by:
setId
in interfaceParaObject
- Parameters:
id
- the new id
-
getType
Description copied from interface:ParaObject
The name of the object's class. This is equivalent toClass.getSimpleName()
.toLowerCase()- Specified by:
getType
in interfaceParaObject
- Returns:
- the simple name of the class
-
setType
Description copied from interface:ParaObject
Sets a new object type. Must not be null or empty.- Specified by:
setType
in interfaceParaObject
- Parameters:
type
- a new type
-
getAppid
Description copied from interface:ParaObject
The application name. Added to support multiple separate apps. Every object must belong to an app.- Specified by:
getAppid
in interfaceParaObject
- Returns:
- the app id (name). default: para
-
setAppid
Description copied from interface:ParaObject
Sets a new app name. Must not be null or empty.- Specified by:
setAppid
in interfaceParaObject
- Parameters:
appid
- the new app id (name)
-
getObjectURI
Description copied from interface:ParaObject
The URI of this object. For example: /users/123- Specified by:
getObjectURI
in interfaceParaObject
- Returns:
- the URI
- See Also:
-
getTags
Description copied from interface:ParaObject
The tags associated with this object. Tags must not be null or empty.- Specified by:
getTags
in interfaceParaObject
- Returns:
- a set of tags, or an empty set
- See Also:
-
setTags
Description copied from interface:ParaObject
Merges the given tags with existing tags.- Specified by:
setTags
in interfaceParaObject
- Parameters:
tags
- the additional tags, or clears all tags if set to null
-
getStored
Description copied from interface:ParaObject
Boolean flag which controls whether this object is stored in the database or not. Default is true.- Specified by:
getStored
in interfaceParaObject
- Returns:
- true if this object is stored in DB.
-
setStored
Description copied from interface:ParaObject
Sets the "isStored" flag.- Specified by:
setStored
in interfaceParaObject
- Parameters:
stored
- when set to true, object is stored in DB.
-
getIndexed
Description copied from interface:ParaObject
Boolean flag which controls whether this object is indexed by the search engine. Default is true.- Specified by:
getIndexed
in interfaceParaObject
- Returns:
- true if this object is indexed
-
setIndexed
Description copied from interface:ParaObject
Sets the "isIndexed" flag.- Specified by:
setIndexed
in interfaceParaObject
- Parameters:
indexed
- when set to true, object is indexed.
-
getCached
Description copied from interface:ParaObject
Boolean flag which controls whether this object is cached. Default is true.- Specified by:
getCached
in interfaceParaObject
- Returns:
- true if this object is cached on update() and create().
-
setCached
Description copied from interface:ParaObject
Sets the "isCached" flag.- Specified by:
setCached
in interfaceParaObject
- Parameters:
cached
- when set to true, object is cached.
-
getTimestamp
Description copied from interface:ParaObject
The time when the object was created, in milliseconds.- Specified by:
getTimestamp
in interfaceParaObject
- Returns:
- the timestamp of creation
-
setTimestamp
Description copied from interface:ParaObject
Sets the timestamp.- Specified by:
setTimestamp
in interfaceParaObject
- Parameters:
timestamp
- a new timestamp in milliseconds.
-
getCreatorid
Description copied from interface:ParaObject
The id of the user who created this. Should point to aUser
id.- Specified by:
getCreatorid
in interfaceParaObject
- Returns:
- the id or null
-
setCreatorid
Description copied from interface:ParaObject
Sets a new creator id. Must not be null or empty.- Specified by:
setCreatorid
in interfaceParaObject
- Parameters:
creatorid
- a new id
-
getName
Description copied from interface:ParaObject
The name of the object. Can be anything.- Specified by:
getName
in interfaceParaObject
- Returns:
- the name. default: [type id]
-
setName
Description copied from interface:ParaObject
Sets a new name. Must not be null or empty.- Specified by:
setName
in interfaceParaObject
- Parameters:
name
- the new name
-
getPlural
Description copied from interface:ParaObject
The plural name of the object. For example: user - users- Specified by:
getPlural
in interfaceParaObject
- Returns:
- the plural name
-
getParentid
Description copied from interface:ParaObject
The id of the parent object.- Specified by:
getParentid
in interfaceParaObject
- Returns:
- the id of the parent or null
-
setParentid
Description copied from interface:ParaObject
Sets a new parent id. Must not be null or empty.- Specified by:
setParentid
in interfaceParaObject
- Parameters:
parentid
- a new id
-
getUpdated
Description copied from interface:ParaObject
The last time this object was updated. Timestamp in ms.- Specified by:
getUpdated
in interfaceParaObject
- Returns:
- timestamp in milliseconds
-
setUpdated
Description copied from interface:ParaObject
Sets the last updated timestamp.- Specified by:
setUpdated
in interfaceParaObject
- Parameters:
updated
- a new timestamp
-
update
public void update()Description copied from interface:ParaObject
Updates the object permanently. Changes toLocked
fields are ignored.- Specified by:
update
in interfaceParaObject
- See Also:
-
exists
public boolean exists()Description copied from interface:ParaObject
Checks if an object is stored in the data store.- Specified by:
exists
in interfaceParaObject
- Returns:
- true if the object is persisted to the data store.
- See Also:
-
voteUp
-
voteDown
-
getVotes
-
setVotes
-
getVersion
Description copied from interface:ParaObject
Returns the version number for this object. Used primarily for optimistic locking.- Specified by:
getVersion
in interfaceParaObject
- Returns:
- a positive number,
0
if unused or-1
, indicating a failed update.
-
setVersion
Description copied from interface:ParaObject
Sets the version of this object. This value should come from the database.- Specified by:
setVersion
in interfaceParaObject
- Parameters:
version
- a positive number, different than the current value of the version field
-
countLinks
Description copied from interface:Linkable
Count the total number of links between this object and another type of object.- Specified by:
countLinks
in interfaceLinkable
- Parameters:
type2
- the other type of object- Returns:
- the number of links
-
getLinks
Description copied from interface:Linkable
Returns all links between this type object and another type of object. -
getLinkedObjects
Description copied from interface:Linkable
Similar toLinkable.getChildren(java.lang.String, com.erudika.para.core.utils.Pager...)
but for many-to-many relationships.- Specified by:
getLinkedObjects
in interfaceLinkable
- Type Parameters:
P
- type of linked objects- Parameters:
type
- type of linked objects to look forpager
- aPager
- Returns:
- a list of linked objects
-
findLinkedObjects
public <P extends ParaObject> List<P> findLinkedObjects(String type, String field, String query, Pager... pager) Description copied from interface:Linkable
Similar toLinkable.findChildren(java.lang.String, java.lang.String, com.erudika.para.core.utils.Pager...)
but for many-to-many relationships. Searches through all linked objects connected to this via aLinker
object.- Specified by:
findLinkedObjects
in interfaceLinkable
- Type Parameters:
P
- type of linked objects- Parameters:
type
- type of linked objects to look forfield
- the name of the field to target (within a nested field "nstd")query
- a query stringpager
- aPager
- Returns:
- a list of linked objects matching the search query
-
isLinked
-
isLinked
Description copied from interface:Linkable
Checks if a given object is linked to this one. -
link
Description copied from interface:Linkable
Links an object to this one in a many-to-many relationship. Only a link is created. Objects are left untouched. The type of the second object is automatically determined on read. -
unlink
-
unlinkAll
-
countChildren
Description copied from interface:Linkable
Count the total number of child objects for this object.- Specified by:
countChildren
in interfaceLinkable
- Parameters:
type
- the other type of object- Returns:
- the number of links
-
getChildren
Description copied from interface:Linkable
Returns all child objects linked to this object.- Specified by:
getChildren
in interfaceLinkable
- Type Parameters:
P
- the type of children- Parameters:
type
- the type of children to look forpager
- aPager
- Returns:
- a list of
ParaObject
in a one-to-many relationship with this object
-
getChildren
public <P extends ParaObject> List<P> getChildren(String type, String field, String term, Pager... pager) Description copied from interface:Linkable
Returns all child objects linked to this object.- Specified by:
getChildren
in interfaceLinkable
- Type Parameters:
P
- the type of children- Parameters:
type
- the type of children to look forfield
- the field name to use as filterterm
- the field value to use as filterpager
- aPager
- Returns:
- a list of
ParaObject
in a one-to-many relationship with this object
-
findChildren
Description copied from interface:Linkable
Search through all child objects. Only searches child objects directly connected to this parent via theparentid
field.- Specified by:
findChildren
in interfaceLinkable
- Type Parameters:
P
- the type of children- Parameters:
type
- the type of children to look forquery
- a query stringpager
- aPager
- Returns:
- a list of
ParaObject
in a one-to-many relationship with this object
-
deleteChildren
Description copied from interface:Linkable
Deletes all child objects permanently.- Specified by:
deleteChildren
in interfaceLinkable
- Parameters:
type
- the children's type.
-
hashCode
-
equals
-
toString
-