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 TypeMethodDescriptionboolean
changePassword
(String username, String current, String newPassword) createUser
(User user) deleteUserProperties
(String siteId, List<String> propertiesToDelete) Delete properties for the given site & current uservoid
deleteUsers
(List<Long> userIds, List<String> usernames) enableUsers
(List<Long> userIds, List<String> usernames, boolean enabled) protected String
getActualSiteId
(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 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 keywordReturns the current authenticated userprotected String
getUserByGitName
(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 void
invalidateCache
(String username) protected void
invalidateCache
(Collection<User> users) protected void
invalidateCache
(List<String> usernames) boolean
isSystemAdmin
(String username) Check if given user has system_admin roleboolean
isUserMemberOfGroup
(String username, String groupName) void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) boolean
setUserPassword
(String username, String newPassword) void
updateUser
(User user) updateUserProperties
(String siteId, Map<String, String> propertiesToUpdate) Update or add properties for the given site & the current userboolean
userExists
(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:
getUserByIdOrUsername
in interfaceUserServiceInternal
- Throws:
ServiceLayerException
UserNotFoundException
-
getUsersByIdOrUsername
public List<User> getUsersByIdOrUsername(List<Long> userIds, List<String> usernames) throws ServiceLayerException, UserNotFoundException - Specified by:
getUsersByIdOrUsername
in interfaceUserServiceInternal
- Throws:
ServiceLayerException
UserNotFoundException
-
getAllUsersForSite
public List<User> getAllUsersForSite(long orgId, List<NormalizedGroup> groupNames, String keyword, int offset, int limit, String sort) throws ServiceLayerException Description copied from interface:UserServiceInternal
Get paginated list of all users for site filtered by keyword- Specified by:
getAllUsersForSite
in 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:UserServiceInternal
Get paginated list of all users filtered by keyword- Specified by:
getAllUsers
in 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:UserServiceInternal
Get total number of users for site filtered by keyword- Specified by:
getAllUsersForSiteTotal
in 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:UserServiceInternal
Get total number of users filtered by keyword- Specified by:
getAllUsersTotal
in interfaceUserServiceInternal
- Parameters:
keyword
- keyword to filter user- Returns:
- total number of users filtered by keyword
- Throws:
ServiceLayerException
-
createUser
- Specified by:
createUser
in interfaceUserServiceInternal
- Throws:
UserAlreadyExistsException
ServiceLayerException
-
userExists
- Specified by:
userExists
in interfaceUserServiceInternal
- Throws:
ServiceLayerException
-
updateUser
- Specified by:
updateUser
in interfaceUserServiceInternal
- Throws:
UserNotFoundException
ServiceLayerException
-
deleteUsers
public void deleteUsers(List<Long> userIds, List<String> usernames) throws UserNotFoundException, ServiceLayerException - Specified by:
deleteUsers
in interfaceUserServiceInternal
- Throws:
UserNotFoundException
ServiceLayerException
-
enableUsers
public List<User> enableUsers(List<Long> userIds, List<String> usernames, boolean enabled) throws ServiceLayerException, UserNotFoundException - Specified by:
enableUsers
in interfaceUserServiceInternal
- Throws:
ServiceLayerException
UserNotFoundException
-
getUserGroups
public List<Group> getUserGroups(long userId, String username) throws UserNotFoundException, ServiceLayerException Description copied from interface:UserServiceInternal
Retrieves the list of groups associated with the specified user.- Specified by:
getUserGroups
in interfaceUserServiceInternal
- Parameters:
userId
- the unique identifier of the userusername
- the username of the user- Returns:
- a list of
Group
objects 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:UserServiceInternal
Retrieves the list of groups associated with the specified user, optionally filtering to include only externally managed groups.- Specified by:
getUserGroups
in 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
Group
objects 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:
isUserMemberOfGroup
in interfaceUserServiceInternal
- Throws:
UserNotFoundException
ServiceLayerException
-
changePassword
public boolean changePassword(String username, String current, String newPassword) throws PasswordDoesNotMatchException, UserExternallyManagedException, ServiceLayerException - Specified by:
changePassword
in interfaceUserServiceInternal
- Throws:
PasswordDoesNotMatchException
UserExternallyManagedException
ServiceLayerException
-
setUserPassword
public boolean setUserPassword(String username, String newPassword) throws UserNotFoundException, ServiceLayerException - Specified by:
setUserPassword
in interfaceUserServiceInternal
- Throws:
UserNotFoundException
ServiceLayerException
-
getUserByGitName
Description copied from interface:UserServiceInternal
Get user by git name. Special use case because git stores user as string of first and last name separated by ' '- Specified by:
getUserByGitName
in interfaceUserServiceInternal
- Parameters:
gitName
- first and last name separated with ' '- Returns:
- user
- Throws:
ServiceLayerException
UserNotFoundException
-
getUserProperties
-
getGlobalSiteName
-
getActualSiteId
-
getUserProperties
Description copied from interface:UserServiceInternal
Get the properties for the given site & the current user- Specified by:
getUserProperties
in 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:UserServiceInternal
Update or add properties for the given site & the current user- Specified by:
updateUserProperties
in 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:UserServiceInternal
Delete properties for the given site & current user- Specified by:
deleteUserProperties
in 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:UserServiceInternal
Returns the current authenticated user- Specified by:
getCurrentUser
in interfaceUserServiceInternal
- Returns:
- the user if present
- Throws:
AuthenticationException
- if there is no user authenticated
-
isSystemAdmin
Description copied from interface:UserServiceInternal
Check if given user has system_admin role- Specified by:
isSystemAdmin
in 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:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-