@Service(value="blCustomerService") public class CustomerServiceImpl extends Object implements CustomerService
Modifier and Type | Field and Description |
---|---|
protected EmailInfo |
changePasswordEmailInfo |
protected CustomerDao |
customerDao |
protected CustomerForgotPasswordSecurityTokenDao |
customerForgotPasswordSecurityTokenDao |
protected EmailService |
emailService |
protected EmailInfo |
forgotPasswordEmailInfo |
protected EmailInfo |
forgotUsernameEmailInfo |
protected IdGenerationService |
idGenerationService |
protected List<PasswordUpdatedHandler> |
passwordChangedHandlers |
protected org.springframework.security.authentication.encoding.PasswordEncoder |
passwordEncoder
Deprecated.
Spring Security has deprecated this encoder interface, this will be removed in 4.2
|
protected Object |
passwordEncoderBean
This is simply a placeholder to be used by
setupPasswordEncoder() to determine if we're using the
new PasswordEncoder or the deprecated PasswordEncoder |
protected org.springframework.security.crypto.password.PasswordEncoder |
passwordEncoderNew
Set by
setupPasswordEncoder() if the blPasswordEncoder bean provided is the new version. |
protected List<PasswordUpdatedHandler> |
passwordResetHandlers |
protected int |
passwordTokenLength |
protected List<PostRegistrationObserver> |
postRegisterListeners |
protected EmailInfo |
registrationEmailInfo |
protected RoleDao |
roleDao |
protected String |
salt
Deprecated.
utilize
saltSource instead so that it can be shared between this class as well as Spring's
authentication manager, this will be removed in 4.2 |
protected org.springframework.security.authentication.dao.SaltSource |
saltSource
Deprecated.
the new
PasswordEncoder handles salting internally, this will be removed in 4.2 |
protected int |
tokenExpiredMinutes |
Constructor and Description |
---|
CustomerServiceImpl() |
Modifier and Type | Method and Description |
---|---|
void |
addPostRegisterListener(PostRegistrationObserver postRegisterListeners) |
Customer |
changePassword(PasswordChange passwordChange) |
protected void |
checkCustomer(Customer customer,
GenericResponse response) |
protected void |
checkPassword(String password,
String confirmPassword,
GenericResponse response) |
GenericResponse |
checkPasswordResetToken(String token)
Deprecated.
|
GenericResponse |
checkPasswordResetToken(String token,
Customer customer)
Verifies that a customer has a valid token.
|
protected CustomerForgotPasswordSecurityToken |
checkPasswordResetToken(String token,
Customer customer,
GenericResponse response) |
Customer |
createCustomer() |
Customer |
createCustomerFromId(Long customerId)
|
Customer |
createNewCustomer()
Returns a non-persisted
Customer . |
void |
createRegisteredCustomerRoles(Customer customer)
Subclassed implementations can assign unique roles for various customer types
|
void |
deleteCustomer(Customer customer)
Delete the customer entity from the persistent store
|
protected String |
encodePass(String rawPassword,
Object salt)
Deprecated.
the new
PasswordEncoder handles salting internally, this will be removed in 4.2 |
String |
encodePassword(String rawPassword)
Encodes the clear text parameter, using the salt provided by PasswordEncoder.
|
String |
encodePassword(String rawPassword,
Customer customer)
Deprecated.
|
Long |
findNextCustomerId()
Allow customers to call from subclassed service.
|
protected String |
generateSecurePassword() |
EmailInfo |
getChangePasswordEmailInfo() |
EmailInfo |
getForgotPasswordEmailInfo() |
EmailInfo |
getForgotUsernameEmailInfo() |
List<PasswordUpdatedHandler> |
getPasswordChangedHandlers() |
List<PasswordUpdatedHandler> |
getPasswordResetHandlers() |
int |
getPasswordTokenLength() |
EmailInfo |
getRegistrationEmailInfo() |
String |
getSalt()
Deprecated.
|
Object |
getSalt(Customer customer)
Deprecated.
|
Object |
getSalt(Customer customer,
String unencodedPassword)
Deprecated.
|
org.springframework.security.authentication.dao.SaltSource |
getSaltSource()
Deprecated.
|
int |
getTokenExpiredMinutes() |
protected void |
invalidateAllTokensForCustomer(Customer customer) |
protected boolean |
isPassValid(String rawPassword,
String encodedPassword,
Object salt)
Deprecated.
the new
PasswordEncoder handles salting internally, this will be removed in 4.2 |
boolean |
isPasswordValid(String rawPassword,
String encodedPassword)
Determines if a password is valid by comparing it to the encoded string, salting is handled internally to the
PasswordEncoder . |
boolean |
isPasswordValid(String rawPassword,
String encodedPassword,
Customer customer)
Deprecated.
|
protected boolean |
isTokenExpired(CustomerForgotPasswordSecurityToken fpst) |
protected void |
notifyPostRegisterListeners(Customer customer) |
Customer |
readCustomerByEmail(String emailAddress) |
Customer |
readCustomerById(Long id) |
Customer |
readCustomerByUsername(String username) |
Customer |
readCustomerByUsername(String username,
Boolean cacheable) |
Customer |
registerCustomer(Customer customer,
String password,
String passwordConfirm) |
void |
removePostRegisterListener(PostRegistrationObserver postRegisterListeners) |
Customer |
resetPassword(PasswordReset passwordReset) |
GenericResponse |
resetPasswordUsingToken(String username,
String token,
String password,
String confirmPassword)
Updates the password for the passed in customer only if the passed
in token is valid for that customer.
|
Customer |
saveCustomer(Customer customer) |
Customer |
saveCustomer(Customer customer,
boolean register) |
GenericResponse |
sendForgotPasswordNotification(String username,
String resetPasswordUrl)
Generates an access token and then emails the user.
|
GenericResponse |
sendForgotUsernameNotification(String emailAddress)
Looks up the corresponding
Customer and emails the address on file with
the associated username. |
void |
setChangePasswordEmailInfo(EmailInfo changePasswordEmailInfo) |
void |
setCustomerDao(CustomerDao customerDao) |
void |
setForgotPasswordEmailInfo(EmailInfo forgotPasswordEmailInfo) |
void |
setForgotUsernameEmailInfo(EmailInfo forgotUsernameEmailInfo) |
void |
setPasswordChangedHandlers(List<PasswordUpdatedHandler> passwordChangedHandlers) |
void |
setPasswordEncoder(Object passwordEncoder)
Set the passwordEncoder to be used by this class.
|
void |
setPasswordResetHandlers(List<PasswordUpdatedHandler> passwordResetHandlers) |
void |
setPasswordTokenLength(int passwordTokenLength) |
void |
setRegistrationEmailInfo(EmailInfo registrationEmailInfo) |
void |
setSalt(String salt)
Deprecated.
|
void |
setSaltSource(org.springframework.security.authentication.dao.SaltSource saltSource)
Deprecated.
|
void |
setTokenExpiredMinutes(int tokenExpiredMinutes) |
protected void |
setupPasswordEncoder()
Sets either
passwordEncoder or passwordEncoderNew based on the type of passwordEncoderBean
in order to provide bean configuration backwards compatibility with the deprecated PasswordEncoder bean. |
protected boolean |
usingDeprecatedPasswordEncoder()
Deprecated.
|
protected CustomerDao customerDao
protected IdGenerationService idGenerationService
protected CustomerForgotPasswordSecurityTokenDao customerForgotPasswordSecurityTokenDao
@Deprecated protected org.springframework.security.authentication.encoding.PasswordEncoder passwordEncoder
Set by setupPasswordEncoder()
if the blPasswordEncoder bean provided is the deprecated version.
protected org.springframework.security.crypto.password.PasswordEncoder passwordEncoderNew
Set by setupPasswordEncoder()
if the blPasswordEncoder bean provided is the new version.
protected Object passwordEncoderBean
This is simply a placeholder to be used by setupPasswordEncoder()
to determine if we're using the
new PasswordEncoder
or the deprecated PasswordEncoder
@Deprecated protected String salt
saltSource
instead so that it can be shared between this class as well as Spring's
authentication manager, this will be removed in 4.2@Deprecated @Autowired(required=false) @Qualifier(value="blSaltSource") protected org.springframework.security.authentication.dao.SaltSource saltSource
PasswordEncoder
handles salting internally, this will be removed in 4.2protected RoleDao roleDao
protected EmailService emailService
protected EmailInfo forgotPasswordEmailInfo
protected EmailInfo forgotUsernameEmailInfo
protected EmailInfo registrationEmailInfo
protected EmailInfo changePasswordEmailInfo
protected int tokenExpiredMinutes
protected int passwordTokenLength
protected final List<PostRegistrationObserver> postRegisterListeners
protected List<PasswordUpdatedHandler> passwordResetHandlers
protected List<PasswordUpdatedHandler> passwordChangedHandlers
@PostConstruct protected void setupPasswordEncoder()
Sets either passwordEncoder
or passwordEncoderNew
based on the type of passwordEncoderBean
in order to provide bean configuration backwards compatibility with the deprecated PasswordEncoder
bean.
passwordEncoderBean
is set by the bean defined as "blPasswordEncoder" and can be changed with setPasswordEncoder(Object)
.
This class will utilize either the new or deprecated PasswordEncoder type depending on which is not null.
org.springframework.beans.factory.NoSuchBeanDefinitionException
- if passwordEncoderBean
is null or not an instance of either PasswordEncoder@Transactional(value="blTransactionManager") public Customer saveCustomer(Customer customer)
saveCustomer
in interface CustomerService
@Transactional(value="blTransactionManager") public Customer saveCustomer(Customer customer, boolean register)
saveCustomer
in interface CustomerService
protected String generateSecurePassword()
@Transactional(value="blTransactionManager") public Customer registerCustomer(Customer customer, String password, String passwordConfirm)
registerCustomer
in interface CustomerService
public void createRegisteredCustomerRoles(Customer customer)
CustomerService
createRegisteredCustomerRoles
in interface CustomerService
customer
- Customer
to create roles forpublic Customer readCustomerByEmail(String emailAddress)
readCustomerByEmail
in interface CustomerService
@Transactional(value="blTransactionManager") public Customer changePassword(PasswordChange passwordChange)
changePassword
in interface CustomerService
@Transactional(value="blTransactionManager") public Customer resetPassword(PasswordReset passwordReset)
resetPassword
in interface CustomerService
public void addPostRegisterListener(PostRegistrationObserver postRegisterListeners)
addPostRegisterListener
in interface CustomerService
public void removePostRegisterListener(PostRegistrationObserver postRegisterListeners)
removePostRegisterListener
in interface CustomerService
protected void notifyPostRegisterListeners(Customer customer)
public Customer createCustomer()
createCustomer
in interface CustomerService
public Customer createCustomerFromId(Long customerId)
CustomerService
Customer
by first looking in the database, otherwise creating a new non-persisted Customer
createCustomerFromId
in interface CustomerService
customerId
- the id of the customer to lookuppublic Long findNextCustomerId()
CustomerService
findNextCustomerId
in interface CustomerService
public Customer createNewCustomer()
CustomerService
Customer
. Typically used with registering a new customer.createNewCustomer
in interface CustomerService
public void deleteCustomer(Customer customer)
CustomerService
deleteCustomer
in interface CustomerService
customer
- the customer entity to removepublic Customer readCustomerByUsername(String username)
readCustomerByUsername
in interface CustomerService
public Customer readCustomerByUsername(String username, Boolean cacheable)
readCustomerByUsername
in interface CustomerService
public Customer readCustomerById(Long id)
readCustomerById
in interface CustomerService
public void setCustomerDao(CustomerDao customerDao)
public void setPasswordEncoder(Object passwordEncoder)
Set the passwordEncoder to be used by this class.
This method will indirectly set one of the two PasswordEncoder member variables, depending on its type
by calling setupPasswordEncoder()
passwordEncoder
- Either Spring Security's new PasswordEncoder
, or the deprecated PasswordEncoder
@Deprecated public Object getSalt(Customer customer)
getSalt
in interface CustomerService
@Deprecated public Object getSalt(Customer customer, String unencodedPassword)
CustomerService
CustomerService.getSaltSource()
. If there is
not a SaltSource
configured (CustomerService.getSaltSource()
returns null) then this also returns null.getSalt
in interface CustomerService
customer
- the Customer
to get UserDetails
fromunencodedPassword
- the unencoded password@Deprecated protected String encodePass(String rawPassword, Object salt)
PasswordEncoder
handles salting internally, this will be removed in 4.2PasswordEncoder
or the deprecated PasswordEncoder
.rawPassword
- the unencoded passwordsalt
- the optional salt@Deprecated public String encodePassword(String rawPassword, Customer customer)
CustomerService
The externally salted PasswordEncoder
support is
being deprecated, following in Spring Security's footsteps, in order to move towards self salting hashing algorithms such as bcrypt.
Bcrypt is a superior hashing algorithm that randomly generates a salt per password in order to protect against rainbow table attacks
and is an intentionally expensive algorithm to further guard against brute force attempts to crack hashed passwords.
Additionally, having the encoding algorithm handle the salt internally reduces code complexity and dependencies such as SaltSource
.
encodePassword
in interface CustomerService
rawPassword
- the unencoded passwordcustomer
- the Customer
to use for the saltpublic String encodePassword(String rawPassword)
CustomerService
This method can only be called once per password. The salt is randomly generated internally in the PasswordEncoder
and appended to the hash to provide the resulting encoded password. Once this has been called on a password,
going forward all checks for authenticity must be done by CustomerService.isPasswordValid(String, String)
as encoding the
same password twice will result in different encoded passwords.
encodePassword
in interface CustomerService
rawPassword
- the unencoded password@Deprecated protected boolean isPassValid(String rawPassword, String encodedPassword, Object salt)
PasswordEncoder
handles salting internally, this will be removed in 4.2PasswordEncoder
or the deprecated PasswordEncoder
.rawPassword
- the unencoded passwordencodedPassword
- the encoded password to compare rawPassword againstsalt
- the optional salt@Deprecated public boolean isPasswordValid(String rawPassword, String encodedPassword, Customer customer)
CustomerService
Customer
for salting. Don't encode the password separately since sometimes salts
are generated randomly and stored with the password.
The externally salted PasswordEncoder
support is
being deprecated, following in Spring Security's footsteps, in order to move towards self salting hashing algorithms such as bcrypt.
Bcrypt is a superior hashing algorithm that randomly generates a salt per password in order to protect against rainbow table attacks
and is an intentionally expensive algorithm to further guard against brute force attempts to crack hashed passwords.
Additionally, having the encoding algorithm handle the salt internally reduces code complexity and dependencies such as SaltSource
.
isPasswordValid
in interface CustomerService
rawPassword
- the unencoded passwordencodedPassword
- the encoded password to compare againstcustomer
- the Customer
to use for the saltpublic boolean isPasswordValid(String rawPassword, String encodedPassword)
CustomerService
PasswordEncoder
.
This method must always be called to verify if a password is valid after the original encoded password is generated
due to PasswordEncoder
randomly generating salts internally and appending them to the resulting hash.
isPasswordValid
in interface CustomerService
rawPassword
- the unencoded passwordencodedPassword
- the encoded password to compare against@Deprecated public String getSalt()
getSalt
in interface CustomerService
@Deprecated public void setSalt(String salt)
setSalt
in interface CustomerService
salt
- new salt string to use@Deprecated public org.springframework.security.authentication.dao.SaltSource getSaltSource()
CustomerService
SaltSource
used with the blPasswordEncoder to encrypt the user password. Usually configured in
applicationContext-security.xml. This is not a required property and will return null if not configuredgetSaltSource
in interface CustomerService
SaltSource
@Deprecated public void setSaltSource(org.springframework.security.authentication.dao.SaltSource saltSource)
CustomerService
SaltSource
used with blPasswordEncoder to encrypt the user password. Usually configured within
applicationContext-security.xmlsetSaltSource
in interface CustomerService
saltSource
- the new SaltSource
to usepublic List<PasswordUpdatedHandler> getPasswordResetHandlers()
getPasswordResetHandlers
in interface CustomerService
public void setPasswordResetHandlers(List<PasswordUpdatedHandler> passwordResetHandlers)
setPasswordResetHandlers
in interface CustomerService
public List<PasswordUpdatedHandler> getPasswordChangedHandlers()
getPasswordChangedHandlers
in interface CustomerService
public void setPasswordChangedHandlers(List<PasswordUpdatedHandler> passwordChangedHandlers)
setPasswordChangedHandlers
in interface CustomerService
@Transactional(value="blTransactionManager") public GenericResponse sendForgotUsernameNotification(String emailAddress)
CustomerService
Customer
and emails the address on file with
the associated username.sendForgotUsernameNotification
in interface CustomerService
emailAddress
- user's email address@Transactional(value="blTransactionManager") public GenericResponse sendForgotPasswordNotification(String username, String resetPasswordUrl)
CustomerService
sendForgotPasswordNotification
in interface CustomerService
username
- - the user to send a reset password email to.resetPasswordUrl
- - Base url to include in the email.@Deprecated public GenericResponse checkPasswordResetToken(String token)
CustomerService
This method can only be used when using the deprecated PasswordEncoder
bean, otherwise an exception will be thrown.
The new PasswordEncoder
bean requires passing in a Customer to find the appropriate token.
checkPasswordResetToken
in interface CustomerService
token
- password reset tokenpublic GenericResponse checkPasswordResetToken(String token, Customer customer)
CustomerService
checkPasswordResetToken
in interface CustomerService
token
- password reset tokencustomer
- Customer
who owns the tokenprotected CustomerForgotPasswordSecurityToken checkPasswordResetToken(String token, Customer customer, GenericResponse response)
@Transactional(value="blTransactionManager") public GenericResponse resetPasswordUsingToken(String username, String token, String password, String confirmPassword)
CustomerService
resetPasswordUsingToken
in interface CustomerService
username
- Username of the customertoken
- Valid reset tokenpassword
- new passwordprotected void invalidateAllTokensForCustomer(Customer customer)
protected void checkCustomer(Customer customer, GenericResponse response)
protected void checkPassword(String password, String confirmPassword, GenericResponse response)
protected boolean isTokenExpired(CustomerForgotPasswordSecurityToken fpst)
public int getTokenExpiredMinutes()
public void setTokenExpiredMinutes(int tokenExpiredMinutes)
public int getPasswordTokenLength()
public void setPasswordTokenLength(int passwordTokenLength)
public EmailInfo getForgotPasswordEmailInfo()
public void setForgotPasswordEmailInfo(EmailInfo forgotPasswordEmailInfo)
public EmailInfo getForgotUsernameEmailInfo()
public void setForgotUsernameEmailInfo(EmailInfo forgotUsernameEmailInfo)
public EmailInfo getRegistrationEmailInfo()
public void setRegistrationEmailInfo(EmailInfo registrationEmailInfo)
public EmailInfo getChangePasswordEmailInfo()
public void setChangePasswordEmailInfo(EmailInfo changePasswordEmailInfo)
@Deprecated protected boolean usingDeprecatedPasswordEncoder()
Copyright © 2020. All rights reserved.