Search in sources :

Example 1 with UseCaseAdminUpdatesUserEmailAddress

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);
}
Also used : NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) Validated(org.springframework.validation.annotation.Validated) UseCaseAdminUpdatesUserEmailAddress(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUpdatesUserEmailAddress) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NotAcceptableException (com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException)1 UserMessage (com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage)1 UseCaseAdminUpdatesUserEmailAddress (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUpdatesUserEmailAddress)1 Transactional (org.springframework.transaction.annotation.Transactional)1 Validated (org.springframework.validation.annotation.Validated)1