use of com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage in project sechub by mercedes-benz.
the class AnonymousUserRequestsNewApiTokenServiceTest method when_emailadress_found_a_new_async_event_is_sent_eventbus.
@Test
public void when_emailadress_found_a_new_async_event_is_sent_eventbus() throws Exception {
User user = new User();
user.emailAdress = "user@test.com";
user.name = "testuser";
/* prepare */
when(mockedUserRepository.findByEmailAdress("user@test.com")).thenReturn(Optional.of(user));
/* execute */
serviceToTest.anonymousRequestToGetNewApiTokenForUserMailAdress("user@test.com");
/* test */
ArgumentCaptor<DomainMessage> domainMessageCaptor = ArgumentCaptor.forClass(DomainMessage.class);
verify(mockedEventBusService).sendAsynchron(domainMessageCaptor.capture());
DomainMessage messageSendByService = domainMessageCaptor.getValue();
assertNotNull("no message send!", messageSendByService);
UserMessage refreshApiKeyMessage = messageSendByService.get(MessageDataKeys.USER_ONE_TIME_TOKEN_INFO);
assertNotNull("no refersh api key data inside message!", refreshApiKeyMessage);
// check event contains expected data
// user id not inside
assertNull(refreshApiKeyMessage.getUserId());
assertEquals("user@test.com", refreshApiKeyMessage.getEmailAdress());
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage in project sechub by mercedes-benz.
the class AuthMessageHandler method handleUserApiTokenChanged.
@IsReceivingAsyncMessage(MessageID.USER_API_TOKEN_CHANGED)
private void handleUserApiTokenChanged(DomainMessage request) {
UserMessage userMessage = request.get(MessageDataKeys.USER_API_TOKEN_DATA);
userAuthTokenUpdateService.updateAPIToken(userMessage.getUserId(), userMessage.getHashedApiToken());
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage in project sechub by mercedes-benz.
the class AuthMessageHandler method handleUserCreation.
@IsReceivingAsyncMessage(MessageID.USER_CREATED)
private void handleUserCreation(DomainMessage request) {
UserMessage userMessage = request.get(MessageDataKeys.USER_CREATION_DATA);
userAuthCreationService.createUser(userMessage.getUserId(), userMessage.getHashedApiToken());
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage 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);
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage in project sechub by mercedes-benz.
the class ScheduleMessageHandler method handleUserAddedToProject.
@IsReceivingAsyncMessage(MessageID.USER_ADDED_TO_PROJECT)
private void handleUserAddedToProject(DomainMessage request) {
UserMessage data = request.get(MessageDataKeys.PROJECT_TO_USER_DATA);
grantService.grantUserAccessToProject(data.getUserId(), data.getProjectId());
}
Aggregations