Search in sources :

Example 6 with NotAcceptableException

use of com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException 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 7 with NotAcceptableException

use of com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException in project sechub by mercedes-benz.

the class FalsePositiveMetaDataFactory method createMetaData.

/**
 * Creates meta data for given finding
 *
 * @param finding
 * @return meta data, never <code>null</code>
 */
public FalsePositiveMetaData createMetaData(SecHubFinding finding) {
    ScanType type = finding.getType();
    if (type == null) {
        /* hmm.. maybe an old report where type was not set */
        SecHubCodeCallStack callstack = finding.getCode();
        if (callstack == null) {
            throw new IllegalStateException("Sorry, cannot determine scan type which is necessary for false positive handling. Please start a new scanjob and use this job UUID and retry.");
        }
        type = ScanType.CODE_SCAN;
        LOG.warn("scan type was not given - fallback to {}", type);
    }
    switch(type) {
        case CODE_SCAN:
            return createCodeScan(finding);
        case WEB_SCAN:
            return createWebScan(finding);
        default:
            throw new NotAcceptableException("A false positive handling for type " + type + " is currently not implemented!");
    }
}
Also used : ScanType(com.mercedesbenz.sechub.commons.model.ScanType) NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) SecHubCodeCallStack(com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack)

Aggregations

NotAcceptableException (com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException)7 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)3 UserMessage (com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Validated (org.springframework.validation.annotation.Validated)2 ScanType (com.mercedesbenz.sechub.commons.model.ScanType)1 SecHubCodeCallStack (com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack)1 UseCaseAdminDeletesUser (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser)1 UseCaseAdminUpdatesUserEmailAddress (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUpdatesUserEmailAddress)1 UseCaseUserApprovesJob (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserApprovesJob)1 Query (javax.persistence.Query)1