Class UserServiceImpl
java.lang.Object
ru.cg.webbpm.modules.security.api.impl.service.UserServiceImpl
- All Implemented Interfaces:
UserService
- Author:
- Tim Urmancheev
-
Constructor Summary
ConstructorsConstructorDescriptionUserServiceImpl
(SecurityContext securityContext, AccessLevelService accessLevelService, UserDao userDao, UserGroupDao userGroupDao, UserRoleDao userRoleDao) User service constructor - creates new user service. -
Method Summary
Modifier and TypeMethodDescriptionBinds group to user by user account id and group id.bindGroupByUser
(String userId, String groupId, String bindingUserId) Binds group to user by user account id, group id and user account id of binding user.Inserts user into database.void
Sets user's "locked" field to true according to user id.void
delete
(Collection<String> userIds) Sets user's "locked" field to true according to user account ids collection.Gets user by user account id.get
(Collection<String> userIds) Gets user by user account ids.get
(LoadOptions options) Gets users according to load options.getByEmail
(String email) Gets user by email.getByUsername
(String username) Gets user by username.getGroups
(String userId, LoadOptions options) Gets groups by user account id according to load options.getRoleNamesInOrg
(String orgUnitCode) Gets all role names of org unit by org unit code.getRoles
(String userId, LoadOptions options) Gets roles by user account id according to load options.Gets user with maximal access level.getUserGroupLinks
(String userId, LoadOptions options) Gets groups by user account id with binding timestamp according to load options.getUsersWithAuthorityIn
(Collection<String> authorityIds) getUsersWithGroupIn
(Collection<String> groupIds) getUsersWithRoleIn
(Collection<String> roleIds) getUsersWithRoleInOrg
(String roleName, String orgUnitCode) Gets users with role name in org unit.Gets any existing(not locked) user with max access level (maybe super admin)boolean
Checks current user access level equals to maximal access level.void
unbindGroup
(String userId, String groupId) Unbinds group from user by user account id and group id.void
unbindGroupByUser
(String userId, String groupId, String unbindingUserId) Unbinds group from user by user account id, group id and user account id of unbinding user.void
Updates user in database.void
updateGroups
(String userId, Collection<String> addedGroupIds, Collection<String> deletedGroupIds) Updates user group links by user account id, added group ids collection and deleted group ids collection Checks current user's access level to binding and unbinding groups.void
updateLockedAndEmailConfirmed
(String userId, boolean locked, boolean emailConfirmed) Updates user's emailConfirmed status.
-
Constructor Details
-
UserServiceImpl
@Autowired public UserServiceImpl(SecurityContext securityContext, AccessLevelService accessLevelService, UserDao userDao, UserGroupDao userGroupDao, UserRoleDao userRoleDao) User service constructor - creates new user service.- Parameters:
securityContext
- user's security context. Instance ofSecurityContext
type.accessLevelService
- access level service. Instance ofAccessLevelService
type.userDao
- user account data access object. Instance ofUserDao
type.userGroupDao
- link user account user group data access object. Instance ofUserGroupDao
type.userRoleDao
- link user account user role data access object. Instance ofUserRoleDao
type.
-
-
Method Details
-
get
Gets user by user account id.- Specified by:
get
in interfaceUserService
- Parameters:
userId
- user account id of user to receive. Instance ofString
type.- Returns:
- requested user or null if does not exist. Instance of
User
type. - See Also:
-
get
Gets users according to load options.- Specified by:
get
in interfaceUserService
- Parameters:
options
- indicates load options properties. Instance ofLoadOptions
type.- Returns:
- list of users. Instance of
List
type. - See Also:
-
get
Gets user by user account ids.- Specified by:
get
in interfaceUserService
- Parameters:
userIds
- user account ids of objects to receive. Instance ofCollection
type.- Returns:
- collection of users. Instance of
Collection
type. - See Also:
-
getLdapUsers
- Specified by:
getLdapUsers
in interfaceUserService
-
getByUsername
Gets user by username.- Specified by:
getByUsername
in interfaceUserService
- Parameters:
username
- username of user to receive. Instance ofString
type.- Returns:
- requested user or null if does not exist. Instance of
User
type. - See Also:
-
getByEmail
Gets user by email.- Specified by:
getByEmail
in interfaceUserService
- Parameters:
email
- email of user to receive. Instance ofString
type.- Returns:
- requested user or null if does not exist. Instance of
User
type. - See Also:
-
create
Inserts user into database. User id will be generated if it is null.- Specified by:
create
in interfaceUserService
- Parameters:
user
- user to add. Instance ofUser
type.- Returns:
- user id. Instance of
String
type. - Throws:
org.springframework.dao.DataAccessException
- if username already exists.org.springframework.dao.DataAccessException
- if user's org unit does not exist.- See Also:
-
update
@CacheEvict(value="user-service-id",key="#user.id()") @CacheEvict(value="runtime-user-id",key="#user.id()") @CacheEvict(value="runtime-user-username",key="#user.username()",condition="#user.username() != null") public void update(User user) Updates user in database. User's username is ignored.- Specified by:
update
in interfaceUserService
- Parameters:
user
- user to update. Instance ofUser
type.- Throws:
org.springframework.dao.DataAccessException
- if user's org unit doesn't exist.- See Also:
-
updateLockedAndEmailConfirmed
@CacheEvict(value="user-service-id",key="#userId") @CacheEvict(value="runtime-user-id",key="#userId") public void updateLockedAndEmailConfirmed(String userId, boolean locked, boolean emailConfirmed) Updates user's emailConfirmed status.- Specified by:
updateLockedAndEmailConfirmed
in interfaceUserService
- Parameters:
userId
- user account id of the user to update. Instance ofString
type.locked
-emailConfirmed
- emailConfirmed status of the user. Instance ofboolean
type.- See Also:
-
delete
@CacheEvict(value="user-service-id",key="#userId") @CacheEvict(value="runtime-user-id",key="#userId") @CacheEvict(value="runtime-user-username",allEntries=true) public void delete(String userId) Sets user's "locked" field to true according to user id.- Specified by:
delete
in interfaceUserService
- Parameters:
userId
- user account id of user to mark removed. Instance ofString
type.- See Also:
-
delete
@CacheEvict(value="user-service-id",allEntries=true) @CacheEvict(value="runtime-user-id",allEntries=true) @CacheEvict(value="runtime-user-username",allEntries=true) public void delete(Collection<String> userIds) Sets user's "locked" field to true according to user account ids collection.- Specified by:
delete
in interfaceUserService
- Parameters:
userIds
- user account ids collection of users to mark removed. Instance ofCollection
type.- See Also:
-
getGroups
Gets groups by user account id according to load options. Filters groups according to current user's access level.- Specified by:
getGroups
in interfaceUserService
- Parameters:
userId
- user account id of user to receive groups. Instance ofString
type.options
- indicates load options properties. Instance ofLoadOptions
type.- Returns:
- list of groups. Instance of
List
type. - See Also:
-
getUserGroupLinks
Gets groups by user account id with binding timestamp according to load options. Groups are filtered according to current user's access level.- Specified by:
getUserGroupLinks
in interfaceUserService
- Parameters:
userId
- user account id of user to receive groups. Instance ofString
type.options
- indicates load options properties. Instance ofLoadOptions
type.- Returns:
- list of user and group links. Instance of
List
type. - See Also:
-
updateGroups
@Transactional @CacheEvict(value="user-service-id",key="#userId") @CacheEvict(value="runtime-user-id",key="#userId") @CacheEvict(value="runtime-user-username",allEntries=true) public void updateGroups(String userId, Collection<String> addedGroupIds, Collection<String> deletedGroupIds) Updates user group links by user account id, added group ids collection and deleted group ids collection Checks current user's access level to binding and unbinding groups.- Specified by:
updateGroups
in interfaceUserService
- Parameters:
userId
- user account id which groups to update. Instance ofString
type.addedGroupIds
- collection of group ids to add. Instance ofCollection
type.deletedGroupIds
- collection of group ids to remove. Instance ofCollection
type.- Throws:
org.springframework.dao.DataAccessException
- if user already has any of groups.- See Also:
-
bindGroup
@Transactional @CacheEvict(value="user-service-id",key="#userId") @CacheEvict(value="runtime-user-id",key="#userId") @CacheEvict(value="runtime-user-username",allEntries=true) public String bindGroup(String userId, String groupId) Binds group to user by user account id and group id. Checks current user's access level to binding group.- Specified by:
bindGroup
in interfaceUserService
- Parameters:
userId
- user account id of user to bind. Instance ofString
type.groupId
- group id of binding group. Instance ofString
type.- Returns:
- id of user group link. Instance of
String
type. - Throws:
org.springframework.dao.DataAccessException
- if user already has group.- See Also:
-
bindGroupByUser
@Transactional @CacheEvict(value="user-service-id",key="#userId") @CacheEvict(value="runtime-user-id",key="#userId") @CacheEvict(value="runtime-user-username",allEntries=true) public String bindGroupByUser(String userId, String groupId, String bindingUserId) Binds group to user by user account id, group id and user account id of binding user. Checks user's access level to binding group.- Specified by:
bindGroupByUser
in interfaceUserService
- Parameters:
userId
- user account id of user to bind. Instance ofString
type.groupId
- group id of binding group. Instance ofString
type.bindingUserId
- user account id of binding user. Instance ofString
type.- Returns:
- id of user group link. Instance of
String
type. - Throws:
org.springframework.dao.DataAccessException
- if user already has group.- See Also:
-
unbindGroup
@Transactional @CacheEvict(value="user-service-id",key="#userId") @CacheEvict(value="runtime-user-id",key="#userId") @CacheEvict(value="runtime-user-username",allEntries=true) public void unbindGroup(String userId, String groupId) Unbinds group from user by user account id and group id. Checks current user's access level to unbinding group.- Specified by:
unbindGroup
in interfaceUserService
- Parameters:
userId
- user account id of user to unbind. Instance ofString
type.groupId
- group id of unbinding group. Instance ofString
type.- See Also:
-
unbindGroupByUser
@Transactional @CacheEvict(value="user-service-id",key="#userId") @CacheEvict(value="runtime-user-id",key="#userId") @CacheEvict(value="runtime-user-username",allEntries=true) public void unbindGroupByUser(String userId, String groupId, String unbindingUserId) Unbinds group from user by user account id, group id and user account id of unbinding user. Checks user's access level to unbinding group.- Specified by:
unbindGroupByUser
in interfaceUserService
- Parameters:
userId
- user account id of user to unbind. Instance ofString
type.groupId
- group id of unbinding group. Instance ofString
type.unbindingUserId
- user account id of unbinding user. Instance ofString
type.- See Also:
-
getRoles
Gets roles by user account id according to load options. Filters groups according to current user's access level.- Specified by:
getRoles
in interfaceUserService
- Parameters:
userId
- user account id of user to receive roles. Instance ofString
type.options
- indicates load options properties. Instance ofLoadOptions
type.- Returns:
- list of roles. Instance of
List
type. - See Also:
-
getUsersWithRoleInOrg
Gets users with role name in org unit.- Specified by:
getUsersWithRoleInOrg
in interfaceUserService
- Parameters:
roleName
- user's role name. Instance ofString
type.orgUnitCode
- user's org unit code. Instance ofString
type.- Returns:
- list of users. Instance of
List
type. - See Also:
-
getRoleNamesInOrg
Gets all role names of org unit by org unit code.- Specified by:
getRoleNamesInOrg
in interfaceUserService
- Parameters:
orgUnitCode
- user's org unit code. Instance ofString
type.- Returns:
- list of role names. Instance of
List
type. - See Also:
-
getSuperAdmin
Gets user with maximal access level.- Specified by:
getSuperAdmin
in interfaceUserService
- Returns:
- requested user or null if does not exist. Instance of
User
type. - See Also:
-
getUserWithMaxAccessLevel
Gets any existing(not locked) user with max access level (maybe super admin)- Specified by:
getUserWithMaxAccessLevel
in interfaceUserService
- Returns:
- requested user or null if does not exist. Instance of
User
type. - See Also:
-
getUserSourceByUserId
- Specified by:
getUserSourceByUserId
in interfaceUserService
-
isCurrentUserSuperAdmin
public boolean isCurrentUserSuperAdmin()Checks current user access level equals to maximal access level.- Specified by:
isCurrentUserSuperAdmin
in interfaceUserService
- Returns:
- boolean result of check. Instance of
boolean
type. - See Also:
-
getUsersWithAuthorityIn
- Specified by:
getUsersWithAuthorityIn
in interfaceUserService
-
getUsersWithRoleIn
- Specified by:
getUsersWithRoleIn
in interfaceUserService
-
getUsersWithGroupIn
- Specified by:
getUsersWithGroupIn
in interfaceUserService
-