public class User extends StorableObject
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_REALM
The default user realm.
|
static java.lang.String |
KEY_DESCRIPTION
The dictionary key for the user description.
|
static java.lang.String |
KEY_EMAIL
The dictionary key for the user email address.
|
static java.lang.String |
KEY_ENABLED
The dictionary key for the user enabled flag.
|
static java.lang.String |
KEY_NAME
The dictionary key for the user name.
|
static java.lang.String |
KEY_PASSWORD
The dictionary key for the user password hash.
|
static java.lang.String |
KEY_REALM
The dictionary key for the user realm.
|
static java.lang.String |
KEY_ROLE
The dictionary key for the user role array.
|
static Path |
PATH
The user object storage path.
|
dict, KEY_CLASSNAME, KEY_ID, KEY_TYPE
Constructor and Description |
---|
User(java.lang.String id)
Creates a new user with the specified user identifier.
|
User(java.lang.String id,
java.lang.String type,
Dict dict)
Creates a new user from a serialized representation.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
createAuthToken(long expiryTime)
Creates an authentication token for this user.
|
static java.lang.String[] |
decodeAuthToken(java.lang.String token)
Decodes a user authentication token.
|
java.lang.String |
description()
Returns the user description.
|
java.lang.String |
email()
Returns the user email address.
|
static java.lang.String |
encodeAuthToken(java.lang.String id,
long expiry,
java.lang.String hash)
Encodes a user authentication token.
|
static User |
find(Storage storage,
java.lang.String id)
Searches for a specific user in the storage.
|
boolean |
hasRole(java.lang.String name)
Checks if the user has the specified role.
|
boolean |
isEnabled()
Checks if the user is enabled.
|
java.lang.String |
name()
Returns the user name.
|
java.lang.String |
passwordHash()
Returns the user password MD5 hash, encoded as a hexadecimal
string.
|
java.lang.String |
realm()
Returns the user realm.
|
java.lang.String[] |
roles()
Returns an array with all the roles for the user.
|
void |
setDescription(java.lang.String descr)
Sets the user description.
|
void |
setEmail(java.lang.String email)
Sets the user email address.
|
void |
setEnabled(boolean enabled)
Sets the user enabled flag.
|
void |
setName(java.lang.String name)
Sets the user name.
|
void |
setPassword(java.lang.String password)
Sets the user password.
|
void |
setPasswordHash(java.lang.String passwordHash)
Sets the user password MD5 hash.
|
void |
setRealm(java.lang.String realm)
Sets the user realm.
|
void |
setRoles(java.lang.String[] roles)
Sets all the all the roles for the user.
|
static void |
store(Storage storage,
User user)
Stores the specified used in the provided storage.
|
boolean |
verifyAuthToken(java.lang.String token)
Verifies that the specified authentication token is valid for this user.
|
boolean |
verifyPasswordHash(java.lang.String passwordHash)
Verifies that the specified password MD5 hash is a match.
|
public static final java.lang.String DEFAULT_REALM
public static final java.lang.String KEY_NAME
public static final java.lang.String KEY_EMAIL
public static final java.lang.String KEY_DESCRIPTION
public static final java.lang.String KEY_ENABLED
public static final java.lang.String KEY_REALM
public static final java.lang.String KEY_PASSWORD
public static final java.lang.String KEY_ROLE
public static final Path PATH
public User(java.lang.String id, java.lang.String type, Dict dict)
id
- the object identifiertype
- the object type namedict
- the serialized representationpublic User(java.lang.String id)
id
- the user identifierpublic static User find(Storage storage, java.lang.String id)
storage
- the storage to search inid
- the user identifierpublic static void store(Storage storage, User user) throws StorageException
storage
- the storage to useuser
- the user to storeStorageException
- if the user couldn't be storedpublic static java.lang.String[] decodeAuthToken(java.lang.String token)
token
- the token stringpublic static java.lang.String encodeAuthToken(java.lang.String id, long expiry, java.lang.String hash)
id
- the user idexpiry
- the expire timestamp (in millis)hash
- the data validation hashpublic java.lang.String name()
public void setName(java.lang.String name)
name
- the user full namepublic java.lang.String email()
public void setEmail(java.lang.String email)
email
- the user email addresspublic java.lang.String description()
public void setDescription(java.lang.String descr)
descr
- the user descriptionpublic boolean isEnabled()
public void setEnabled(boolean enabled)
enabled
- the enabled flagpublic java.lang.String realm()
public void setRealm(java.lang.String realm)
realm
- the new user realmpublic java.lang.String passwordHash()
verifyPasswordHash(String)
public void setPasswordHash(java.lang.String passwordHash)
passwordHash
- the new user password MD5 hashsetPassword(String)
public void setPassword(java.lang.String password)
password
- the new user password (in clear text)setPasswordHash(String)
public boolean verifyPasswordHash(java.lang.String passwordHash)
passwordHash
- the password hash to checkpublic java.lang.String createAuthToken(long expiryTime)
expiryTime
- the authentication token expire time (in millis)public boolean verifyAuthToken(java.lang.String token)
token
- the authentication tokenpublic boolean hasRole(java.lang.String name)
name
- the role namepublic java.lang.String[] roles()
public void setRoles(java.lang.String[] roles)
roles
- the array with all roles