@Test void testGenerateDefaultRootAclBadResource() throws Exception { final String resource = "badTurtle.ttl"; final IRI rootAuth = rdf.createIRI(TRELLIS_DATA_PREFIX + "#auth"); try (final Dataset dataset = WebAcService.generateDefaultRootAuthorizationsDataset(resource)) { assertEquals(7L, dataset.size()); assertTrue(dataset.contains(of(PreferAccessControl), rootAuth, ACL.mode, ACL.Read)); assertTrue(dataset.contains(of(PreferAccessControl), rootAuth, ACL.mode, ACL.Write)); assertTrue(dataset.contains(of(PreferAccessControl), rootAuth, ACL.mode, ACL.Append)); assertTrue(dataset.contains(of(PreferAccessControl), rootAuth, ACL.mode, ACL.Control)); assertTrue(dataset.contains(of(PreferAccessControl), rootAuth, ACL.default_, rootIRI)); assertTrue(dataset.contains(of(PreferAccessControl), rootAuth, ACL.accessTo, rootIRI)); assertTrue(dataset.contains(of(PreferAccessControl), rootAuth, ACL.agentClass, FOAF.Agent)); } }
static Dataset generateDefaultRootAuthorizationsDataset(final String resource) { final Dataset dataset = rdf.createDataset(); final Model model = createDefaultModel(); try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { if (is != null) { LOGGER.debug("Using classpath resource for default root ACL: {}", resource); RDFParser.source(is).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } else { LOGGER.debug("Using external resource for default root ACL: {}", resource); RDFParser.source(resource).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } fromJena(model.getGraph()).stream().map(triple -> rdf.createQuad(Trellis.PreferAccessControl, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEach(dataset::add); } catch (final IOException | RiotException ex) { LOGGER.warn("Couldn't initialize root ACL with {}, falling back to default: {}", resource, ex.getMessage()); } finally { model.close(); } if (dataset.size() == 0) { dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Read)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Write)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Control)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Append)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.agentClass, FOAF.Agent)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.default_, root)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.accessTo, root)); } return dataset; }
WebAcService { static Dataset generateDefaultRootAuthorizationsDataset(final String resource) { final Dataset dataset = rdf.createDataset(); final Model model = createDefaultModel(); try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { if (is != null) { LOGGER.debug("Using classpath resource for default root ACL: {}", resource); RDFParser.source(is).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } else { LOGGER.debug("Using external resource for default root ACL: {}", resource); RDFParser.source(resource).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } fromJena(model.getGraph()).stream().map(triple -> rdf.createQuad(Trellis.PreferAccessControl, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEach(dataset::add); } catch (final IOException | RiotException ex) { LOGGER.warn("Couldn't initialize root ACL with {}, falling back to default: {}", resource, ex.getMessage()); } finally { model.close(); } if (dataset.size() == 0) { dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Read)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Write)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Control)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Append)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.agentClass, FOAF.Agent)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.default_, root)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.accessTo, root)); } return dataset; } }
WebAcService { static Dataset generateDefaultRootAuthorizationsDataset(final String resource) { final Dataset dataset = rdf.createDataset(); final Model model = createDefaultModel(); try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { if (is != null) { LOGGER.debug("Using classpath resource for default root ACL: {}", resource); RDFParser.source(is).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } else { LOGGER.debug("Using external resource for default root ACL: {}", resource); RDFParser.source(resource).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } fromJena(model.getGraph()).stream().map(triple -> rdf.createQuad(Trellis.PreferAccessControl, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEach(dataset::add); } catch (final IOException | RiotException ex) { LOGGER.warn("Couldn't initialize root ACL with {}, falling back to default: {}", resource, ex.getMessage()); } finally { model.close(); } if (dataset.size() == 0) { dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Read)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Write)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Control)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Append)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.agentClass, FOAF.Agent)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.default_, root)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.accessTo, root)); } return dataset; } WebAcService(); @Inject  WebAcService(final ResourceService resourceService,
            @TrellisAuthorizationCache final CacheService<String, AuthorizedModes> cache); private  WebAcService(final ResourceService resourceService, final CacheService<String, AuthorizedModes> cache,
            final Config config);  WebAcService(final ResourceService resourceService, final CacheService<String, AuthorizedModes> cache,
            final boolean checkMembershipResources, final String defaultAuthResourceLocation); }
WebAcService { static Dataset generateDefaultRootAuthorizationsDataset(final String resource) { final Dataset dataset = rdf.createDataset(); final Model model = createDefaultModel(); try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { if (is != null) { LOGGER.debug("Using classpath resource for default root ACL: {}", resource); RDFParser.source(is).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } else { LOGGER.debug("Using external resource for default root ACL: {}", resource); RDFParser.source(resource).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } fromJena(model.getGraph()).stream().map(triple -> rdf.createQuad(Trellis.PreferAccessControl, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEach(dataset::add); } catch (final IOException | RiotException ex) { LOGGER.warn("Couldn't initialize root ACL with {}, falling back to default: {}", resource, ex.getMessage()); } finally { model.close(); } if (dataset.size() == 0) { dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Read)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Write)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Control)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Append)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.agentClass, FOAF.Agent)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.default_, root)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.accessTo, root)); } return dataset; } WebAcService(); @Inject  WebAcService(final ResourceService resourceService,
            @TrellisAuthorizationCache final CacheService<String, AuthorizedModes> cache); private  WebAcService(final ResourceService resourceService, final CacheService<String, AuthorizedModes> cache,
            final Config config);  WebAcService(final ResourceService resourceService, final CacheService<String, AuthorizedModes> cache,
            final boolean checkMembershipResources, final String defaultAuthResourceLocation); @PostConstruct void initialize(); Set<IRI> getAccessModes(final IRI identifier, final Session session); AuthorizedModes getAuthorizedModes(final IRI identifier, final Session session); static String generateCacheKey(final IRI identifier, final IRI agent); }
WebAcService { static Dataset generateDefaultRootAuthorizationsDataset(final String resource) { final Dataset dataset = rdf.createDataset(); final Model model = createDefaultModel(); try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) { if (is != null) { LOGGER.debug("Using classpath resource for default root ACL: {}", resource); RDFParser.source(is).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } else { LOGGER.debug("Using external resource for default root ACL: {}", resource); RDFParser.source(resource).lang(TURTLE).base(TRELLIS_DATA_PREFIX).parse(model); } fromJena(model.getGraph()).stream().map(triple -> rdf.createQuad(Trellis.PreferAccessControl, triple.getSubject(), triple.getPredicate(), triple.getObject())).forEach(dataset::add); } catch (final IOException | RiotException ex) { LOGGER.warn("Couldn't initialize root ACL with {}, falling back to default: {}", resource, ex.getMessage()); } finally { model.close(); } if (dataset.size() == 0) { dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Read)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Write)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Control)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.mode, ACL.Append)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.agentClass, FOAF.Agent)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.default_, root)); dataset.add(rdf.createQuad(Trellis.PreferAccessControl, rootAuth, ACL.accessTo, root)); } return dataset; } WebAcService(); @Inject  WebAcService(final ResourceService resourceService,
            @TrellisAuthorizationCache final CacheService<String, AuthorizedModes> cache); private  WebAcService(final ResourceService resourceService, final CacheService<String, AuthorizedModes> cache,
            final Config config);  WebAcService(final ResourceService resourceService, final CacheService<String, AuthorizedModes> cache,
            final boolean checkMembershipResources, final String defaultAuthResourceLocation); @PostConstruct void initialize(); Set<IRI> getAccessModes(final IRI identifier, final Session session); AuthorizedModes getAuthorizedModes(final IRI identifier, final Session session); static String generateCacheKey(final IRI identifier, final IRI agent); static final String CONFIG_WEBAC_MEMBERSHIP_CHECK; static final String CONFIG_WEBAC_DEFAULT_ACL_LOCATION; static final String CONFIG_WEBAC_INITIALIZE_ROOT_ACL; static final String DEFAULT_ACL_LOCATION; }