Package org.rapidcontext.core.type
Class User
java.lang.Object
org.rapidcontext.core.storage.StorableObject
org.rapidcontext.core.type.User
A system user.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default active user time (5 minutes).static final StringThe default user realm.static final StringThe dictionary key for the oldest valid authentication timestamp.static final StringThe dictionary key for the user description.static final StringThe dictionary key for the user email address.static final StringThe dictionary key for the user enabled flag.static final StringThe dictionary key for the user name.static final StringThe dictionary key for the user password hash.static final StringThe dictionary key for the user realm.static final StringThe dictionary key for the user role array.static final StringThe dictionary key for the user settings dictionary.static final PathThe user object storage path.Fields inherited from class org.rapidcontext.core.storage.StorableObject
dict, KEY_ACTIVATED_TIME, KEY_CLASSNAME, KEY_ID, KEY_TYPE, PREFIX_COMPUTED, PREFIX_HIDDEN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the oldest valid authentication timestamp.Returns the user description.email()Returns the user email address.static UserSearches for a specific user in the storage.booleanChecks if the user has the specified role.protected booleanisActive()Checks if this object is in active use.booleanChecks if the user is enabled.static MetricsReturns the user request metrics.name()Returns the user name.static DictNormalizes a user data object if needed.Returns the user password MD5 hash, encoded as a hexadecimal string.realm()Returns the user realm.static voidReports user request metrics for a single request.String[]roles()Returns an array with all the roles for the user.voidsetDescription(String descr) Sets the user description.voidSets the user email address.voidsetEnabled(boolean enabled) Sets the user enabled flag.voidSets the user name.voidsetPassword(String password) Sets the user password.voidsetPasswordHash(String passwordHash) Sets the user password MD5 hash.voidSets the user realm.voidSets all the roles for the user.settings()Returns the user settings dictionary.static voidStores the specified user in the provided storage.voidupdateSettings(Dict updates) Merges updates into the user settings dictionary.booleanverifyPasswordHash(String passwordHash) Verifies that the specified password MD5 hash is a match.Methods inherited from class org.rapidcontext.core.storage.StorableObject
activate, activatedTime, destroy, dictKey, id, init, isDeleted, isModified, passivate, path, serialize, sterilize, toString, type
-
Field Details
-
DEFAULT_REALM
The default user realm.- See Also:
-
KEY_NAME
The dictionary key for the user name.- See Also:
-
KEY_EMAIL
The dictionary key for the user email address.- See Also:
-
KEY_DESCRIPTION
The dictionary key for the user description.- See Also:
-
KEY_ENABLED
The dictionary key for the user enabled flag.- See Also:
-
KEY_REALM
The dictionary key for the user realm.- See Also:
-
KEY_PASSWORD
The dictionary key for the user password hash.- See Also:
-
KEY_ROLE
The dictionary key for the user role array.- See Also:
-
KEY_AUTHORIZED_TIME
The dictionary key for the oldest valid authentication timestamp.- See Also:
-
KEY_SETTINGS
The dictionary key for the user settings dictionary.- See Also:
-
PATH
The user object storage path. -
ACTIVE_MILLIS
public static final long ACTIVE_MILLISThe default active user time (5 minutes).- See Also:
-
-
Constructor Details
-
User
Creates a new user from a serialized representation.- Parameters:
id- the object identifiertype- the object type namedict- the serialized representation
-
User
Creates a new user with the specified user identifier. The user will be created with a blank password.- Parameters:
id- the user identifier
-
-
Method Details
-
find
Searches for a specific user in the storage.- Parameters:
storage- the storage to search inid- the user identifier- Returns:
- the user found, or null if not found
-
store
Stores the specified user in the provided storage.- Parameters:
storage- the storage to useuser- the user to store- Throws:
StorageException- if the user couldn't be stored
-
metrics
Returns the user request metrics. The metrics will be loaded from storage if not already in memory.- Parameters:
storage- the storage to load from- Returns:
- the user request metrics
-
report
Reports user request metrics for a single request.- Parameters:
user- the user object, or null for anonymousstart- the start time (in millis)success- the success flagerror- the optional error message
-
normalize
Normalizes a user data object if needed. This method will modify legacy data into the proper keys and values.- Parameters:
id- the object identifierdict- the storage data- Returns:
- the storage data (possibly modified)
-
isActive
protected boolean isActive()Checks if this object is in active use. This method will return true if the object was activated during the last 5 minutes.- Overrides:
isActivein classStorableObject- Returns:
- true if the object is considered active, or false otherwise
-
name
Returns the user name.- Returns:
- the user name.
-
setName
Sets the user name.- Parameters:
name- the user full name
-
email
Returns the user email address.- Returns:
- the user email address.
-
setEmail
Sets the user email address.- Parameters:
email- the user email address
-
description
Returns the user description.- Returns:
- the user description.
-
setDescription
Sets the user description.- Parameters:
descr- the user description
-
isEnabled
public boolean isEnabled()Checks if the user is enabled.- Returns:
- true if the user is enabled, or false otherwise
-
setEnabled
public void setEnabled(boolean enabled) Sets the user enabled flag.- Parameters:
enabled- the enabled flag
-
realm
Returns the user realm.- Returns:
- the user realm.
-
setRealm
Sets the user realm. Note that this method will make the old password impossible to use, since the password hash contains the old realm name. A new password hash should be calculated.- Parameters:
realm- the new user realm
-
passwordHash
Returns the user password MD5 hash, encoded as a hexadecimal string. Avoid using this method to verify the current user password, since it may be blank (any password) or the user might be disabled. Use verifyPasswordHash() instead.- Returns:
- the user password hash
- See Also:
-
setPasswordHash
Sets the user password MD5 hash. The password hash should be created from the string "id:realm:password" and converted to a lower-case hexadecimal string before being sent to this method.- Parameters:
passwordHash- the new user password MD5 hash- See Also:
-
setPassword
Sets the user password. This method will create a password MD5 hash from the string "id:realm:password" and store that result in the password field. This is an irreversible process, so the original password cannot be retrieved from the object.- Parameters:
password- the new user password (in clear text)- See Also:
-
verifyPasswordHash
Verifies that the specified password MD5 hash is a match. This method checks that the user is enabled and that the current user password hash is identical to the specified one. If the current password hash is blank, this method will also return true.- Parameters:
passwordHash- the password hash to check- Returns:
- true if the password hashes are identical, or false otherwise
-
hasRole
Checks if the user has the specified role. Note that this method doesn't check for automatic roles.- Parameters:
name- the role name- Returns:
- true if the user has the role, or false otherwise
- See Also:
-
roles
Returns an array with all the roles for the user.- Returns:
- an array with all the roles
-
setRoles
Sets all the roles for the user.- Parameters:
roles- the array with all roles
-
authorizedTime
Returns the oldest valid authentication timestamp. Any session, auth token or similar created prior is considered invalid.- Returns:
- the oldest valid authentication timestamp
-
settings
Returns the user settings dictionary.- Returns:
- a dictionary with user settings, or a new empty dictionary if not set
-
updateSettings
Merges updates into the user settings dictionary. Keys with null values will be removed from settings and other keys will be overwritten. Any key not listed in the updates will remain unmodified.- Parameters:
updates- the dictionary with updates
-