@Override public void encodeAndSetPassword(UserCredentials userCredentials, String rawPassword) { boolean isNewPassword = StringUtils.isBlank(userCredentials.getPassword()) || !passwordManager.legacyOrCurrentMatches( rawPassword, userCredentials.getPassword(), userCredentials.getUsername()); if (isNewPassword) { userCredentials.setPasswordLastUpdated(new Date()); } userCredentials.setPassword(passwordManager.encode(rawPassword)); }
public String execute() throws Exception { UserCredentials currentUserCredentials = currentUserService.getCurrentUser() != null ? currentUserService.getCurrentUser().getUserCredentials() : null; // --------------------------------------------------------------------- // Prepare values // --------------------------------------------------------------------- if (email != null && email.trim().length() == 0) { email = null; } if (rawPassword != null && rawPassword.trim().length() == 0) { rawPassword = null; } // --------------------------------------------------------------------- // Update userCredentials and user // --------------------------------------------------------------------- Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits(); User user = userService.getUser(id); user.setSurname(surname); user.setFirstName(firstName); user.setEmail(email); user.setPhoneNumber(phoneNumber); user.updateOrganisationUnits(new HashSet<OrganisationUnit>(units)); UserCredentials userCredentials = userService.getUserCredentials(user); Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>(); for (String id : selectedList) { UserAuthorityGroup group = userService.getUserAuthorityGroup(Integer.parseInt(id)); if (currentUserCredentials != null && currentUserCredentials.canIssue(group)) { userAuthorityGroups.add(group); } } userCredentials.setUserAuthorityGroups(userAuthorityGroups); if (rawPassword != null) { userCredentials.setPassword( passwordManager.encodePassword(userCredentials.getUsername(), rawPassword)); } if (jsonAttributeValues != null) { AttributeUtils.updateAttributeValuesFromJson( user.getAttributeValues(), jsonAttributeValues, attributeService); } userService.updateUserCredentials(userCredentials); userService.updateUser(user); if (currentUserService.getCurrentUser() == user) { selectionManager.setRootOrganisationUnits(units); selectionManager.setSelectedOrganisationUnits(units); selectionTreeManager.setRootOrganisationUnits(units); selectionTreeManager.setSelectedOrganisationUnits(units); } if (units.size() > 0) { selectionManager.setSelectedOrganisationUnits(units); } return SUCCESS; }