Search in sources :

Example 1 with ProjectAccessCompositeKey

use of com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey 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.");
    }
}
Also used : NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException) ProjectAccessCompositeKey(com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey)

Example 2 with ProjectAccessCompositeKey

use of com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method before.

@Before
public void before() {
    randomUUID = UUID.randomUUID();
    project1 = mock(ScheduleAccess.class);
    ProjectAccessCompositeKey key = new ProjectAccessCompositeKey("user", PROJECT1_ID);
    when(project1.getKey()).thenReturn(key);
    when(mockedProjectRepository.findById(key)).thenReturn(Optional.of(project1));
    when(sechubConfigurationValidator.supports(SecHubConfiguration.class)).thenReturn(true);
}
Also used : ScheduleAccess(com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess) ProjectAccessCompositeKey(com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey) Before(org.junit.Before)

Example 3 with ProjectAccessCompositeKey

use of com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey in project sechub by mercedes-benz.

the class SchedulerRestControllerMockTest method before.

@Before
public void before() {
    randomUUID = UUID.randomUUID();
    project1 = mock(ScheduleAccess.class);
    ProjectAccessCompositeKey key = new ProjectAccessCompositeKey("user", PROJECT1_ID);
    when(project1.getKey()).thenReturn(key);
    when(mockedProjectRepository.findById(key)).thenReturn(Optional.of(project1));
    when(sechubConfigurationValidator.supports(SecHubConfiguration.class)).thenReturn(true);
}
Also used : ScheduleAccess(com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess) ProjectAccessCompositeKey(com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey) Before(org.junit.Before)

Example 4 with ProjectAccessCompositeKey

use of com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey in project sechub by mercedes-benz.

the class ScheduleAccessCountService method countProjectAccess.

public long countProjectAccess(String projectId) {
    assertion.assertIsValidProjectId(projectId);
    ScheduleAccess probe = new ScheduleAccess();
    probe.key = new ProjectAccessCompositeKey(null, projectId);
    Example<ScheduleAccess> example = Example.of(probe);
    return repository.count(example);
}
Also used : ProjectAccessCompositeKey(com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey)

Example 5 with ProjectAccessCompositeKey

use of com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey in project sechub by mercedes-benz.

the class ScheduleRevokeUserAccessFromProjectService method revokeUserAccessFromProject.

@UseCaseAdminUnassignsUserFromProject(@Step(number = 2, name = "Update authorization parts"))
public void revokeUserAccessFromProject(String userId, String projectId) {
    assertion.assertIsValidUserId(userId);
    assertion.assertIsValidProjectId(projectId);
    ProjectAccessCompositeKey id = new ProjectAccessCompositeKey(userId, projectId);
    repository.deleteById(id);
    LOG.info("Revoked access to project:{} for user:{}", projectId, userId);
}
Also used : ProjectAccessCompositeKey(com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey) UseCaseAdminUnassignsUserFromProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject)

Aggregations

ProjectAccessCompositeKey (com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess.ProjectAccessCompositeKey)5 ScheduleAccess (com.mercedesbenz.sechub.domain.schedule.access.ScheduleAccess)2 Before (org.junit.Before)2 NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)1 UseCaseAdminUnassignsUserFromProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject)1