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);
}
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);
}
Aggregations