Search in sources :

Example 6 with ProjectAccessLevel

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

the class ScanMessageHandler method handleProcessAccessLevelChanged.

@IsReceivingAsyncMessage(MessageID.PROJECT_ACCESS_LEVEL_CHANGED)
@UseCaseAdministratorChangesProjectAccessLevel(@Step(number = 3, name = "Event handler", description = "Receives change project access level event"))
private void handleProcessAccessLevelChanged(DomainMessage request) {
    ProjectMessage data = request.get(MessageDataKeys.PROJECT_ACCESS_LEVEL_CHANGE_DATA);
    String projectId = data.getProjectId();
    ProjectAccessLevel formerAccessLevel = data.getFormerAccessLevel();
    ProjectAccessLevel newAccessLevel = data.getNewAccessLevel();
    projectAccessLevelService.changeProjectAccessLevel(projectId, newAccessLevel, formerAccessLevel);
}
Also used : ProjectMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage) ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel) UseCaseAdministratorChangesProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel) UseCaseAdministratorChangesProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel) IsReceivingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsReceivingAsyncMessage)

Example 7 with ProjectAccessLevel

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

the class ScanProjectConfigAccessLevelService method getProjectAccessLevelOrFallback.

private ProjectAccessLevel getProjectAccessLevelOrFallback(String projectId, ProjectAccessLevel fallback) {
    ProjectAccessLevel defaultValue = fallback;
    if (defaultValue == null) {
        defaultValue = DEFAULT_ACCESS_LEVEL;
        LOG.warn("Given project access level fallback was null - should not happen. Used instead now default :{}", defaultValue.getId());
    }
    ScanProjectConfig config = scanProjectConfigService.getOrCreate(projectId, CONFIG_ID_PROJECT_ACCESS_LEVEL, false, defaultValue.getId());
    ProjectAccessLevel configuredAccessLevel = ProjectAccessLevel.fromId(config.getData());
    return configuredAccessLevel;
}
Also used : ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel)

Example 8 with ProjectAccessLevel

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

the class SchedulerProjectConfigService method changeProjectAccessLevel.

/**
 * Change the project access level for given project
 *
 * @param projectId
 * @param newAccessLevel
 * @param expectedFormerAccessLevel
 */
public void changeProjectAccessLevel(String projectId, ProjectAccessLevel newAccessLevel, ProjectAccessLevel expectedFormerAccessLevel) {
    /* validate */
    notNull(newAccessLevel, "new project access level may not be null!");
    assertService.assertProjectIdValid(projectId);
    /* change config */
    SchedulerProjectConfig config = getOrCreateConfig(projectId);
    ProjectAccessLevel configuredAccessLevel = config.getProjectAccessLevel();
    if (!Objects.equals(configuredAccessLevel, expectedFormerAccessLevel)) {
        LOG.warn("Project {} has configured access level: {} but expected former access level was:{}", projectId, configuredAccessLevel, expectedFormerAccessLevel);
    }
    config.setProjectAccessLevel(newAccessLevel);
    repository.save(config);
}
Also used : ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel)

Example 9 with ProjectAccessLevel

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

the class SchedulerProjectConfigService method isWriteAllowed.

/**
 * Checks if project can be written by normal user operations
 *
 * @param projectId
 * @return <code>true</code> when write is possible, otherwise
 *         <code>false</code>
 */
public boolean isWriteAllowed(String projectId) {
    assertService.assertProjectIdValid(projectId);
    ProjectAccessLevel accessLevel = getProjectAccessLevelOrFallback(projectId);
    return accessLevel.isEqualOrHigherThan(ProjectAccessLevel.FULL);
}
Also used : ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel)

Example 10 with ProjectAccessLevel

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

the class SchedulerProjectConfigService method isReadAllowed.

/**
 * Checks if project can be read by normal user operations
 *
 * @param projectId
 * @return <code>true</code> when read is possible, otherwise <code>false</code>
 */
public boolean isReadAllowed(String projectId) {
    assertService.assertProjectIdValid(projectId);
    ProjectAccessLevel accessLevel = getProjectAccessLevelOrFallback(projectId);
    return accessLevel.isEqualOrHigherThan(ProjectAccessLevel.READ_ONLY);
}
Also used : ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel)

Aggregations

ProjectAccessLevel (com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel)15 UseCaseAdministratorChangesProjectAccessLevel (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel)4 ProjectMessage (com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage)3 Test (org.junit.jupiter.api.Test)3 IsReceivingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsReceivingAsyncMessage)2 DeveloperAdministration (com.mercedesbenz.sechub.developertools.admin.DeveloperAdministration)1 DeveloperProjectDetailInformation (com.mercedesbenz.sechub.developertools.admin.DeveloperProjectDetailInformation)1 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)1 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)1 Test (org.junit.Test)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1