@Test void testAccessControlGraphError() { when(mockSession.getAgent()).thenReturn(acoburnIRI); when(mockResource.hasMetadata(eq(PreferAccessControl))).thenReturn(true); when(mockResource.stream(eq(PreferAccessControl))).thenThrow(new RuntimeException("Expected")); assertThrows(TrellisRuntimeException.class, () -> testService.getAuthorizedModes(resourceIRI, mockSession)); }
public AuthorizedModes getAuthorizedModes(final IRI identifier, final Session session) { requireNonNull(session, "A non-null session must be provided!"); if (Trellis.AdministratorAgent.equals(session.getAgent())) { return new AuthorizedModes(null, allModes); } LOGGER.debug("Looking up ACL for agent [{}] on resource [{}]", session.getAgent(), identifier); final AuthorizedModes cachedModes = cache.get(generateCacheKey(identifier, session.getAgent()), k -> getAuthz(identifier, session.getAgent())); return session.getDelegatedBy().map(delegate -> { final Set<IRI> modes = new HashSet<>(cachedModes.getAccessModes()); final AuthorizedModes delegatedModes = cache.get(generateCacheKey(identifier, delegate), k -> getAuthz(identifier, delegate)); modes.retainAll(delegatedModes.getAccessModes()); return new AuthorizedModes(cachedModes.getEffectiveAcl().orElse(null), modes); }).orElse(cachedModes); }
WebAcService { public AuthorizedModes getAuthorizedModes(final IRI identifier, final Session session) { requireNonNull(session, "A non-null session must be provided!"); if (Trellis.AdministratorAgent.equals(session.getAgent())) { return new AuthorizedModes(null, allModes); } LOGGER.debug("Looking up ACL for agent [{}] on resource [{}]", session.getAgent(), identifier); final AuthorizedModes cachedModes = cache.get(generateCacheKey(identifier, session.getAgent()), k -> getAuthz(identifier, session.getAgent())); return session.getDelegatedBy().map(delegate -> { final Set<IRI> modes = new HashSet<>(cachedModes.getAccessModes()); final AuthorizedModes delegatedModes = cache.get(generateCacheKey(identifier, delegate), k -> getAuthz(identifier, delegate)); modes.retainAll(delegatedModes.getAccessModes()); return new AuthorizedModes(cachedModes.getEffectiveAcl().orElse(null), modes); }).orElse(cachedModes); } }
WebAcService { public AuthorizedModes getAuthorizedModes(final IRI identifier, final Session session) { requireNonNull(session, "A non-null session must be provided!"); if (Trellis.AdministratorAgent.equals(session.getAgent())) { return new AuthorizedModes(null, allModes); } LOGGER.debug("Looking up ACL for agent [{}] on resource [{}]", session.getAgent(), identifier); final AuthorizedModes cachedModes = cache.get(generateCacheKey(identifier, session.getAgent()), k -> getAuthz(identifier, session.getAgent())); return session.getDelegatedBy().map(delegate -> { final Set<IRI> modes = new HashSet<>(cachedModes.getAccessModes()); final AuthorizedModes delegatedModes = cache.get(generateCacheKey(identifier, delegate), k -> getAuthz(identifier, delegate)); modes.retainAll(delegatedModes.getAccessModes()); return new AuthorizedModes(cachedModes.getEffectiveAcl().orElse(null), modes); }).orElse(cachedModes); } 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 { public AuthorizedModes getAuthorizedModes(final IRI identifier, final Session session) { requireNonNull(session, "A non-null session must be provided!"); if (Trellis.AdministratorAgent.equals(session.getAgent())) { return new AuthorizedModes(null, allModes); } LOGGER.debug("Looking up ACL for agent [{}] on resource [{}]", session.getAgent(), identifier); final AuthorizedModes cachedModes = cache.get(generateCacheKey(identifier, session.getAgent()), k -> getAuthz(identifier, session.getAgent())); return session.getDelegatedBy().map(delegate -> { final Set<IRI> modes = new HashSet<>(cachedModes.getAccessModes()); final AuthorizedModes delegatedModes = cache.get(generateCacheKey(identifier, delegate), k -> getAuthz(identifier, delegate)); modes.retainAll(delegatedModes.getAccessModes()); return new AuthorizedModes(cachedModes.getEffectiveAcl().orElse(null), modes); }).orElse(cachedModes); } 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 { public AuthorizedModes getAuthorizedModes(final IRI identifier, final Session session) { requireNonNull(session, "A non-null session must be provided!"); if (Trellis.AdministratorAgent.equals(session.getAgent())) { return new AuthorizedModes(null, allModes); } LOGGER.debug("Looking up ACL for agent [{}] on resource [{}]", session.getAgent(), identifier); final AuthorizedModes cachedModes = cache.get(generateCacheKey(identifier, session.getAgent()), k -> getAuthz(identifier, session.getAgent())); return session.getDelegatedBy().map(delegate -> { final Set<IRI> modes = new HashSet<>(cachedModes.getAccessModes()); final AuthorizedModes delegatedModes = cache.get(generateCacheKey(identifier, delegate), k -> getAuthz(identifier, delegate)); modes.retainAll(delegatedModes.getAccessModes()); return new AuthorizedModes(cachedModes.getEffectiveAcl().orElse(null), modes); }).orElse(cachedModes); } 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; }