use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class ProjectCreationService method createProject.
@Validated
/* @formatter:off */
@UseCaseAdminCreatesProject(@Step(number = 2, name = "Create project", description = "The service will create the project when not already existing with such name."))
public /* @formatter:on */
void createProject(@NotNull String projectId, @NotNull String description, @NotNull String owner, @NotNull Set<URI> whitelist, @NotNull ProjectMetaData metaData) {
LOG.info("Administrator {} triggers create of project:{}, having owner:{}", userContext.getUserId(), projectId, owner);
assertion.assertIsValidProjectId(projectId);
assertion.assertIsValidUserId(owner);
assertion.assertIsValidProjectDescription(description);
/* assert found */
Optional<Project> foundProject = projectRepository.findById(projectId);
if (foundProject.isPresent()) {
throw new AlreadyExistsException("Project '" + projectId + "' already exists");
}
Optional<User> foundOwner = userRepository.findById(owner);
if (!foundOwner.isPresent()) {
throw new NotFoundException("Owner '" + owner + "' not found");
}
/* setup */
Project project = new Project();
project.id = projectId;
project.description = description;
User ownerUser = foundOwner.get();
project.owner = ownerUser;
/**
* add only accepted/valid URIs - sanitize
*/
whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(project.getWhiteList()::add);
List<ProjectMetaDataEntity> metaDataEntities = metaData.getMetaDataMap().entrySet().stream().map(entry -> new ProjectMetaDataEntity(projectId, entry.getKey(), entry.getValue())).collect(Collectors.toList());
project.metaData.addAll(metaDataEntities);
/* store */
persistenceService.saveInOwnTransaction(project);
sendProjectCreatedEvent(projectId, whitelist);
sendRefreshUserAuth(ownerUser);
}
use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class ProjectDetailChangeServiceTest method change_description_but_project_does_not_exist.
@Test
public void change_description_but_project_does_not_exist() {
/* prepare */
String json = "{\"description\": \"new\"}";
when(projectRepository.findOrFailProject("project2")).thenThrow(new NotFoundException());
/* execute + test */
assertThrows(NotFoundException.class, () -> {
ProjectJsonInput withNewDescription = new ProjectJsonInput();
withNewDescription = withNewDescription.fromJSON(json);
serviceToTest.changeProjectDescription("project2", withNewDescription);
});
}
use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class IntegrationTestSchedulerService method revertJobAsStillRunning.
/**
* Reverts/Marks given job as still running - will reset result, state, end
* timestamp and traffic light
*
* @param sechubJobUUID
*/
public void revertJobAsStillRunning(UUID sechubJobUUID) {
Optional<ScheduleSecHubJob> found = repository.findById(sechubJobUUID);
if (!found.isPresent()) {
throw new NotFoundException("Job not found!");
}
ScheduleSecHubJob job = found.get();
job.setExecutionResult(ExecutionResult.NONE);
job.setExecutionState(ExecutionState.STARTED);
job.setEnded(null);
job.setTrafficLight(null);
repository.save(job);
}
use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class ScheduleUserAccessToProjectValidationService method assertUserHasAccessToProject.
/**
* Assert user logged in has access to project
*
* @param projectId
*/
public void assertUserHasAccessToProject(String projectId) {
if (userContextService.isSuperAdmin()) {
if (!accessRepository.hasProjectUserAccess(projectId)) {
throw new NotFoundException("Project " + projectId + " does not exist, or no user has access at all.");
}
return;
}
String userId = userContextService.getUserId();
ProjectAccessCompositeKey key = new ProjectAccessCompositeKey(userId, projectId);
Optional<ScheduleAccess> scheduleAccess = accessRepository.findById(key);
if (!scheduleAccess.isPresent()) {
securityLogService.log(SecurityLogType.POTENTIAL_INTRUSION, "Denied user access in domain 'schedule'. userId={},projectId={}", userId, logSanitizer.sanitize(projectId, 30));
// bad guys they got a target...
throw new NotFoundException("Project " + projectId + " does not exist, or you have no access.");
}
}
use of com.mercedesbenz.sechub.sharedkernel.error.NotFoundException in project sechub by mercedes-benz.
the class ScanUserAccessToProjectValidationService method assertUserHasAccessToProject.
/**
* Assert user logged in has access to project
*
* @param projectId
*/
public void assertUserHasAccessToProject(String projectId) {
if (userContextService.isSuperAdmin()) {
/* a super admin has always access */
return;
}
String userId = userContextService.getUserId();
ProjectAccessCompositeKey key = new ProjectAccessCompositeKey(userId, projectId);
Optional<ScanAccess> project = accessRepository.findById(key);
if (!project.isPresent()) {
securityLogService.log(SecurityLogType.POTENTIAL_INTRUSION, "Denied user access in domain 'scan'. userId={},projectId={}", userId, logSanitizer.sanitize(projectId, 30));
// bad guys they got a target...
throw new NotFoundException("Project " + projectId + " does not exist, or you have no access.");
}
}
Aggregations