use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.
the class ProjectAdministrationRestControllerRestDocTest method restdoc_change_project_access_level.
@Test
@UseCaseRestDoc(useCase = UseCaseAdministratorChangesProjectAccessLevel.class)
public void restdoc_change_project_access_level() throws Exception {
Class<UseCaseAdministratorChangesProjectAccessLevel> useCase = UseCaseAdministratorChangesProjectAccessLevel.class;
String apiEndpoint = https(PORT_USED).buildAdminChangesProjectAccessLevelUrl(PROJECT_ID.pathElement(), PROJECT_ACCESS_LEVEL.pathElement());
/* prepare */
StringBuilder acceptedValues = new StringBuilder();
acceptedValues.append("Accepted values: ");
for (Iterator<ProjectAccessLevel> it = Arrays.asList(ProjectAccessLevel.values()).iterator(); it.hasNext(); ) {
ProjectAccessLevel level = it.next();
acceptedValues.append(level.getId());
String description = level.getDescription();
if (description != null) {
acceptedValues.append("(");
acceptedValues.append(description);
acceptedValues.append(")");
}
if (it.hasNext()) {
acceptedValues.append(", ");
}
}
/* execute + test @formatter:off */
this.mockMvc.perform(post(apiEndpoint, "projectId1", ProjectAccessLevel.READ_ONLY.getId()).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The id for project"), parameterWithName(PROJECT_ACCESS_LEVEL.paramName()).description("The new project access level. " + acceptedValues.toString()))));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.
the class ScanProjectConfigAccessLevelService method changeProjectAccessLevel.
public void changeProjectAccessLevel(String projectId, ProjectAccessLevel newAccessLevel, ProjectAccessLevel formerAccessLevel) {
/* validate */
notNull(newAccessLevel, "New access level may not be null!");
projectIdValidation.validate(projectId);
/* change configuration */
ProjectAccessLevel configuredAccessLevel = getProjectAccessLevelOrFallback(projectId, formerAccessLevel);
if (!Objects.equals(formerAccessLevel, configuredAccessLevel)) {
/*
* In this case this could be a race condition (two events on nearly same time
* happening). So we add a warn log entry.
*/
LOG.warn("Configured access level was in scan domain:'{}' - but given fallback was: '{}'. This should not happen.", configuredAccessLevel, formerAccessLevel);
}
scanProjectConfigService.set(projectId, CONFIG_ID_PROJECT_ACCESS_LEVEL, newAccessLevel.getId());
LOG.info("Changed access level for project:{} to level:{}", projectId, newAccessLevel.getId());
}
use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.
the class ScanMessageHandlerTest method when_sending_message_id_PROJECT_ACCESS_LEVEL_CHANGED_changeProjectAccessLevel_is_called.
@Test
void when_sending_message_id_PROJECT_ACCESS_LEVEL_CHANGED_changeProjectAccessLevel_is_called() {
/* prepare */
ProjectAccessLevel newAccessLevel = ProjectAccessLevel.NONE;
ProjectAccessLevel formerAccessLevel = ProjectAccessLevel.READ_ONLY;
DomainMessage request = new DomainMessage(MessageID.PROJECT_ACCESS_LEVEL_CHANGED);
ProjectMessage content = new ProjectMessage();
content.setProjectId("projectId1");
content.setFormerAccessLevel(formerAccessLevel);
content.setNewAccessLevel(newAccessLevel);
request.set(MessageDataKeys.PROJECT_ACCESS_LEVEL_CHANGE_DATA, content);
/* execute */
simulateEventSend(request, messageHandlerToTest);
/* test */
verify(messageHandlerToTest.projectAccessLevelService).changeProjectAccessLevel("projectId1", newAccessLevel, formerAccessLevel);
}
use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.
the class ScanProjectConfigAccessLevelServiceTest method fetchProjectAccessLevel_returns_result_from_scanProjectConfigService_by_getOrCreate.
@Test
void fetchProjectAccessLevel_returns_result_from_scanProjectConfigService_by_getOrCreate() {
/* prepare */
ScanProjectConfig config = new ScanProjectConfig(ScanProjectConfigID.PROJECT_ACCESS_LEVEL, PROJECT1);
config.setData(null);
when(scanProjectConfigService.getOrCreate(eq(PROJECT1), eq(ScanProjectConfigID.PROJECT_ACCESS_LEVEL), eq(false), any())).thenReturn(config);
/* part 1: test */
ProjectAccessLevel result = serviceToTest.fetchProjectAccessLevel(PROJECT1);
/* test */
assertNull(result);
/* part 2: for each level we try out as well */
for (ProjectAccessLevel level : ProjectAccessLevel.values()) {
/* execute */
config.setData(level.getId());
result = serviceToTest.fetchProjectAccessLevel(PROJECT1);
/* test */
assertEquals(level, result);
}
}
use of com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel in project sechub by mercedes-benz.
the class ProjectChangeAccessLevelService method changeProjectAccessLevel.
/* @formatter:off */
@UseCaseAdministratorChangesProjectAccessLevel(@Step(number = 2, name = "Change access level", description = "The service will change the project access level inside administration domain and trigger a change event to inform recipients about the new situation."))
public /* @formatter:on */
void changeProjectAccessLevel(String projectId, ProjectAccessLevel wantedLevel) {
/* audit */
auditLogService.log("triggers for project:{} an access level change to '{}'", logSanitizer.sanitize(projectId, 30), wantedLevel);
/* validate */
notNull(wantedLevel, "project access level may not be null!");
assertion.assertIsValidProjectId(projectId);
Project project = projectRepository.findOrFailProject(projectId);
ProjectAccessLevel formerAccessLevel = project.getAccessLevel();
if (wantedLevel.equals(formerAccessLevel)) {
LOG.info("Access level is already '{}' for project:{}, so cancel operation", formerAccessLevel, project.getId());
return;
}
/* change */
project.accessLevel = wantedLevel;
transactionService.saveInOwnTransaction(project);
/* trigger event */
sendProjectAccessLevelChangedEvent(project, formerAccessLevel);
}
Aggregations