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); } } }
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); }
user.setPassword(userRequest.getPassword()); identityService.updateUserPassword(user); } else {
@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); }
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 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 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; } }