userUpdater.update(dbSession, UpdateUser.create(userDto.getLogin())
.setEmail(user.getEmail())
.setName(user.getName())
- .setExternalIdentity(new ExternalIdentity(provider.getKey(), user.getProviderLogin())));
+ .setExternalIdentity(new ExternalIdentity(provider.getKey(), user.getProviderLogin()))
+ .setPassword(null));
return userDto.getId();
}
return this;
}
- @CheckForNull
- public String passwordConfirmation() {
- return passwordConfirmation;
- }
-
- public UpdateUser setPasswordConfirmation(@Nullable String passwordConfirmation) {
- this.passwordConfirmation = passwordConfirmation;
- passwordChanged = true;
- return this;
- }
-
@CheckForNull
public ExternalIdentity externalIdentity() {
return externalIdentity;
String password = updateUser.password();
if (updateUser.isPasswordChanged()) {
- checkPasswordChangeAllowed(updateUser.login(), messages);
validatePasswords(password, messages);
- setEncryptedPassWord(password, userDto);
+ checkPasswordChangeAllowed(updateUser.login(), messages);
+ if (Strings.isNullOrEmpty(password)) {
+ userDto.setSalt(null);
+ userDto.setCryptedPassword(null);
+ } else {
+ setEncryptedPassWord(password, userDto);
+ }
}
if (updateUser.isScmAccountsChanged()) {
}
private static void validatePasswords(@Nullable String password, List<Message> messages) {
- checkNotEmptyParam(password, PASSWORD_PARAM, messages);
+ if (password != null && password.length() == 0) {
+ messages.add(Message.of(Validation.CANT_BE_EMPTY_MESSAGE, PASSWORD_PARAM));
+ }
}
private void validateScmAccounts(DbSession dbSession, List<String> scmAccounts, @Nullable String login, @Nullable String email, @Nullable UserDto existingUser,
assertThat(updateUser.email()).isEqualTo("john@email.com");
assertThat(updateUser.externalIdentity().getProvider()).isEqualTo("github");
assertThat(updateUser.externalIdentity().getId()).isEqualTo("johndoo");
+ assertThat(updateUser.isPasswordChanged()).isTrue();
+ assertThat(updateUser.password()).isNull();
}
@Test
assertThat(dto.getEmail()).isEqualTo("marius@lesbronzes.fr");
}
+ @Test
+ public void update_password_with_null_value() {
+ db.prepareDbUnit(getClass(), "update_user.xml");
+ createDefaultGroup();
+
+ userUpdater.update(UpdateUser.create(DEFAULT_LOGIN)
+ .setPassword(null));
+ session.commit();
+ session.clearCache();
+
+ UserDto dto = userDao.selectByLogin(session, DEFAULT_LOGIN);
+ assertThat(dto.getSalt()).isNull();
+ assertThat(dto.getCryptedPassword()).isNull();
+ }
+
@Test
public void fail_to_update_password_when_external_auth_is_used() {
db.prepareDbUnit(getClass(), "update_user.xml");