Search in sources :

Example 26 with UserMessage

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());
}
Also used : UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 27 with UserMessage

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());
}
Also used : UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) IsReceivingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsReceivingAsyncMessage)

Example 28 with UserMessage

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());
}
Also used : UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) IsReceivingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsReceivingAsyncMessage)

Example 29 with UserMessage

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

Example 30 with UserMessage

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());
}
Also used : UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) IsReceivingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsReceivingAsyncMessage)

Aggregations

UserMessage (com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage)38 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)21 IsReceivingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsReceivingAsyncMessage)11 IsSendingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)10 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)5 NotAcceptableException (com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException)2 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Validated (org.springframework.validation.annotation.Validated)2 UseCaseAdminDeletesUser (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser)1 UseCaseAdminUpdatesUserEmailAddress (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUpdatesUserEmailAddress)1