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
Nested ClassesModifier and TypeClassDescription(package private) static classA PasswordComparator sorts UserPassword by date ascending. -
Field Summary
FieldsModifier and TypeFieldDescriptionEmail addresses.private booleantrueif the User is enabled.private ZonedDateTimeDate when the account expires.private booleantrueif the User is authenticated by an external system, otherwisefalse.private StringThe User's fullname (doesn't have to be unique).private ZonedDateTimeDate of the last password change.private booleantrueif this User is locked and has no permission to login.private static final org.slf4j.Loggerstatic final shortThe number of passwords to keep in the password history.private StringThe User's current password (only kept transient).private List<UserPassword> Last passwords of the User.private StringThe User's current password.List ofRoles assigned to the User.private UserDetailsMore detail information of the User.private @NotEmpty StringUnique identifier of this User (not nullable).Fields inherited from class org.ameba.integration.jpa.ApplicationEntity
C_ID -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddNewEmailAddress(Email email) booleanvoidchangePassword(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.booleanReturn 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 grantedRoles.Return the details of the User.Return the unique username of the User.inthashCode()booleanChecks whether the password is going to change.booleanCheck whether this User has UserDetails set.booleanDetermines whether the User is enabled or not.booleanIs the User authenticated by an external system?booleanisLocked()Check if the User is locked.protected voidloadLazy()voidpostLoad()After load, the saved password is copied to the transient one.booleanremoveEmailAddress(Email email) voidsetEmailAddresses(Set<Email> emailAddresses) voidsetEnabled(boolean enabled) Enable or disable the User.voidsetExpirationDate(ZonedDateTime expDate) Change the date when the account expires.voidsetExternalUser(boolean externalUser) Change the authentication method of the User.voidsetFullname(String fullname) Change the fullname of the User.voidsetLastPasswordChange(ZonedDateTime lastPasswordChange) Set the date when the password has been changed the last time.voidsetLocked(boolean locked) Lock the User.voidsetOl(long ol) voidsetPersistentKey(String pKey) voidSet theRoles of this User.voidsetUserDetails(UserDetails userDetails) Assign some details to the User.voidsetUsername(String username) Change the username of the User.private voidstoreOldPassword(String oldPassword) Supplygrantsto the consumercif present.SupplylastPasswordChangeto the consumercif present.Supply the primaryemailto the consumercif present.supplyRoles(Consumer<List<Role>> c) Supplyrolesto the consumercif present.SupplyuserDetailsto the consumercif present.toString()protected voidvalidateAgainstPasswordHistory(String rawPassword, org.springframework.security.crypto.password.PasswordEncoder encoder) Check whether the new password is in the history of former passwords.voidSet thepasswordandpersistedPasswordto null.Methods inherited from class org.ameba.integration.jpa.ApplicationEntity
getPersistentKey, hasPersistentKey, onEntityPersist, onPersistMethods 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 externtrueif the User is authenticated by an external system, otherwisefalse. -
lastPasswordChange
Date of the last password change. -
locked
private boolean lockedtrueif 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 enabledtrueif 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 ofRoles 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:
setPersistentKeyin classorg.ameba.integration.jpa.ApplicationEntity
-
setOl
public void setOl(long ol) - Overrides:
setOlin classorg.ameba.integration.jpa.BaseEntity
-
wipePassword
public void wipePassword()Set thepasswordandpersistedPasswordto 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
SupplylastPasswordChangeto the consumercif 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
passwordis 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 grantedRoles.- Returns:
- The list of granted
Roles
-
supplyRoles
Supplyrolesto the consumercif present.- Parameters:
c- The consumer- Returns:
- This instance
-
getGrants
- Returns:
- A list of all
Grants
-
supplyGrants
Supplygrantsto the consumercif present.- Parameters:
c- The consumer- Returns:
- This instance
-
addRole
- Parameters:
role- The newRoleto add- Returns:
- see
Collection.add(Object)
-
setRoles
- Parameters:
roles- The new list ofRoles
-
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 primaryemailto the consumercif 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
SupplyuserDetailsto the consumercif 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:
hashCodein classorg.ameba.integration.jpa.ApplicationEntity- See Also:
-
equals
Uses the username for comparison.
- Overrides:
equalsin classorg.ameba.integration.jpa.ApplicationEntity- See Also:
-
toString
-