@Test void testSessionBuilderNoSlash() { when(mockSecurityContext.getUserPrincipal()).thenReturn(mockPrincipal); when(mockSecurityContext.isUserInRole(anyString())).thenReturn(false); when(mockPrincipal.getName()).thenReturn(webid); when(mockContext.getSecurityContext()).thenReturn(mockSecurityContext); final String baseUrl = "https: final Session session = WebAcFilter.buildSession(mockContext, baseUrl); assertEquals("trellis:data/user#me", session.getAgent().getIRIString()); }
static Session buildSession(final ContainerRequestContext ctx, final String baseUrl) { final Session session = HttpSession.from(ctx.getSecurityContext()); final String context = getBaseUrl(ctx, baseUrl); if (session.getAgent().getIRIString().startsWith(context)) { final String path = session.getAgent().getIRIString().substring(context.length()); if (path.startsWith(SLASH)) { return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path.substring(1))); } return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path)); } return session; }
WebAcFilter implements ContainerRequestFilter, ContainerResponseFilter { static Session buildSession(final ContainerRequestContext ctx, final String baseUrl) { final Session session = HttpSession.from(ctx.getSecurityContext()); final String context = getBaseUrl(ctx, baseUrl); if (session.getAgent().getIRIString().startsWith(context)) { final String path = session.getAgent().getIRIString().substring(context.length()); if (path.startsWith(SLASH)) { return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path.substring(1))); } return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path)); } return session; } }
WebAcFilter implements ContainerRequestFilter, ContainerResponseFilter { static Session buildSession(final ContainerRequestContext ctx, final String baseUrl) { final Session session = HttpSession.from(ctx.getSecurityContext()); final String context = getBaseUrl(ctx, baseUrl); if (session.getAgent().getIRIString().startsWith(context)) { final String path = session.getAgent().getIRIString().substring(context.length()); if (path.startsWith(SLASH)) { return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path.substring(1))); } return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path)); } return session; } WebAcFilter(); }
WebAcFilter implements ContainerRequestFilter, ContainerResponseFilter { static Session buildSession(final ContainerRequestContext ctx, final String baseUrl) { final Session session = HttpSession.from(ctx.getSecurityContext()); final String context = getBaseUrl(ctx, baseUrl); if (session.getAgent().getIRIString().startsWith(context)) { final String path = session.getAgent().getIRIString().substring(context.length()); if (path.startsWith(SLASH)) { return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path.substring(1))); } return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path)); } return session; } WebAcFilter(); @Inject void setAccessService(final WebAcService accessService); @Inject void setResourceService(final ResourceService resourceService); void setChallenges(final List<String> challenges); void setBaseUrl(final String baseUrl); @Timed @Override void filter(final ContainerRequestContext ctx); @Override void filter(final ContainerRequestContext req, final ContainerResponseContext res); }
WebAcFilter implements ContainerRequestFilter, ContainerResponseFilter { static Session buildSession(final ContainerRequestContext ctx, final String baseUrl) { final Session session = HttpSession.from(ctx.getSecurityContext()); final String context = getBaseUrl(ctx, baseUrl); if (session.getAgent().getIRIString().startsWith(context)) { final String path = session.getAgent().getIRIString().substring(context.length()); if (path.startsWith(SLASH)) { return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path.substring(1))); } return new HttpSession(rdf.createIRI(TRELLIS_DATA_PREFIX + path)); } return session; } WebAcFilter(); @Inject void setAccessService(final WebAcService accessService); @Inject void setResourceService(final ResourceService resourceService); void setChallenges(final List<String> challenges); void setBaseUrl(final String baseUrl); @Timed @Override void filter(final ContainerRequestContext ctx); @Override void filter(final ContainerRequestContext req, final ContainerResponseContext res); static final String CONFIG_WEBAC_CHALLENGES; static final String CONFIG_WEBAC_READABLE_METHODS; static final String CONFIG_WEBAC_WRITABLE_METHODS; static final String CONFIG_WEBAC_APPENDABLE_METHODS; static final String CONFIG_WEBAC_REALM; static final String CONFIG_WEBAC_SCOPE; static final String CONFIG_WEBAC_ENABED; static final String SESSION_WEBAC_MODES; }