protected void removeinvolvedUsers(List<? extends User> matchingUsers, Set<String> involvedUsers) { if (involvedUsers != null) { // Using iterator to be able to remove without ConcurrentModExceptions Iterator<? extends User> userIt = matchingUsers.iterator(); while (userIt.hasNext()) { if (involvedUsers.contains(userIt.next().getId())) { userIt.remove(); } } } }
public UserResponse createUserResponse(User user, boolean incudePassword, RestUrlBuilder urlBuilder) { UserResponse response = new UserResponse(); response.setFirstName(user.getFirstName()); response.setLastName(user.getLastName()); response.setDisplayName(user.getDisplayName()); response.setId(user.getId()); response.setEmail(user.getEmail()); if (incudePassword) { response.setPassword(user.getPassword()); } return response; }
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; }
public UserRepresentation(User user) { setId(user.getId()); setFirstName(user.getFirstName()); setLastName(user.getLastName()); setFullName((user.getFirstName() != null ? user.getFirstName() : "") + " " + (user.getLastName() != null ? user.getLastName() : "")); setEmail(user.getEmail()); }
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 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 Void execute(CommandContext commandContext) { if (user == null) { throw new FlowableIllegalArgumentException("user is null"); } if (CommandContextUtil.getUserEntityManager(commandContext).isNewUser(user)) { if (user.getPassword() != null) { PasswordEncoder passwordEncoder = CommandContextUtil.getIdmEngineConfiguration().getPasswordEncoder(); PasswordSalt passwordSalt = CommandContextUtil.getIdmEngineConfiguration().getPasswordSalt(); user.setPassword(passwordEncoder.encode(user.getPassword(), passwordSalt)); } if (user instanceof UserEntity) { CommandContextUtil.getUserEntityManager(commandContext).insert((UserEntity) user, true); } else { CommandContextUtil.getDbSqlSession(commandContext).insert((Entity) user); } } else { UserEntity dbUser = CommandContextUtil.getUserEntityManager().findById(user.getId()); user.setPassword(dbUser.getPassword()); CommandContextUtil.getUserEntityManager().updateUser(user); } return null; } }
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); }
/** * The userId needs to be passed explicitly. It can be the email, but also the external id when eg LDAP is being used. */ public FlowableAppUser(org.flowable.idm.api.User user, String userId, Collection<? extends GrantedAuthority> authorities) { super(userId, user.getPassword() != null ? user.getPassword() : "", authorities); // password needs to be non null this.userObject = user; }
@Override public List<User> getUsersWithPrivilege(String name) { List<User> users = new ArrayList<>(); List<PrivilegeMapping> privilegeMappings = getPrivilegeMappingsByPrivilegeId(name); for (PrivilegeMapping privilegeMapping : privilegeMappings) { if (privilegeMapping.getUserId() != null) { User user = new UserEntityImpl(); user.setId(privilegeMapping.getUserId()); user.setLastName(privilegeMapping.getUserId()); users.add(user); } } return users; }
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); } } }
User user = getUserFromRequest(userId); if (userRequest.isEmailChanged()) { user.setEmail(userRequest.getEmail()); user.setFirstName(userRequest.getFirstName()); user.setLastName(userRequest.getLastName()); user.setDisplayName(userRequest.getDisplayName()); user.setPassword(userRequest.getPassword()); identityService.updateUserPassword(user); } else {
@Override public User execute(CommandContext commandContext) { if (!CommandContextUtil.getUserEntityManager(commandContext).isNewUser(user)) { PasswordEncoder passwordEncoder = CommandContextUtil.getIdmEngineConfiguration().getPasswordEncoder(); PasswordSalt passwordSalt = CommandContextUtil.getIdmEngineConfiguration().getPasswordSalt(); user.setPassword(passwordEncoder.encode(user.getPassword(), passwordSalt)); CommandContextUtil.getUserEntityManager(commandContext).updateUser(user); } return user; } }
@Override public Boolean checkPassword(String userId, String password, PasswordEncoder passwordEncoder, PasswordSalt salt) { User user = null; if (userId != null) { user = findById(userId); } return (user != null) && (password != null) && passwordEncoder.isMatches(password, user.getPassword(), salt); }
/** * Get the login of the current user. */ public static String getCurrentUserId() { User user = getCurrentUserObject(); if (user != null) { return user.getId(); } return null; }
@ApiOperation(value = "Create a user", tags = { "Users" }) @ApiResponses(value = { @ApiResponse(code = 201, message = "Indicates the user was created."), @ApiResponse(code = 400, message = "Indicates the id of the user was missing.") }) @PostMapping(value = "/users", produces = "application/json") public UserResponse createUser(@RequestBody UserRequest userRequest, HttpServletRequest request, HttpServletResponse response) { if (userRequest.getId() == null) { throw new FlowableIllegalArgumentException("Id cannot be null."); } // Check if a user with the given ID already exists so we return a CONFLICT if (identityService.createUserQuery().userId(userRequest.getId()).count() > 0) { throw new FlowableConflictException("A user with id '" + userRequest.getId() + "' already exists."); } User created = identityService.newUser(userRequest.getId()); created.setEmail(userRequest.getEmail()); created.setFirstName(userRequest.getFirstName()); created.setLastName(userRequest.getLastName()); created.setDisplayName(userRequest.getDisplayName()); created.setPassword(userRequest.getPassword()); if (restApiInterceptor != null) { restApiInterceptor.createNewUser(created); } identityService.saveUser(created); response.setStatus(HttpStatus.CREATED.value()); return idmRestResponseFactory.createUserResponse(created, false); }
@ApiOperation(value = "Delete a user", tags = { "Users" }) @ApiResponses(value = { @ApiResponse(code = 204, message = "Indicates the user was found and has been deleted. Response-body is intentionally empty."), @ApiResponse(code = 404, message = "Indicates the requested user was not found.") }) @DeleteMapping("/users/{userId}") public void deleteUser(@ApiParam(name = "userId") @PathVariable String userId, HttpServletResponse response) { User user = getUserFromRequest(userId); if (restApiInterceptor != null) { restApiInterceptor.deleteUser(user); } identityService.deleteUser(user.getId()); response.setStatus(HttpStatus.NO_CONTENT.value()); } }
@RequestMapping(value = "/profile", method = RequestMethod.GET, produces = "application/json") public UserRepresentation getProfile() { User user = SecurityUtils.getCurrentFlowableAppUser().getUserObject(); UserRepresentation userRepresentation = new UserRepresentation(user); for (Group group : groupService.getGroupsForUser(user.getId())) { userRepresentation.getGroups().add(new GroupRepresentation(group)); } return userRepresentation; }
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); }
@Override public Token createToken(User user, String remoteAddress, String userAgent) { Token token = idmIdentityService.newToken(generateSeriesData()); token.setTokenValue(generateTokenData()); token.setTokenDate(new Date()); token.setIpAddress(remoteAddress); token.setUserAgent(userAgent); token.setUserId(user.getId()); try { saveAndFlush(token); return token; } catch (DataAccessException e) { LOGGER.error("Failed to save persistent token ", e); return token; } }