@Test void testFilterGenericWebid() { try { System.setProperty(OAuthFilter.CONFIG_AUTH_OAUTH_SHARED_SECRET, "y7MCBmoOx7TH70q1fabSGLzOrEYx+liUmLWPkwIPUTfWMXn/J5MDZuepBd8mcRObUDYYQN3MIS8p40ZT5EhvWw=="); final String token = Jwts.builder().claim("webid", WEBID1).signWith(hmacShaKeyFor(getConfig() .getValue(OAuthFilter.CONFIG_AUTH_OAUTH_SHARED_SECRET, String.class).getBytes(UTF_8))) .compact(); when(mockContext.getHeaderString(AUTHORIZATION)).thenReturn("Bearer " + token); final OAuthFilter filter = new OAuthFilter(); filter.filter(mockContext); verify(mockContext).setSecurityContext(securityArgument.capture()); assertAll("Validate security context", checkSecurityContext(securityArgument.getValue(), WEBID1)); } finally { System.clearProperty(OAuthFilter.CONFIG_AUTH_OAUTH_SHARED_SECRET); } }
@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; }