use of org.molgenis.security.user.MolgenisUserException in project molgenis by molgenis.
the class AccountControllerTest method activateUserMolgenisUserException.
@Test
public void activateUserMolgenisUserException() throws Exception {
doThrow(new MolgenisUserException("message")).when(accountService).activateUser("123");
this.mockMvc.perform(get("/account/activate/123")).andExpect(view().name("forward:/")).andExpect(model().attribute("warningMessage", "message"));
verify(accountService).activateUser("123");
}
use of org.molgenis.security.user.MolgenisUserException in project molgenis by molgenis.
the class AccountServiceImpl method changePassword.
@Override
@RunAsSystem
public void changePassword(String username, String newPassword) {
User user = dataService.query(USER, User.class).eq(USERNAME, username).findOne();
if (user == null) {
throw new MolgenisUserException(format("Unknown user [%s]", username));
}
user.setPassword(newPassword);
user.setChangePassword(false);
dataService.update(USER, user);
LOG.info("Changed password of user [{}]", username);
}
use of org.molgenis.security.user.MolgenisUserException in project molgenis by molgenis.
the class AccountServiceImpl method activateUser.
@Override
@RunAsSystem
public void activateUser(String activationCode) {
User user = dataService.query(USER, User.class).eq(ACTIVE, false).and().eq(ACTIVATIONCODE, activationCode).findOne();
if (user != null) {
user.setActive(true);
dataService.update(USER, user);
// send activated email to user
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(user.getEmail());
mailMessage.setSubject("Your registration request for " + appSettings.getTitle());
mailMessage.setText(createActivatedEmailText(user, appSettings.getTitle()));
mailSender.send(mailMessage);
} else {
throw new MolgenisUserException("Invalid activation code or account already activated.");
}
}
use of org.molgenis.security.user.MolgenisUserException in project molgenis by molgenis.
the class AccountServiceImpl method resetPassword.
@Override
@RunAsSystem
public void resetPassword(String userEmail) {
User user = dataService.query(USER, User.class).eq(EMAIL, userEmail).findOne();
if (user != null) {
String newPassword = idGenerator.generateId(SHORT_SECURE_RANDOM);
user.setPassword(newPassword);
user.setChangePassword(true);
dataService.update(USER, user);
// send password reseted email to user
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(user.getEmail());
mailMessage.setSubject("Your new password request");
mailMessage.setText(createPasswordResettedEmailText(newPassword));
mailSender.send(mailMessage);
} else {
throw new MolgenisUserException("Invalid email address.");
}
}
use of org.molgenis.security.user.MolgenisUserException in project molgenis by molgenis.
the class UserAccountController method validatePasswordInUpdateRequest.
private String validatePasswordInUpdateRequest(@Valid @NotNull AccountUpdateRequest updateRequest) {
// validate new password
String newPassword = updateRequest.getNewpwd();
if (!StringUtils.isEmpty(newPassword)) {
String oldPassword = updateRequest.getOldpwd();
String newPasswordConfirm = updateRequest.getNewpwd2();
// validate password for current user
if (oldPassword == null || oldPassword.isEmpty()) {
throw new MolgenisUserException("Please enter old password to update your password.");
}
boolean valid = userAccountService.validateCurrentUserPassword(oldPassword);
if (!valid)
throw new MolgenisUserException("The password you entered is incorrect.");
// validate new password against new password confirmation
if (!newPassword.equals(newPasswordConfirm)) {
throw new MolgenisUserException("'New password' does not match 'Repeat new password'.");
}
// TODO implement http://www.molgenis.org/ticket/2145
if (newPassword.length() < MIN_PASSWORD_LENGTH) {
throw new MolgenisUserException("New password must consist of at least 6 characters.");
}
}
return newPassword;
}
Aggregations