use of com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUpdatesUserEmailAddress in project sechub by mercedes-benz.
the class UserEmailAddressUpdateService method updateUserEmailAddress.
/* @formatter:off */
@Validated
@UseCaseAdminUpdatesUserEmailAddress(@Step(number = 2, name = "Service updates user email address.", next = { 3 }, description = "The service will update the user email address and also trigger events."))
/* @formatter:on */
@Transactional
public void updateUserEmailAddress(String userId, String newEmailAddress) {
assertion.assertIsValidUserId(userId);
assertion.assertIsValidEmailAddress(newEmailAddress);
User user = userRepository.findOrFailUser(userId);
String formerEmailAddress = user.getEmailAdress();
if (newEmailAddress.equalsIgnoreCase(formerEmailAddress)) {
throw new NotAcceptableException("User has already this email address");
}
/* parameters valid, we audit log the change */
auditLogService.log("Changed email adress of user {}", logSanitizer.sanitize(userId, 30));
user.emailAdress = newEmailAddress;
/* create message containing data before user email has changed */
UserMessage message = new UserMessage();
message.setUserId(user.getName());
message.setEmailAdress(user.getEmailAdress());
message.setFormerEmailAddress(formerEmailAddress);
message.setSubject("A SecHub administrator has changed your email address");
userRepository.save(user);
informUserEmailAddressUpdated(message);
}
Aggregations