@Service(value="blAdminSecurityService") public class AdminSecurityServiceImpl extends Object implements AdminSecurityService
Modifier and Type | Field and Description |
---|---|
protected AdminPermissionDao |
adminPermissionDao |
protected AdminRoleDao |
adminRoleDao |
protected AdminUserDao |
adminUserDao |
protected net.sf.ehcache.Cache |
cache |
protected static String |
CACHE_KEY_PREFIX |
protected static String |
CACHE_NAME |
protected EmailService |
emailService |
protected ForgotPasswordSecurityTokenDao |
forgotPasswordSecurityTokenDao |
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 EmailInfo |
resetPasswordEmailInfo |
protected String |
salt
Deprecated.
use
saltSource instead, 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 EmailInfo |
sendUsernameEmailInfo |
DEFAULT_PERMISSIONS
Constructor and Description |
---|
AdminSecurityServiceImpl() |
Modifier and Type | Method and Description |
---|---|
protected String |
buildCacheKey(AdminUser adminUser,
PermissionType permissionType,
String ceilingEntityFullyQualifiedName) |
AdminUser |
changePassword(PasswordChange passwordChange) |
GenericResponse |
changePassword(String username,
String oldPassword,
String password,
String confirmPassword)
Change a user's password only if oldPassword matches what's stored for that user
|
protected void |
checkExistingPassword(String unencodedPassword,
AdminUser user,
GenericResponse response) |
protected void |
checkPassword(String password,
String confirmPassword,
GenericResponse response) |
protected void |
checkUser(AdminUser user,
GenericResponse response) |
void |
clearAdminSecurityCache()
Clears the cache used for
AdminSecurityService.isUserQualifiedForOperationOnCeilingEntity(AdminUser, PermissionType, String) |
void |
deleteAdminPermission(AdminPermission permission) |
void |
deleteAdminRole(AdminRole role) |
void |
deleteAdminUser(AdminUser user) |
boolean |
doesOperationExistForCeilingEntity(PermissionType permissionType,
String ceilingEntityFullyQualifiedName) |
protected String |
encodePassword(String rawPassword)
Generate an encoded password from a raw password, salting is handled internally to the
PasswordEncoder . |
protected String |
encodePassword(String rawPassword,
Object salt)
Deprecated.
the new
PasswordEncoder handles salting internally, this will be removed in 4.2 |
protected String |
generateSecurePassword() |
static int |
getPASSWORD_TOKEN_LENGTH() |
EmailInfo |
getResetPasswordEmailInfo() |
protected String |
getResetPasswordURL() |
String |
getSalt()
Deprecated.
|
Object |
getSalt(AdminUser user,
String unencodedPassword)
Deprecated.
|
org.springframework.security.authentication.dao.SaltSource |
getSaltSource()
Deprecated.
|
EmailInfo |
getSendUsernameEmailInfo() |
protected int |
getTokenExpiredMinutes() |
protected void |
invalidateAllTokensForAdminUser(AdminUser user) |
protected boolean |
isPasswordValid(String encodedPassword,
String rawPassword)
Determines if a password is valid by comparing it to the encoded string, salting is handled internally to the
PasswordEncoder . |
protected boolean |
isPasswordValid(String encodedPassword,
String rawPassword,
Object salt)
Deprecated.
the new
PasswordEncoder handles salting internally, this will be removed in 4.2 |
protected boolean |
isTokenExpired(ForgotPasswordSecurityToken fpst) |
boolean |
isUserQualifiedForOperationOnCeilingEntity(AdminUser adminUser,
PermissionType permissionType,
String ceilingEntityFullyQualifiedName) |
AdminPermission |
readAdminPermissionById(Long id) |
AdminRole |
readAdminRoleById(Long id) |
AdminUser |
readAdminUserById(Long id) |
AdminUser |
readAdminUserByUserName(String userName) |
List<AdminUser> |
readAdminUsersByEmail(String email)
Returns a list of admin users that match the given email.
|
List<AdminPermission> |
readAllAdminPermissions() |
List<AdminRole> |
readAllAdminRoles() |
List<AdminUser> |
readAllAdminUsers() |
GenericResponse |
resetPasswordUsingToken(String username,
String token,
String password,
String confirmPassword)
Updates the password for the passed in user only if the passed
in token is valid for that user.
|
AdminPermission |
saveAdminPermission(AdminPermission permission) |
AdminRole |
saveAdminRole(AdminRole role) |
AdminUser |
saveAdminUser(AdminUser user) |
GenericResponse |
sendForgotUsernameNotification(String emailAddress)
Looks up the corresponding AdminUser and emails the address on file with
the associated username.
|
GenericResponse |
sendResetPasswordNotification(String username)
Generates an access token and then emails the user.
|
static void |
setPASSWORD_TOKEN_LENGTH(int PASSWORD_TOKEN_LENGTH) |
void |
setResetPasswordEmailInfo(EmailInfo resetPasswordEmailInfo) |
void |
setSalt(String salt)
Deprecated.
|
void |
setSaltSource(org.springframework.security.authentication.dao.SaltSource saltSource)
Deprecated.
|
void |
setSendUsernameEmailInfo(EmailInfo sendUsernameEmailInfo) |
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 AdminRoleDao adminRoleDao
protected AdminUserDao adminUserDao
protected ForgotPasswordSecurityTokenDao forgotPasswordSecurityTokenDao
protected AdminPermissionDao adminPermissionDao
@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 static String CACHE_NAME
protected static String CACHE_KEY_PREFIX
protected net.sf.ehcache.Cache cache
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, this will be removed in 4.2@Deprecated @Autowired(required=false) @Qualifier(value="blAdminSaltSource") protected org.springframework.security.authentication.dao.SaltSource saltSource
PasswordEncoder
handles salting internally, this will be removed in 4.2protected EmailService emailService
protected EmailInfo resetPasswordEmailInfo
protected EmailInfo sendUsernameEmailInfo
@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".
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 PasswordEncoderprotected int getTokenExpiredMinutes()
protected String getResetPasswordURL()
@Transactional(value="blTransactionManager") public void deleteAdminPermission(AdminPermission permission)
deleteAdminPermission
in interface AdminSecurityService
@Transactional(value="blTransactionManager") public void deleteAdminRole(AdminRole role)
deleteAdminRole
in interface AdminSecurityService
@Transactional(value="blTransactionManager") public void deleteAdminUser(AdminUser user)
deleteAdminUser
in interface AdminSecurityService
public AdminPermission readAdminPermissionById(Long id)
readAdminPermissionById
in interface AdminSecurityService
public AdminRole readAdminRoleById(Long id)
readAdminRoleById
in interface AdminSecurityService
public AdminUser readAdminUserById(Long id)
readAdminUserById
in interface AdminSecurityService
@Transactional(value="blTransactionManager") public AdminPermission saveAdminPermission(AdminPermission permission)
saveAdminPermission
in interface AdminSecurityService
@Transactional(value="blTransactionManager") public AdminRole saveAdminRole(AdminRole role)
saveAdminRole
in interface AdminSecurityService
@Transactional(value="blTransactionManager") public AdminUser saveAdminUser(AdminUser user)
saveAdminUser
in interface AdminSecurityService
public void clearAdminSecurityCache()
AdminSecurityService
AdminSecurityService.isUserQualifiedForOperationOnCeilingEntity(AdminUser, PermissionType, String)
clearAdminSecurityCache
in interface AdminSecurityService
protected String generateSecurePassword()
@Transactional(value="blTransactionManager") public AdminUser changePassword(PasswordChange passwordChange)
changePassword
in interface AdminSecurityService
public boolean isUserQualifiedForOperationOnCeilingEntity(AdminUser adminUser, PermissionType permissionType, String ceilingEntityFullyQualifiedName)
isUserQualifiedForOperationOnCeilingEntity
in interface AdminSecurityService
protected String buildCacheKey(AdminUser adminUser, PermissionType permissionType, String ceilingEntityFullyQualifiedName)
public boolean doesOperationExistForCeilingEntity(PermissionType permissionType, String ceilingEntityFullyQualifiedName)
doesOperationExistForCeilingEntity
in interface AdminSecurityService
public AdminUser readAdminUserByUserName(String userName)
readAdminUserByUserName
in interface AdminSecurityService
public List<AdminUser> readAdminUsersByEmail(String email)
AdminSecurityService
readAdminUsersByEmail
in interface AdminSecurityService
email
- the email address to search forList
of AdminUser
matching the provided email addresspublic List<AdminUser> readAllAdminUsers()
readAllAdminUsers
in interface AdminSecurityService
public List<AdminRole> readAllAdminRoles()
readAllAdminRoles
in interface AdminSecurityService
public List<AdminPermission> readAllAdminPermissions()
readAllAdminPermissions
in interface AdminSecurityService
@Transactional(value="blTransactionManager") public GenericResponse sendForgotUsernameNotification(String emailAddress)
AdminSecurityService
sendForgotUsernameNotification
in interface AdminSecurityService
emailAddress
- email address of user to email@Transactional(value="blTransactionManager") public GenericResponse sendResetPasswordNotification(String username)
AdminSecurityService
sendResetPasswordNotification
in interface AdminSecurityService
username
- the username of the user to send a password reset email@Transactional(value="blTransactionManager") public GenericResponse resetPasswordUsingToken(String username, String token, String password, String confirmPassword)
AdminSecurityService
resetPasswordUsingToken
in interface AdminSecurityService
username
- the username of the usertoken
- a valid reset token from the emailpassword
- the new desired passwordconfirmPassword
- the password confirmation to match passwordprotected void invalidateAllTokensForAdminUser(AdminUser user)
protected void checkUser(AdminUser user, GenericResponse response)
protected void checkPassword(String password, String confirmPassword, GenericResponse response)
protected void checkExistingPassword(String unencodedPassword, AdminUser user, GenericResponse response)
protected boolean isTokenExpired(ForgotPasswordSecurityToken fpst)
public static int getPASSWORD_TOKEN_LENGTH()
public static void setPASSWORD_TOKEN_LENGTH(int PASSWORD_TOKEN_LENGTH)
public EmailInfo getSendUsernameEmailInfo()
public void setSendUsernameEmailInfo(EmailInfo sendUsernameEmailInfo)
public EmailInfo getResetPasswordEmailInfo()
public void setResetPasswordEmailInfo(EmailInfo resetPasswordEmailInfo)
@Deprecated public Object getSalt(AdminUser user, String unencodedPassword)
AdminSecurityService
AdminSecurityService.getSaltSource()
. If there is
not a SaltSource
configured (AdminSecurityService.getSaltSource()
returns null) then this also returns null.getSalt
in interface AdminSecurityService
user
- the AdminUser
to get UserDetails
fromunencodedPassword
- the unencoded password@Deprecated public String getSalt()
getSalt
in interface AdminSecurityService
@Deprecated public void setSalt(String salt)
setSalt
in interface AdminSecurityService
salt
- the new salt string to use@Deprecated public org.springframework.security.authentication.dao.SaltSource getSaltSource()
AdminSecurityService
SaltSource
used with the blAdminPasswordEncoder to encrypt the user password. Usually configured in
applicationContext-admin-security.xml. This is not a required property and will return null if not configuredgetSaltSource
in interface AdminSecurityService
SaltSource
@Deprecated public void setSaltSource(org.springframework.security.authentication.dao.SaltSource saltSource)
AdminSecurityService
SaltSource
used with blAdminPasswordEncoder to encrypt the user password. Usually configured within
applicationContext-admin-security.xmlsetSaltSource
in interface AdminSecurityService
saltSource
- the new SaltSource
to use@Transactional(value="blTransactionManager") public GenericResponse changePassword(String username, String oldPassword, String password, String confirmPassword)
AdminSecurityService
changePassword
in interface AdminSecurityService
username
- the username to change the password foroldPassword
- the user's current passwordpassword
- the desired new passwordconfirmPassword
- the confirm password to ensure it matches password@Deprecated protected boolean isPasswordValid(String encodedPassword, String rawPassword, Object salt)
PasswordEncoder
handles salting internally, this will be removed in 4.2
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
.
encodedPassword
- the encoded passwordrawPassword
- the unencoded passwordsalt
- the optional saltprotected boolean isPasswordValid(String encodedPassword, String rawPassword)
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.
encodedPassword
- the encoded passwordrawPassword
- the raw password to check against the encoded password@Deprecated protected String encodePassword(String rawPassword, Object salt)
PasswordEncoder
handles salting internally, this will be removed in 4.2
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
.
rawPassword
- salt
- protected String encodePassword(String rawPassword)
PasswordEncoder
.
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 isPasswordValid(String, String)
as encoding the
same password twice will result in different encoded passwords.
rawPassword
- the unencoded password to encode@Deprecated protected boolean usingDeprecatedPasswordEncoder()
Copyright © 2019. All rights reserved.