public CachedUser load(final String userId) throws Exception { User userFromDatabase = null; if (ldapProperties == null || !ldapProperties.isEnabled()) { userFromDatabase = identityService.createUserQuery().userIdIgnoreCase(userId.toLowerCase()).singleResult(); } else { userFromDatabase = identityService.createUserQuery().userId(userId).singleResult(); } if (userFromDatabase == null) { throw new UsernameNotFoundException("User " + userId + " was not found in the database"); } Collection<GrantedAuthority> grantedAuthorities = new ArrayList<>(); UserInformation userInformation = userService.getUserInformation(userFromDatabase.getId()); for (String privilege : userInformation.getPrivileges()) { grantedAuthorities.add(new SimpleGrantedAuthority(privilege)); } return new CachedUser(userFromDatabase, grantedAuthorities); }
public void bulkUpdatePassword(List<String> userIds, String newPassword) { for (String userId : userIds) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user != null) { user.setPassword(newPassword); identityService.updateUserPassword(user); } } }
protected User getUserFromRequest(String userId) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new FlowableObjectNotFoundException("Could not find a user with id '" + userId + "'.", User.class); } if (restApiInterceptor != null) { restApiInterceptor.accessUserInfoById(user); } return user; }
protected boolean isUserPrivilege(String privilegeId, String userId) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new IllegalArgumentException("Invalid user id"); } return identityService.createPrivilegeQuery().privilegeId(privilegeId).userId(userId).count() > 0; }
public void changePassword(String originalPassword, String newPassword) { User user = identityService.createUserQuery().userId(SecurityUtils.getCurrentUserId()).singleResult(); if (!user.getPassword().equals(originalPassword)) { throw new NotFoundException(); } user.setPassword(newPassword); identityService.updateUserPassword(user); }
@Override public UserInformation getUserInformation(String userId) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new NotFoundException(); } List<Privilege> userPrivileges = identityService.createPrivilegeQuery().userId(userId).list(); Set<String> privilegeNames = new HashSet<>(); for (Privilege userPrivilege : userPrivileges) { privilegeNames.add(userPrivilege.getName()); } List<Group> groups = identityService.createGroupQuery().groupMember(userId).list(); if (groups.size() > 0) { List<String> groupIds = new ArrayList<>(); for (Group group : groups) { groupIds.add(group.getId()); } List<Privilege> groupPrivileges = identityService.createPrivilegeQuery().groupIds(groupIds).list(); for (Privilege groupPrivilege : groupPrivileges) { privilegeNames.add(groupPrivilege.getName()); } } return new UserInformation(user, groups, new ArrayList<>(privilegeNames)); }
public void updateUserDetails(String userId, String firstName, String lastName, String email) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user != null) { user.setFirstName(firstName); user.setLastName(lastName); user.setEmail(email); identityService.saveUser(user); } }
public User updateProfile(String firstName, String lastName, String email) { User currentUser = SecurityUtils.getCurrentUserObject(); // If user is not externally managed, we need the email address for login, so an empty email is not allowed if (StringUtils.isEmpty(email)) { throw new BadRequestException("Empty email is not allowed"); } User user = identityService.createUserQuery().userId(currentUser.getId()).singleResult(); user.setFirstName(firstName); user.setLastName(lastName); user.setEmail(email); identityService.saveUser(user); return user; }
protected void verifyGroupMemberExists(String groupId, String userId) { // Check existence Group group = identityService.createGroupQuery().groupId(groupId).singleResult(); User user = identityService.createUserQuery().userId(userId).singleResult(); for (User groupMember : identityService.createUserQuery().memberOfGroup(groupId).list()) { if (groupMember.getId().equals(userId)) { user = groupMember; } } if (group == null || user == null) { throw new NotFoundException(); } }
public User createNewUser(String id, String firstName, String lastName, String email, String password) { if (StringUtils.isBlank(id) || StringUtils.isBlank(password) || StringUtils.isBlank(firstName)) { throw new BadRequestException("Id, password and first name are required"); } if (email != null && identityService.createUserQuery().userEmail(email).count() > 0) { throw new ConflictingRequestException("User already registered", "ACCOUNT.SIGNUP.ERROR.ALREADY-REGISTERED"); } User user = identityService.newUser(id); user.setFirstName(firstName); user.setLastName(lastName); user.setEmail(email); identityService.saveUser(user); User savedUser = identityService.createUserQuery().userEmail(email).singleResult(); savedUser.setPassword(password); identityService.updateUserPassword(savedUser); return user; }
@Override public Picture execute(CommandContext commandContext) { if (userId == null) { throw new FlowableIllegalArgumentException("userId is null"); } User user = CommandContextUtil.getIdmEngineConfiguration().getIdmIdentityService() .createUserQuery().userId(userId) .singleResult(); if (user == null) { throw new FlowableObjectNotFoundException("user " + userId + " doesn't exist", User.class); } return CommandContextUtil.getUserEntityManager(commandContext).getUserPicture(user); }
public void deleteGroupMember(String groupId, String userId) { verifyGroupMemberExists(groupId, userId); Group group = identityService.createGroupQuery().groupId(groupId).singleResult(); if (group == null) { throw new NotFoundException(); } User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new NotFoundException(); } identityService.deleteMembership(userId, groupId); }
@Override public Object execute(CommandContext commandContext) { if (userId == null) { throw new FlowableIllegalArgumentException("userId is null"); } User user = CommandContextUtil.getIdmEngineConfiguration().getIdmIdentityService() .createUserQuery().userId(userId) .singleResult(); if (user == null) { throw new FlowableObjectNotFoundException("user " + userId + " doesn't exist", User.class); } CommandContextUtil.getUserEntityManager(commandContext).setUserPicture(user, picture); return null; }
public void addGroupMember(String groupId, String userId) { verifyGroupMemberExists(groupId, userId); Group group = identityService.createGroupQuery().groupId(groupId).singleResult(); if (group == null) { throw new NotFoundException(); } User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new NotFoundException(); } identityService.createMembership(userId, groupId); }