@Test void testGetWebacService() throws Exception { final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class, Validators.newValidator(), Jackson.newMinimalObjectMapper(), "") .build(new File(getClass().getResource("/config1.yml").toURI())); when(mockResourceService.get(any())).thenAnswer(inv -> completedFuture(mockResource)); when(mockResource.getMetadataGraphNames()).thenReturn(singleton(Trellis.PreferAccessControl)); assertNotNull(TrellisUtils.getWebacService(config, mockResourceService), "WebAC configuration not present!"); config.getAuth().getWebac().setEnabled(false); assertNull(TrellisUtils.getWebacService(config, mockResourceService), "WebAC config persists after disabling it!"); config.getAuth().getWebac().setEnabled(true); final ResourceService mockRS = mock(ResourceService.class, inv -> { throw new TrellisRuntimeException("expected"); }); assertThrows(TrellisRuntimeException.class, () -> TrellisUtils.getWebacService(config, mockRS)); config.getAuth().getWebac().setEnabled(false); assertNull(TrellisUtils.getWebacService(config, mockRS), "WebAC config persists after disabling it!"); }
public static WebAcService getWebacService(final TrellisConfiguration config, final ResourceService resourceService) { if (config.getAuth().getWebac().getEnabled()) { final Cache<String, AuthorizedModes> authCache = newBuilder().maximumSize(config.getAuth().getWebac() .getCacheSize()).expireAfterWrite(config.getAuth().getWebac() .getCacheExpireSeconds(), SECONDS).build(); final WebAcService webac = new WebAcService(resourceService, new TrellisCache<>(authCache)); try { webac.initialize(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Access Control system", ex); } return webac; } return null; }
TrellisUtils { public static WebAcService getWebacService(final TrellisConfiguration config, final ResourceService resourceService) { if (config.getAuth().getWebac().getEnabled()) { final Cache<String, AuthorizedModes> authCache = newBuilder().maximumSize(config.getAuth().getWebac() .getCacheSize()).expireAfterWrite(config.getAuth().getWebac() .getCacheExpireSeconds(), SECONDS).build(); final WebAcService webac = new WebAcService(resourceService, new TrellisCache<>(authCache)); try { webac.initialize(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Access Control system", ex); } return webac; } return null; } }
TrellisUtils { public static WebAcService getWebacService(final TrellisConfiguration config, final ResourceService resourceService) { if (config.getAuth().getWebac().getEnabled()) { final Cache<String, AuthorizedModes> authCache = newBuilder().maximumSize(config.getAuth().getWebac() .getCacheSize()).expireAfterWrite(config.getAuth().getWebac() .getCacheExpireSeconds(), SECONDS).build(); final WebAcService webac = new WebAcService(resourceService, new TrellisCache<>(authCache)); try { webac.initialize(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Access Control system", ex); } return webac; } return null; } private  TrellisUtils(); }
TrellisUtils { public static WebAcService getWebacService(final TrellisConfiguration config, final ResourceService resourceService) { if (config.getAuth().getWebac().getEnabled()) { final Cache<String, AuthorizedModes> authCache = newBuilder().maximumSize(config.getAuth().getWebac() .getCacheSize()).expireAfterWrite(config.getAuth().getWebac() .getCacheExpireSeconds(), SECONDS).build(); final WebAcService webac = new WebAcService(resourceService, new TrellisCache<>(authCache)); try { webac.initialize(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Access Control system", ex); } return webac; } return null; } private  TrellisUtils(); static Authenticator getJwtAuthenticator(final JwtAuthConfiguration config); static WebAcService getWebacService(final TrellisConfiguration config,
            final ResourceService resourceService); static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config); static String buildChallenge(final String scheme, final String realm, final String scope); static CORSConfiguration getCorsConfiguration(final TrellisConfiguration config); }
TrellisUtils { public static WebAcService getWebacService(final TrellisConfiguration config, final ResourceService resourceService) { if (config.getAuth().getWebac().getEnabled()) { final Cache<String, AuthorizedModes> authCache = newBuilder().maximumSize(config.getAuth().getWebac() .getCacheSize()).expireAfterWrite(config.getAuth().getWebac() .getCacheExpireSeconds(), SECONDS).build(); final WebAcService webac = new WebAcService(resourceService, new TrellisCache<>(authCache)); try { webac.initialize(); } catch (final Exception ex) { throw new TrellisRuntimeException("Error initializing Access Control system", ex); } return webac; } return null; } private  TrellisUtils(); static Authenticator getJwtAuthenticator(final JwtAuthConfiguration config); static WebAcService getWebacService(final TrellisConfiguration config,
            final ResourceService resourceService); static List<ContainerRequestFilter> getAuthFilters(final TrellisConfiguration config); static String buildChallenge(final String scheme, final String realm, final String scope); static CORSConfiguration getCorsConfiguration(final TrellisConfiguration config);  }