Search in sources :

Example 1 with UseCaseAdminDeletesUser

use of com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser in project sechub by mercedes-benz.

the class UserDeleteService method deleteUser.

/* @formatter:off */
@Validated
@UseCaseAdminDeletesUser(@Step(number = 2, name = "Service deletes user.", next = { 3, 4 }, description = "The service will delete the user with dependencies and triggers asynchronous events"))
/* @formatter:on */
@Transactional
public void deleteUser(String userId) {
    auditLogService.log("Triggers delete of user {}", logSanitizer.sanitize(userId, 30));
    assertion.assertIsValidUserId(userId);
    if (userId.contentEquals(userContext.getUserId())) {
        throw new NotAcceptableException("You are not allowed to delete yourself!");
    }
    User user = userRepository.findOrFailUser(userId);
    /* create message containing data before user is deleted */
    UserMessage message = new UserMessage();
    message.setUserId(user.getName());
    message.setEmailAdress(user.getEmailAdress());
    userRepository.deleteUserWithAssociations(user.getName());
    informUserDeleted(message);
}
Also used : UseCaseAdminDeletesUser(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser) NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) Validated(org.springframework.validation.annotation.Validated) UseCaseAdminDeletesUser(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UseCaseAdminDeletesUser

use of com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser in project sechub by mercedes-benz.

the class UserDeletedNotificationService method notify.

@UseCaseAdminDeletesUser(@Step(number = 5, next = { Step.NO_NEXT_STEP }, name = "Inform user that the account has been deleted by administrator"))
public void notify(UserMessage userMessage) {
    StringBuilder emailContent = new StringBuilder();
    emailContent.append("Your account '");
    emailContent.append(userMessage.getUserId());
    emailContent.append("'");
    // emailContent.append(" for environment " + baseUrl); // not trivial; maybe add
    // this later
    emailContent.append("\nhas been removed by an administrator.\n");
    SimpleMailMessage message = factory.createMessage("SecHub account removed");
    message.setTo(userMessage.getEmailAdress());
    message.setText(emailContent.toString());
    emailService.send(message);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) UseCaseAdminDeletesUser(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser)

Aggregations

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