Class UserServiceInternalImpl
java.lang.Object
org.craftercms.studio.impl.v2.service.security.internal.UserServiceInternalImpl
- All Implemented Interfaces:
UserServiceInternal,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
public class UserServiceInternalImpl
extends Object
implements UserServiceInternal, org.springframework.context.ApplicationContextAware
-
Constructor Summary
ConstructorsConstructorDescriptionUserServiceInternalImpl(UserDAO userDao, GroupServiceInternal groupServiceInternal, StudioConfiguration studioConfiguration, SiteService siteService, SecurityService securityService, RetryingDatabaseOperationFacade retryingDatabaseOperationFacade, com.google.common.cache.Cache<String, User> userCache, com.nulabinc.zxcvbn.Zxcvbn zxcvbn) -
Method Summary
Modifier and TypeMethodDescriptionbooleanchangePassword(String username, String current, String newPassword) createUser(User user) deleteUserProperties(String siteId, List<String> propertiesToDelete) Delete properties for the given site & current uservoiddeleteUsers(List<Long> userIds, List<String> usernames) enableUsers(List<Long> userIds, List<String> usernames, boolean enabled) protected StringgetActualSiteId(String siteId) getAllUsers(String keyword, int offset, int limit, String sort) Get paginated list of all users filtered by keywordgetAllUsersForSite(long orgId, List<NormalizedGroup> groupNames, String keyword, int offset, int limit, String sort) Get paginated list of all users for site filtered by keywordintgetAllUsersForSiteTotal(long orgId, String siteId, String keyword) Get total number of users for site filtered by keywordintgetAllUsersTotal(String keyword) Get total number of users filtered by keywordReturns the current authenticated userprotected StringgetUserByGitName(String gitName) Get user by git name.getUserByIdOrUsername(long userId, String username) getUserGroups(long userId, String username) Retrieves the list of groups associated with the specified user.getUserGroups(long userId, String username, boolean filterExternallyManagedGroups) Retrieves the list of groups associated with the specified user, optionally filtering to include only externally managed groups.getUserProperties(String siteId) Get the properties for the given site & the current usergetUserProperties(User user, long siteId) getUsersByIdOrUsername(List<Long> userIds, List<String> usernames) protected voidinvalidateCache(String username) protected voidinvalidateCache(Collection<User> users) protected voidinvalidateCache(List<String> usernames) booleanisSystemAdmin(String username) Check if given user has system_admin rolebooleanisUserMemberOfGroup(String username, String groupName) voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) booleansetUserPassword(String username, String newPassword) voidupdateUser(User user) updateUserProperties(String siteId, Map<String, String> propertiesToUpdate) Update or add properties for the given site & the current userbooleanuserExists(long userId, String username)
-
Constructor Details
-
UserServiceInternalImpl
@ConstructorProperties({"userDao","groupServiceInternal","studioConfiguration","siteService","securityService","retryingDatabaseOperationFacade","userCache","zxcvbn"}) public UserServiceInternalImpl(UserDAO userDao, GroupServiceInternal groupServiceInternal, StudioConfiguration studioConfiguration, SiteService siteService, SecurityService securityService, RetryingDatabaseOperationFacade retryingDatabaseOperationFacade, com.google.common.cache.Cache<String, User> userCache, com.nulabinc.zxcvbn.Zxcvbn zxcvbn)
-
-
Method Details
-
invalidateCache
-
invalidateCache
-
invalidateCache
-
getUserByIdOrUsername
@NonNull public User getUserByIdOrUsername(long userId, String username) throws ServiceLayerException, UserNotFoundException - Specified by:
getUserByIdOrUsernamein interfaceUserServiceInternal- Throws:
ServiceLayerExceptionUserNotFoundException
-
getUsersByIdOrUsername
public List<User> getUsersByIdOrUsername(List<Long> userIds, List<String> usernames) throws ServiceLayerException, UserNotFoundException - Specified by:
getUsersByIdOrUsernamein interfaceUserServiceInternal- Throws:
ServiceLayerExceptionUserNotFoundException
-
getAllUsersForSite
public List<User> getAllUsersForSite(long orgId, List<NormalizedGroup> groupNames, String keyword, int offset, int limit, String sort) throws ServiceLayerException Description copied from interface:UserServiceInternalGet paginated list of all users for site filtered by keyword- Specified by:
getAllUsersForSitein interfaceUserServiceInternal- Parameters:
orgId- organization identifiergroupNames- group names for sitekeyword- keyword to filter usersoffset- pagination offsetlimit- 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:UserServiceInternalGet paginated list of all users filtered by keyword- Specified by:
getAllUsersin interfaceUserServiceInternal- Parameters:
keyword- keyword to filter usersoffset- offset for paginationlimit- limit number of users 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:UserServiceInternalGet total number of users for site filtered by keyword- Specified by:
getAllUsersForSiteTotalin interfaceUserServiceInternal- Parameters:
orgId- organization identifiersiteId- site identifierkeyword- keyword to filter users- Returns:
- total number of users for site filtered by keyword
- Throws:
ServiceLayerException
-
getAllUsersTotal
Description copied from interface:UserServiceInternalGet total number of users filtered by keyword- Specified by:
getAllUsersTotalin interfaceUserServiceInternal- Parameters:
keyword- keyword to filter user- Returns:
- total number of users filtered by keyword
- Throws:
ServiceLayerException
-
createUser
- Specified by:
createUserin interfaceUserServiceInternal- Throws:
UserAlreadyExistsExceptionServiceLayerException
-
userExists
- Specified by:
userExistsin interfaceUserServiceInternal- Throws:
ServiceLayerException
-
updateUser
- Specified by:
updateUserin interfaceUserServiceInternal- Throws:
UserNotFoundExceptionServiceLayerException
-
deleteUsers
public void deleteUsers(List<Long> userIds, List<String> usernames) throws UserNotFoundException, ServiceLayerException - Specified by:
deleteUsersin interfaceUserServiceInternal- Throws:
UserNotFoundExceptionServiceLayerException
-
enableUsers
public List<User> enableUsers(List<Long> userIds, List<String> usernames, boolean enabled) throws ServiceLayerException, UserNotFoundException - Specified by:
enableUsersin interfaceUserServiceInternal- Throws:
ServiceLayerExceptionUserNotFoundException
-
getUserGroups
public List<Group> getUserGroups(long userId, String username) throws UserNotFoundException, ServiceLayerException Description copied from interface:UserServiceInternalRetrieves the list of groups associated with the specified user.- Specified by:
getUserGroupsin interfaceUserServiceInternal- Parameters:
userId- the unique identifier of the userusername- the username of the user- Returns:
- a list of
Groupobjects associated with the user - Throws:
UserNotFoundException- if no user is found with the given userId or usernameServiceLayerException- if an error occurs while accessing the service layer
-
getUserGroups
public List<Group> getUserGroups(long userId, String username, boolean filterExternallyManagedGroups) throws UserNotFoundException, ServiceLayerException Description copied from interface:UserServiceInternalRetrieves the list of groups associated with the specified user, optionally filtering to include only externally managed groups.- Specified by:
getUserGroupsin interfaceUserServiceInternal- Parameters:
userId- the unique identifier of the userusername- the username of the userfilterExternallyManagedGroups- if true, only externally managed groups are returned; if false, all groups are returned- Returns:
- a list of
Groupobjects associated with the user, filtered based on the flag - Throws:
UserNotFoundException- if no user is found with the given userId or usernameServiceLayerException- if an error occurs while accessing the service layer
-
isUserMemberOfGroup
public boolean isUserMemberOfGroup(String username, String groupName) throws UserNotFoundException, ServiceLayerException - Specified by:
isUserMemberOfGroupin interfaceUserServiceInternal- Throws:
UserNotFoundExceptionServiceLayerException
-
changePassword
public boolean changePassword(String username, String current, String newPassword) throws PasswordDoesNotMatchException, UserExternallyManagedException, ServiceLayerException - Specified by:
changePasswordin interfaceUserServiceInternal- Throws:
PasswordDoesNotMatchExceptionUserExternallyManagedExceptionServiceLayerException
-
setUserPassword
public boolean setUserPassword(String username, String newPassword) throws UserNotFoundException, ServiceLayerException - Specified by:
setUserPasswordin interfaceUserServiceInternal- Throws:
UserNotFoundExceptionServiceLayerException
-
getUserByGitName
Description copied from interface:UserServiceInternalGet user by git name. Special use case because git stores user as string of first and last name separated by ' '- Specified by:
getUserByGitNamein interfaceUserServiceInternal- Parameters:
gitName- first and last name separated with ' '- Returns:
- user
- Throws:
ServiceLayerExceptionUserNotFoundException
-
getUserProperties
-
getGlobalSiteName
-
getActualSiteId
-
getUserProperties
Description copied from interface:UserServiceInternalGet the properties for the given site & the current user- Specified by:
getUserPropertiesin interfaceUserServiceInternal- 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 ServiceLayerExceptionDescription copied from interface:UserServiceInternalUpdate or add properties for the given site & the current user- Specified by:
updateUserPropertiesin interfaceUserServiceInternal- 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:UserServiceInternalDelete properties for the given site & current user- Specified by:
deleteUserPropertiesin interfaceUserServiceInternal- 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
-
getCurrentUser
Description copied from interface:UserServiceInternalReturns the current authenticated user- Specified by:
getCurrentUserin interfaceUserServiceInternal- Returns:
- the user if present
- Throws:
AuthenticationException- if there is no user authenticated
-
isSystemAdmin
Description copied from interface:UserServiceInternalCheck if given user has system_admin role- Specified by:
isSystemAdminin interfaceUserServiceInternal- Parameters:
username- user- Returns:
- true if user is system_admin, false otherwise
-
setApplicationContext
public void setApplicationContext(@NonNull org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-