@Test public void testSecurityContextUsesProvidedAuthorizer() throws AuthenticationException, IOException { final Authorizer<Principal> authorizer = mock(Authorizer.class); when(authorizer.authorize(any(), any())).thenReturn(true); final JsonWebTokenAuthFilter filter = createAuthFilterWithAuthorizer(authorizer); final ContainerRequestContext request = createDummyRequest(); filter.filter(request); final SecurityContext securityContext = request.getSecurityContext(); verify(authorizer, times(0)).authorize(any(), any()); final String role = TestHelpers.generateRandomString(); securityContext.isUserInRole(role); verify(authorizer, times(1)).authorize(any(), any()); }
@Override public void filter(ContainerRequestContext containerRequestContext) throws NullPointerException, WebApplicationException { final String authorizationHeaderValue = containerRequestContext.getHeaderString("Authorization"); if (authorizationHeaderValue == null) throw new WebApplicationException("Authorization header was not set.", 401); final String jwtToken = tryExtractJwtTokenFromAuthorizationHeader(authorizationHeaderValue); final P principal = this.tryAuthenticateUsingJwtToken(jwtToken); final boolean isSecure = isRequestSecure(containerRequestContext); final SecurityContext securityContext = createSecurityContext(principal, this.authorizer, isSecure); containerRequestContext.setSecurityContext(securityContext); }
JsonWebTokenAuthFilter extends AuthFilter<String, P> { @Override public void filter(ContainerRequestContext containerRequestContext) throws NullPointerException, WebApplicationException { final String authorizationHeaderValue = containerRequestContext.getHeaderString("Authorization"); if (authorizationHeaderValue == null) throw new WebApplicationException("Authorization header was not set.", 401); final String jwtToken = tryExtractJwtTokenFromAuthorizationHeader(authorizationHeaderValue); final P principal = this.tryAuthenticateUsingJwtToken(jwtToken); final boolean isSecure = isRequestSecure(containerRequestContext); final SecurityContext securityContext = createSecurityContext(principal, this.authorizer, isSecure); containerRequestContext.setSecurityContext(securityContext); } }
JsonWebTokenAuthFilter extends AuthFilter<String, P> { @Override public void filter(ContainerRequestContext containerRequestContext) throws NullPointerException, WebApplicationException { final String authorizationHeaderValue = containerRequestContext.getHeaderString("Authorization"); if (authorizationHeaderValue == null) throw new WebApplicationException("Authorization header was not set.", 401); final String jwtToken = tryExtractJwtTokenFromAuthorizationHeader(authorizationHeaderValue); final P principal = this.tryAuthenticateUsingJwtToken(jwtToken); final boolean isSecure = isRequestSecure(containerRequestContext); final SecurityContext securityContext = createSecurityContext(principal, this.authorizer, isSecure); containerRequestContext.setSecurityContext(securityContext); }  }
JsonWebTokenAuthFilter extends AuthFilter<String, P> { @Override public void filter(ContainerRequestContext containerRequestContext) throws NullPointerException, WebApplicationException { final String authorizationHeaderValue = containerRequestContext.getHeaderString("Authorization"); if (authorizationHeaderValue == null) throw new WebApplicationException("Authorization header was not set.", 401); final String jwtToken = tryExtractJwtTokenFromAuthorizationHeader(authorizationHeaderValue); final P principal = this.tryAuthenticateUsingJwtToken(jwtToken); final boolean isSecure = isRequestSecure(containerRequestContext); final SecurityContext securityContext = createSecurityContext(principal, this.authorizer, isSecure); containerRequestContext.setSecurityContext(securityContext); }  @Override void filter(ContainerRequestContext containerRequestContext); }
JsonWebTokenAuthFilter extends AuthFilter<String, P> { @Override public void filter(ContainerRequestContext containerRequestContext) throws NullPointerException, WebApplicationException { final String authorizationHeaderValue = containerRequestContext.getHeaderString("Authorization"); if (authorizationHeaderValue == null) throw new WebApplicationException("Authorization header was not set.", 401); final String jwtToken = tryExtractJwtTokenFromAuthorizationHeader(authorizationHeaderValue); final P principal = this.tryAuthenticateUsingJwtToken(jwtToken); final boolean isSecure = isRequestSecure(containerRequestContext); final SecurityContext securityContext = createSecurityContext(principal, this.authorizer, isSecure); containerRequestContext.setSecurityContext(securityContext); }  @Override void filter(ContainerRequestContext containerRequestContext);  }