Search in sources :

Example 1 with SecuritySettings

use of net.nemerosa.ontrack.model.settings.SecuritySettings in project ontrack by nemerosa.

the class StructureServiceImpl method getProjectList.

@Override
public List<Project> getProjectList() {
    SecuritySettings securitySettings = securityService.getSecuritySettings();
    List<Project> list = structureRepository.getProjectList();
    if (securitySettings.isGrantProjectViewToAll() || securityService.isGlobalFunctionGranted(ProjectList.class)) {
        return list;
    } else if (securityService.isLogged()) {
        return list.stream().filter(p -> securityService.isProjectFunctionGranted(p.id(), ProjectView.class)).collect(Collectors.toList());
    } else {
        throw new AccessDeniedException("Authentication is required.");
    }
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) SecuritySettings(net.nemerosa.ontrack.model.settings.SecuritySettings)

Example 2 with SecuritySettings

use of net.nemerosa.ontrack.model.settings.SecuritySettings in project ontrack by nemerosa.

the class CachedSettingsServiceIT method cache_security_settings.

@Test
public void cache_security_settings() throws Exception {
    asUser().with(GlobalSettings.class).call(() -> {
        // Gets the initial settings
        SecuritySettings s0 = settingsService.getCachedSettings(SecuritySettings.class);
        // Gets them a second time
        SecuritySettings s1 = settingsService.getCachedSettings(SecuritySettings.class);
        assertSame("The instance must have been cached", s0, s1);
        // Invalidates the cache
        settingsService.invalidate(SecuritySettings.class);
        // Gets this new version
        SecuritySettings s2 = settingsService.getCachedSettings(SecuritySettings.class);
        assertNotSame("The cached instance must have been discarded", s1, s2);
        // End
        return null;
    });
}
Also used : GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) SecuritySettings(net.nemerosa.ontrack.model.settings.SecuritySettings) Test(org.junit.Test)

Aggregations

SecuritySettings (net.nemerosa.ontrack.model.settings.SecuritySettings)2 GlobalSettings (net.nemerosa.ontrack.model.security.GlobalSettings)1 Test (org.junit.Test)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1