@Test void testFilterGenericJwks() throws Exception { final BigInteger exponent = new BigInteger(1, getUrlDecoder().decode("VRPRBm9dCoAJfBbEz5oAHEz7Tnm0i0O6m5yj7N" + "wqAZOj9i4ZwgZ8VZQo88oxZQWNaYd1yKeoQhUsJija_vxQEPXO1Q2q6OqMcwTBH0wyGhIFp--z2dAyRlDVLUTQbJUXyqammdh7b16-i" + "gH-BB67jfolM-cw-O7YaN7GrxCCYX5bI38IipeYfcroeIUXdLYmmUdNy7c8P2_K4O-iHQ6A4AUtQRUOzt2FGOdmlGZihupI9YprshIy" + "9CZq_iA3BcOl4Gcc-ljwwUzT0M_4jt53DCV7oxqWVt9WRdYDNoD62g2FzQ-1nYUqsz4YChk1MuOPV1xFpRklwSpt5dfhuldnbQ")); final BigInteger modulus = new BigInteger(1, getUrlDecoder().decode("oMyjaeUbmnqojRpMBDbWbfBFitd_dQcFJ96CDWw" + "zsVcyAK3_kp4dEvhc2KLBjrmE69gJ-4HRuPF-kulDEmpC-MVx9eOihdUG9XV0ZA_eYWj9RoI_Gt3TUqTxlQH_nJRADTfy82fOCCboKp" + "aQ2idZH55Vb0FDbau2b2462tYRmcnxTFjClP4fDTTubI-3oFJ4tKMjynvUT34mCrZPiM8Q4noxVoyRYpzUTL1USxdUf56IKSB8NduH4" + "38zhMXE5VLC6PzhR3i_4KKpe4nq2otsrJ3KlEc7Me6UeiMXxPYz8rrPovW5L3LFWDmntGs5q923fBZFLFg8yBgMdTineaahEQ")); try { System.setProperty(OAuthFilter.CONFIG_AUTH_OAUTH_JWK_URL, "https: final Key key = KeyFactory.getInstance("RSA").generatePrivate(new RSAPrivateKeySpec(modulus, exponent)); final String token = Jwts.builder().setHeaderParam(JwsHeader.KEY_ID, "trellis-test") .setSubject(WEBID2).signWith(key).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_JWK_URL); } }
@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; }