Package org.openwms.core.uaa.impl
Class User
java.lang.Object
org.ameba.integration.jpa.BaseEntity
org.ameba.integration.jpa.ApplicationEntity
org.openwms.core.uaa.impl.User
- All Implemented Interfaces:
Serializable
,org.ameba.integration.TypedEntity<Long>
- Direct Known Subclasses:
SystemUser
@Entity
public class User
extends org.ameba.integration.jpa.ApplicationEntity
implements Serializable
An User represents a human user of the system. Typically an User is assigned to one or more
Roles
to define security constraints.
Users can have their own configuration settings in form of UserPreferences
and certain user details, encapsulated in an
UserDetails
object that tend to be extended by projects.- Author:
- Heiko Scherrer
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
A PasswordComparator sorts UserPassword by date ascending. -
Field Summary
Modifier and TypeFieldDescriptionEmail addresses.private boolean
true
if the User is enabled.private ZonedDateTime
Date when the account expires.private boolean
true
if the User is authenticated by an external system, otherwisefalse
.private String
The User's fullname (doesn't have to be unique).private ZonedDateTime
Date of the last password change.private boolean
true
if this User is locked and has no permission to login.private static final org.slf4j.Logger
static final short
The number of passwords to keep in the password history.private String
The User's current password (only kept transient).private List
<UserPassword> Last passwords of the User.private String
The User's current password.List ofRole
s assigned to the User.private UserDetails
More detail information of the User.private @NotEmpty String
Unique identifier of this User (not nullable).Fields inherited from class org.ameba.integration.jpa.ApplicationEntity
C_ID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addNewEmailAddress
(Email email) boolean
void
changePassword
(String encodedPassword, String rawPassword, org.springframework.security.crypto.password.PasswordEncoder encoder) Checks if the new password is a valid and change the password of this User.boolean
Return the date when the account expires.Return the fullname of the User.Return the date when the password has been changed the last time.Returns the current password of the User.Return a list of recently used passwords.getRoles()
Returns a list of grantedRole
s.Return the details of the User.Return the unique username of the User.int
hashCode()
boolean
Checks whether the password is going to change.boolean
Check whether this User has UserDetails set.boolean
Determines whether the User is enabled or not.boolean
Is the User authenticated by an external system?boolean
isLocked()
Check if the User is locked.protected void
loadLazy()
void
postLoad()
After load, the saved password is copied to the transient one.boolean
removeEmailAddress
(Email email) void
setEmailAddresses
(Set<Email> emailAddresses) void
setEnabled
(boolean enabled) Enable or disable the User.void
setExpirationDate
(ZonedDateTime expDate) Change the date when the account expires.void
setExternalUser
(boolean externalUser) Change the authentication method of the User.void
setFullname
(String fullname) Change the fullname of the User.void
setLastPasswordChange
(ZonedDateTime lastPasswordChange) Set the date when the password has been changed the last time.void
setLocked
(boolean locked) Lock the User.void
setOl
(long ol) void
setPersistentKey
(String pKey) void
Set theRole
s of this User.void
setUserDetails
(UserDetails userDetails) Assign some details to the User.void
setUsername
(String username) Change the username of the User.private void
storeOldPassword
(String oldPassword) Supplygrants
to the consumerc
if present.SupplylastPasswordChange
to the consumerc
if present.Supply the primaryemail
to the consumerc
if present.supplyRoles
(Consumer<List<Role>> c) Supplyroles
to the consumerc
if present.SupplyuserDetails
to the consumerc
if present.toString()
protected void
validateAgainstPasswordHistory
(String rawPassword, org.springframework.security.crypto.password.PasswordEncoder encoder) Check whether the new password is in the history of former passwords.void
Set thepassword
andpersistedPassword
to null.Methods inherited from class org.ameba.integration.jpa.ApplicationEntity
getPersistentKey, hasPersistentKey, onEntityPersist, onPersist
Methods inherited from class org.ameba.integration.jpa.BaseEntity
getCreatedBy, getCreateDt, getLastModifiedBy, getLastModifiedDt, getOl, getPk, isNew, setCreatedBy, setCreateDt, setLastModifiedBy, setLastModifiedDt
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
username
Unique identifier of this User (not nullable). -
extern
private boolean externtrue
if the User is authenticated by an external system, otherwisefalse
. -
lastPasswordChange
Date of the last password change. -
locked
private boolean lockedtrue
if this User is locked and has no permission to login. -
password
The User's current password (only kept transient). -
persistedPassword
The User's current password. -
enabled
private boolean enabledtrue
if the User is enabled. This field can be managed by the UI application to lock the User manually. -
expirationDate
Date when the account expires. After account expiration, the User cannot login anymore. -
fullname
The User's fullname (doesn't have to be unique). -
emailAddresses
Email addresses. -
userDetails
More detail information of the User. -
roles
List ofRole
s assigned to the User. -
passwords
Last passwords of the User. -
NUMBER_STORED_PASSWORDS
public static final short NUMBER_STORED_PASSWORDSThe number of passwords to keep in the password history. Default: 3.- See Also:
-
-
Constructor Details
-
User
protected User()Dear JPA... -
User
Create a new User with an username.- Parameters:
username
- The unique name of the user- Throws:
IllegalArgumentException
- when username is null or empty
-
User
Create a new User with a username.- Parameters:
username
- The unique name of the userpassword
- The password of the user- Throws:
IllegalArgumentException
- when username or password is null or empty
-
-
Method Details
-
postLoad
public void postLoad()After load, the saved password is copied to the transient one. The transient one can be overridden by the application to force a password change. -
loadLazy
protected void loadLazy() -
setPersistentKey
- Overrides:
setPersistentKey
in classorg.ameba.integration.jpa.ApplicationEntity
-
setOl
public void setOl(long ol) - Overrides:
setOl
in classorg.ameba.integration.jpa.BaseEntity
-
wipePassword
public void wipePassword()Set thepassword
andpersistedPassword
to null. -
addNewEmailAddress
-
removeEmailAddress
-
getUsername
Return the unique username of the User.- Returns:
- The current username
-
setUsername
Change the username of the User.- Parameters:
username
- The new username to set
-
isExternalUser
public boolean isExternalUser()Is the User authenticated by an external system?- Returns:
- true if so, otherwise false
-
setExternalUser
public void setExternalUser(boolean externalUser) Change the authentication method of the User.- Parameters:
externalUser
- true if the User was authenticated by an external system, otherwise false.
-
getLastPasswordChange
Return the date when the password has been changed the last time.- Returns:
- The date when the password has been changed the last time
-
setLastPasswordChange
Set the date when the password has been changed the last time.- Parameters:
lastPasswordChange
- The date when the password has been changed the last time
-
supplyLastPasswordChange
SupplylastPasswordChange
to the consumerc
if present.- Parameters:
c
- The consumer- Returns:
- This instance
-
isLocked
public boolean isLocked()Check if the User is locked.- Returns:
- true if locked, otherwise false
-
setLocked
public void setLocked(boolean locked) Lock the User.- Parameters:
locked
- true to lock the User, false to unlock
-
getPassword
Returns the current password of the User.- Returns:
- The current password as String
-
changePassword
public void changePassword(String encodedPassword, String rawPassword, org.springframework.security.crypto.password.PasswordEncoder encoder) throws InvalidPasswordException Checks if the new password is a valid and change the password of this User.- Parameters:
encodedPassword
- The new encoded password of this User- Throws:
InvalidPasswordException
- in case changing the password is not allowed or the new password is not valid
-
hasPasswordChanged
public boolean hasPasswordChanged()Checks whether the password is going to change.- Returns:
- true when
password
is different to the originally persisted one, otherwise false
-
validateAgainstPasswordHistory
protected void validateAgainstPasswordHistory(String rawPassword, org.springframework.security.crypto.password.PasswordEncoder encoder) throws InvalidPasswordException Check whether the new password is in the history of former passwords.- Parameters:
rawPassword
- The password to verify- Throws:
InvalidPasswordException
-
storeOldPassword
-
isEnabled
public boolean isEnabled()Determines whether the User is enabled or not.- Returns:
- true if the User is enabled, otherwise false
-
setEnabled
public void setEnabled(boolean enabled) Enable or disable the User.- Parameters:
enabled
- true when enabled, otherwise false
-
getExpirationDate
Return the date when the account expires.- Returns:
- The expiration date
-
setExpirationDate
Change the date when the account expires.- Parameters:
expDate
- The new expiration date to set
-
getRoles
Returns a list of grantedRole
s.- Returns:
- The list of granted
Role
s
-
supplyRoles
Supplyroles
to the consumerc
if present.- Parameters:
c
- The consumer- Returns:
- This instance
-
getGrants
- Returns:
- A list of all
Grant
s
-
supplyGrants
Supplygrants
to the consumerc
if present.- Parameters:
c
- The consumer- Returns:
- This instance
-
addRole
- Parameters:
role
- The newRole
to add- Returns:
- see
Collection.add(Object)
-
setRoles
- Parameters:
roles
- The new list ofRole
s
-
getFullname
Return the fullname of the User.- Returns:
- The current fullname
-
setFullname
Change the fullname of the User.- Parameters:
fullname
- The new fullname to set
-
setFullname
-
getEmailAddressesInternal
-
getEmailAddresses
-
setEmailAddresses
-
getPrimaryEmailAddress
-
supplyPrimaryEmailAddress
Supply the primaryemail
to the consumerc
if present.- Parameters:
c
- The consumer- Returns:
- This instance
-
getPasswords
Return a list of recently used passwords.- Returns:
- A list of recently used passwords
-
getUserDetails
Return the details of the User.- Returns:
- The userDetails
-
supplyUserDetails
SupplyuserDetails
to the consumerc
if present.- Parameters:
c
- The consumer- Returns:
- This instance
-
hasUserDetails
public boolean hasUserDetails()Check whether this User has UserDetails set.- Returns:
- true if set, otherwise false
-
setUserDetails
Assign some details to the User.- Parameters:
userDetails
- The userDetails to set
-
hashCode
public int hashCode()Does not call the superclass. Uses the username for calculation.
- Overrides:
hashCode
in classorg.ameba.integration.jpa.ApplicationEntity
- See Also:
-
equals
Uses the username for comparison.
- Overrides:
equals
in classorg.ameba.integration.jpa.ApplicationEntity
- See Also:
-
toString
-