Class UserServiceImpl
- java.lang.Object
-
- org.craftercms.studio.impl.v2.service.security.UserServiceImpl
-
- All Implemented Interfaces:
UserService
public class UserServiceImpl extends Object implements UserService
-
-
Constructor Summary
Constructors Constructor Description UserServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description User
changePassword(String username, String current, String newPassword)
User changes passwordUser
createUser(User user)
protected String
decryptToken(String hashedToken)
Map<String,String>
deleteUserProperties(String siteId, List<String> propertiesToDelete)
Delete properties for the given site & current uservoid
deleteUsers(List<Long> userIds, List<String> usernames)
List<User>
enableUsers(List<Long> userIds, List<String> usernames, boolean enabled)
boolean
forgotPassword(String username)
Forgot password feature for given usernameList<User>
getAllUsers(String keyword, int offset, int limit, String sort)
Get paginated list of all users filtered by keywordList<User>
getAllUsersForSite(long orgId, String siteId, String keyword, int offset, int limit, String sort)
Get paginated list of all users for site filtered by keywordint
getAllUsersForSiteTotal(long orgId, String siteId, String keyword)
Get total number of users for site filtered by keywordint
getAllUsersTotal(String keyword)
Get total number of users filtered by keywordAuthenticatedUser
getCurrentUser()
List<String>
getCurrentUserGlobalPermissions()
Get global permissions of the current authenticated userList<String>
getCurrentUserSitePermissions(String site)
Get permissions of the current authenticated user for given siteList<String>
getCurrentUserSiteRoles(String site)
List<Site>
getCurrentUserSites()
User
getUserByIdOrUsername(long userId, String username)
Map<String,Map<String,String>>
getUserProperties(String siteId)
Get the properties for the given site & the current userList<String>
getUserSiteRoles(long userId, String username, String site)
List<Site>
getUserSites(long userId, String username)
Map<String,Boolean>
hasCurrentUserGlobalPermissions(List<String> permissions)
Check if the current authenticated user has given global permissionsMap<String,Boolean>
hasCurrentUserSitePermissions(String site, List<String> permissions)
Check if the current authenticated user has given permissions for given siteboolean
resetPassword(String username, String newPassword)
Admin resets the user passwordvoid
setAuditServiceInternal(AuditServiceInternal auditServiceInternal)
void
setConfigurationService(ConfigurationService configurationService)
void
setEmailService(org.springframework.mail.javamail.JavaMailSender emailService)
void
setEmailServiceNoAuth(org.springframework.mail.javamail.JavaMailSender emailServiceNoAuth)
void
setEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor)
void
setEntitlementValidator(org.craftercms.commons.entitlements.validator.EntitlementValidator entitlementValidator)
void
setFreeMarkerConfig(org.springframework.beans.factory.ObjectFactory<org.springframework.web.servlet.view.freemarker.FreeMarkerConfig> freeMarkerConfig)
void
setGeneralLockService(GeneralLockService generalLockService)
void
setGroupServiceInternal(GroupServiceInternal groupServiceInternal)
void
setInstanceService(InstanceService instanceService)
User
setPassword(String token, String newPassword)
Set user password - forgot password tokenvoid
setSecurityService(SecurityService securityService)
void
setSecurityServiceV2(SecurityService securityServiceV2)
void
setSessionRegistry(org.springframework.security.core.session.SessionRegistry sessionRegistry)
void
setSiteService(SiteService siteService)
void
setStudioConfiguration(StudioConfiguration studioConfiguration)
void
setUserServiceInternal(UserServiceInternal userServiceInternal)
void
updateUser(User user)
Map<String,String>
updateUserProperties(String siteId, Map<String,String> propertiesToUpdate)
Update or add properties for the given site & the current userprotected boolean
validateDecryptedToken(String decryptedToken)
boolean
validateToken(String token)
Validate forgot password token
-
-
-
Method Detail
-
getAllUsersForSite
public List<User> getAllUsersForSite(long orgId, String siteId, String keyword, int offset, int limit, String sort) throws ServiceLayerException
Description copied from interface:UserService
Get paginated list of all users for site filtered by keyword- Specified by:
getAllUsersForSite
in interfaceUserService
- Parameters:
orgId
- organization identifiersiteId
- site identifierkeyword
- keyword to filter usersoffset
- offset for paginationlimit
- limit number of users to return per pagesort
- sort order- Returns:
- requested page of list of users
- Throws:
ServiceLayerException
-
getAllUsers
public List<User> getAllUsers(String keyword, int offset, int limit, String sort) throws ServiceLayerException
Description copied from interface:UserService
Get paginated list of all users filtered by keyword- Specified by:
getAllUsers
in interfaceUserService
- Parameters:
keyword
- keyword to filter usersoffset
- offset for paginationlimit
- limit number of users to return per pagesort
- sort order- Returns:
- requested page of list of users
- Throws:
ServiceLayerException
-
getAllUsersForSiteTotal
public int getAllUsersForSiteTotal(long orgId, String siteId, String keyword) throws ServiceLayerException
Description copied from interface:UserService
Get total number of users for site filtered by keyword- Specified by:
getAllUsersForSiteTotal
in interfaceUserService
- Parameters:
orgId
- organization identifiersiteId
- site identifierkeyword
- keyword to filter users- Returns:
- total number of users for site filtered by keyword
- Throws:
ServiceLayerException
-
getAllUsersTotal
public int getAllUsersTotal(String keyword) throws ServiceLayerException
Description copied from interface:UserService
Get total number of users filtered by keyword- Specified by:
getAllUsersTotal
in interfaceUserService
- Parameters:
keyword
- keyword to filter user- Returns:
- total number of users filtered by keyword
- Throws:
ServiceLayerException
-
createUser
public User createUser(User user) throws UserAlreadyExistsException, ServiceLayerException, AuthenticationException
- Specified by:
createUser
in interfaceUserService
- Throws:
UserAlreadyExistsException
ServiceLayerException
AuthenticationException
-
updateUser
public void updateUser(User user) throws ServiceLayerException, UserNotFoundException, AuthenticationException, UserExternallyManagedException
- Specified by:
updateUser
in interfaceUserService
- Throws:
ServiceLayerException
UserNotFoundException
AuthenticationException
UserExternallyManagedException
-
deleteUsers
public void deleteUsers(List<Long> userIds, List<String> usernames) throws ServiceLayerException, AuthenticationException, UserNotFoundException, UserExternallyManagedException
- Specified by:
deleteUsers
in interfaceUserService
- Throws:
ServiceLayerException
AuthenticationException
UserNotFoundException
UserExternallyManagedException
-
getUserByIdOrUsername
public User getUserByIdOrUsername(long userId, String username) throws ServiceLayerException, UserNotFoundException
- Specified by:
getUserByIdOrUsername
in interfaceUserService
- Throws:
ServiceLayerException
UserNotFoundException
-
enableUsers
public List<User> enableUsers(List<Long> userIds, List<String> usernames, boolean enabled) throws ServiceLayerException, UserNotFoundException, AuthenticationException, UserExternallyManagedException
- Specified by:
enableUsers
in interfaceUserService
- Throws:
ServiceLayerException
UserNotFoundException
AuthenticationException
UserExternallyManagedException
-
getUserSites
public List<Site> getUserSites(long userId, String username) throws ServiceLayerException, UserNotFoundException
- Specified by:
getUserSites
in interfaceUserService
- Throws:
ServiceLayerException
UserNotFoundException
-
getUserSiteRoles
public List<String> getUserSiteRoles(long userId, String username, String site) throws ServiceLayerException, UserNotFoundException
- Specified by:
getUserSiteRoles
in interfaceUserService
- Throws:
ServiceLayerException
UserNotFoundException
-
getCurrentUser
public AuthenticatedUser getCurrentUser() throws AuthenticationException
- Specified by:
getCurrentUser
in interfaceUserService
- Throws:
AuthenticationException
-
getCurrentUserSites
public List<Site> getCurrentUserSites() throws AuthenticationException, ServiceLayerException
- Specified by:
getCurrentUserSites
in interfaceUserService
- Throws:
AuthenticationException
ServiceLayerException
-
getCurrentUserSiteRoles
public List<String> getCurrentUserSiteRoles(String site) throws AuthenticationException, ServiceLayerException
- Specified by:
getCurrentUserSiteRoles
in interfaceUserService
- Throws:
AuthenticationException
ServiceLayerException
-
forgotPassword
public boolean forgotPassword(String username) throws ServiceLayerException, UserNotFoundException, UserExternallyManagedException
Description copied from interface:UserService
Forgot password feature for given username- Specified by:
forgotPassword
in interfaceUserService
- Parameters:
username
- user that forgot password- Returns:
- true if success
- Throws:
ServiceLayerException
- general service errorUserNotFoundException
- user not foundUserExternallyManagedException
- user is externally managed
-
changePassword
public User changePassword(String username, String current, String newPassword) throws PasswordDoesNotMatchException, UserExternallyManagedException, ServiceLayerException, AuthenticationException, UserNotFoundException
Description copied from interface:UserService
User changes password- Specified by:
changePassword
in interfaceUserService
- Parameters:
username
- usernamecurrent
- current passwordnewPassword
- new password- Returns:
- user whose password is successfully changed
- Throws:
PasswordDoesNotMatchException
- password does not match with storedUserExternallyManagedException
- user is externally managedServiceLayerException
- general service errorAuthenticationException
- authentication errorUserNotFoundException
- user not found
-
setPassword
public User setPassword(String token, String newPassword) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException
Description copied from interface:UserService
Set user password - forgot password token- Specified by:
setPassword
in interfaceUserService
- Parameters:
token
- forgot password tokennewPassword
- new password- Returns:
- uses whose password is successfully set
- Throws:
UserNotFoundException
- user not foundUserExternallyManagedException
- user is externally managedServiceLayerException
- general service error
-
validateToken
public boolean validateToken(String token) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException
Description copied from interface:UserService
Validate forgot password token- Specified by:
validateToken
in interfaceUserService
- Parameters:
token
- forgot password token to validate- Returns:
- true if token is valid otherwise false
- Throws:
UserNotFoundException
- user not foundUserExternallyManagedException
- user is externally managedServiceLayerException
- general service error
-
validateDecryptedToken
protected boolean validateDecryptedToken(String decryptedToken) throws UserNotFoundException, ServiceLayerException, UserExternallyManagedException
-
resetPassword
public boolean resetPassword(String username, String newPassword) throws UserNotFoundException, ServiceLayerException
Description copied from interface:UserService
Admin resets the user password- Specified by:
resetPassword
in interfaceUserService
- Parameters:
username
- usernamenewPassword
- new password- Returns:
- true if user's password is successfully reset
- Throws:
UserNotFoundException
- user not foundServiceLayerException
- general service error
-
getUserProperties
public Map<String,Map<String,String>> getUserProperties(String siteId) throws ServiceLayerException
Description copied from interface:UserService
Get the properties for the given site & the current user- Specified by:
getUserProperties
in interfaceUserService
- Parameters:
siteId
- the id of the site- Returns:
- the current properties
- Throws:
ServiceLayerException
- if there is any error fetching the properties
-
updateUserProperties
public Map<String,String> updateUserProperties(String siteId, Map<String,String> propertiesToUpdate) throws ServiceLayerException
Description copied from interface:UserService
Update or add properties for the given site & the current user- Specified by:
updateUserProperties
in interfaceUserService
- Parameters:
siteId
- the id of the sitepropertiesToUpdate
- the properties to update or add- Returns:
- the updated properties
- Throws:
ServiceLayerException
- if there is any error updating or fetching the properties
-
deleteUserProperties
public Map<String,String> deleteUserProperties(String siteId, List<String> propertiesToDelete) throws ServiceLayerException
Description copied from interface:UserService
Delete properties for the given site & current user- Specified by:
deleteUserProperties
in interfaceUserService
- Parameters:
siteId
- the id of the sitepropertiesToDelete
- the list of keys to delete- Returns:
- the updated properties
- Throws:
ServiceLayerException
- if there is any error deleting or fetching the properties
-
getCurrentUserSitePermissions
public List<String> getCurrentUserSitePermissions(String site) throws ServiceLayerException, UserNotFoundException, ExecutionException
Description copied from interface:UserService
Get permissions of the current authenticated user for given site- Specified by:
getCurrentUserSitePermissions
in interfaceUserService
- Parameters:
site
- site identifier- Returns:
- Throws:
ServiceLayerException
UserNotFoundException
ExecutionException
-
hasCurrentUserSitePermissions
public Map<String,Boolean> hasCurrentUserSitePermissions(String site, List<String> permissions) throws ServiceLayerException, UserNotFoundException, ExecutionException
Description copied from interface:UserService
Check if the current authenticated user has given permissions for given site- Specified by:
hasCurrentUserSitePermissions
in interfaceUserService
- Parameters:
site
- site identifierpermissions
- list of permissions to check- Returns:
- map with values true or false for each given permission
- Throws:
ServiceLayerException
UserNotFoundException
ExecutionException
-
getCurrentUserGlobalPermissions
public List<String> getCurrentUserGlobalPermissions() throws ServiceLayerException, UserNotFoundException, ExecutionException
Description copied from interface:UserService
Get global permissions of the current authenticated user- Specified by:
getCurrentUserGlobalPermissions
in interfaceUserService
- Returns:
- Throws:
ServiceLayerException
UserNotFoundException
ExecutionException
-
hasCurrentUserGlobalPermissions
public Map<String,Boolean> hasCurrentUserGlobalPermissions(List<String> permissions) throws ServiceLayerException, UserNotFoundException, ExecutionException
Description copied from interface:UserService
Check if the current authenticated user has given global permissions- Specified by:
hasCurrentUserGlobalPermissions
in interfaceUserService
- Parameters:
permissions
- list of permissions to check- Returns:
- map with values true or false for each given permission
- Throws:
ServiceLayerException
UserNotFoundException
ExecutionException
-
setUserServiceInternal
public void setUserServiceInternal(UserServiceInternal userServiceInternal)
-
setConfigurationService
public void setConfigurationService(ConfigurationService configurationService)
-
setGroupServiceInternal
public void setGroupServiceInternal(GroupServiceInternal groupServiceInternal)
-
setSiteService
public void setSiteService(SiteService siteService)
-
setEntitlementValidator
public void setEntitlementValidator(org.craftercms.commons.entitlements.validator.EntitlementValidator entitlementValidator)
-
setGeneralLockService
public void setGeneralLockService(GeneralLockService generalLockService)
-
setSecurityService
public void setSecurityService(SecurityService securityService)
-
setStudioConfiguration
public void setStudioConfiguration(StudioConfiguration studioConfiguration)
-
setAuditServiceInternal
public void setAuditServiceInternal(AuditServiceInternal auditServiceInternal)
-
setFreeMarkerConfig
public void setFreeMarkerConfig(org.springframework.beans.factory.ObjectFactory<org.springframework.web.servlet.view.freemarker.FreeMarkerConfig> freeMarkerConfig)
-
setEmailService
public void setEmailService(org.springframework.mail.javamail.JavaMailSender emailService)
-
setEmailServiceNoAuth
public void setEmailServiceNoAuth(org.springframework.mail.javamail.JavaMailSender emailServiceNoAuth)
-
setInstanceService
public void setInstanceService(InstanceService instanceService)
-
setEncryptor
public void setEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor)
-
setSecurityServiceV2
public void setSecurityServiceV2(SecurityService securityServiceV2)
-
setSessionRegistry
public void setSessionRegistry(org.springframework.security.core.session.SessionRegistry sessionRegistry)
-
-