@Test void testFilterGenericFederated() throws Exception { final String passphrase = "password"; try { final String keystorePath = OAuthUtilsTest.class.getResource("/keystore.jks").getPath(); System.setProperty(OAuthFilter.CONFIG_AUTH_OAUTH_KEYSTORE_PATH, keystorePath); System.setProperty(OAuthFilter.CONFIG_AUTH_OAUTH_KEYSTORE_CREDENTIALS, passphrase); System.setProperty(OAuthFilter.CONFIG_AUTH_OAUTH_KEYSTORE_IDS, "trellis,trellis-ec"); final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(getClass().getResourceAsStream("/keystore.jks"), passphrase.toCharArray()); final Key privateKey = ks.getKey("trellis", passphrase.toCharArray()); final String token = Jwts.builder().setHeaderParam(JwsHeader.KEY_ID, "trellis") .setSubject(WEBID2).signWith(privateKey, SignatureAlgorithm.RS256).compact(); when(mockContext.getHeaderString(AUTHORIZATION)).thenReturn("Bearer " + token); final OAuthFilter filter = new OAuthFilter(); filter.filter(mockContext); verify(mockContext).setSecurityContext(securityArgument.capture()); assertEquals(WEBID2, securityArgument.getValue().getUserPrincipal().getName(), "Unexpected agent IRI!"); } finally { System.clearProperty(OAuthFilter.CONFIG_AUTH_OAUTH_KEYSTORE_PATH); System.clearProperty(OAuthFilter.CONFIG_AUTH_OAUTH_KEYSTORE_CREDENTIALS); System.clearProperty(OAuthFilter.CONFIG_AUTH_OAUTH_KEYSTORE_IDS); } }
@Override public void filter(final ContainerRequestContext requestContext) { final SecurityContext securityContext = requestContext.getSecurityContext(); final boolean secure = securityContext != null && securityContext.isSecure(); final String token = getOAuthToken(requestContext); if (token != null) { final Principal principal = authenticate(token); if (principal == null) throw new NotAuthorizedException(challenge); requestContext.setSecurityContext(new OAuthSecurityContext(principal, admins, secure)); } }
OAuthFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext requestContext) { final SecurityContext securityContext = requestContext.getSecurityContext(); final boolean secure = securityContext != null && securityContext.isSecure(); final String token = getOAuthToken(requestContext); if (token != null) { final Principal principal = authenticate(token); if (principal == null) throw new NotAuthorizedException(challenge); requestContext.setSecurityContext(new OAuthSecurityContext(principal, admins, secure)); } } }
OAuthFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext requestContext) { final SecurityContext securityContext = requestContext.getSecurityContext(); final boolean secure = securityContext != null && securityContext.isSecure(); final String token = getOAuthToken(requestContext); if (token != null) { final Principal principal = authenticate(token); if (principal == null) throw new NotAuthorizedException(challenge); requestContext.setSecurityContext(new OAuthSecurityContext(principal, admins, secure)); } } OAuthFilter(); }
OAuthFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext requestContext) { final SecurityContext securityContext = requestContext.getSecurityContext(); final boolean secure = securityContext != null && securityContext.isSecure(); final String token = getOAuthToken(requestContext); if (token != null) { final Principal principal = authenticate(token); if (principal == null) throw new NotAuthorizedException(challenge); requestContext.setSecurityContext(new OAuthSecurityContext(principal, admins, secure)); } } OAuthFilter(); void setAuthenticator(final Authenticator authenticator); void setChallenge(final String challenge); void setAdmins(final Set<String> admins); @Override void filter(final ContainerRequestContext requestContext); }
OAuthFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext requestContext) { final SecurityContext securityContext = requestContext.getSecurityContext(); final boolean secure = securityContext != null && securityContext.isSecure(); final String token = getOAuthToken(requestContext); if (token != null) { final Principal principal = authenticate(token); if (principal == null) throw new NotAuthorizedException(challenge); requestContext.setSecurityContext(new OAuthSecurityContext(principal, admins, secure)); } } OAuthFilter(); void setAuthenticator(final Authenticator authenticator); void setChallenge(final String challenge); void setAdmins(final Set<String> admins); @Override void filter(final ContainerRequestContext requestContext); static final String CONFIG_AUTH_ADMIN_USERS; static final String CONFIG_AUTH_REALM; static final String CONFIG_AUTH_OAUTH_KEYSTORE_PATH; static final String CONFIG_AUTH_OAUTH_KEYSTORE_CREDENTIALS; static final String CONFIG_AUTH_OAUTH_KEYSTORE_IDS; static final String CONFIG_AUTH_OAUTH_SHARED_SECRET; static final String CONFIG_AUTH_OAUTH_JWK_URL; static final String SCHEME; }