@Test(expected = WebApplicationException.class) public void testFilterThrowsWebApplicationExceptionIfAuthenticatorThrowsAuthenticationException() throws AuthenticationException, IOException { final Authenticator<String, Principal> authenticator = mock(Authenticator.class); when(authenticator.authenticate(any())).thenThrow(new AuthenticationException("Cannot authenticate")); final JsonWebTokenAuthFilter filter = createAuthFilterWithAuthenticator(authenticator); final ContainerRequestContext request = createDummyRequest(); filter.filter(request); }
@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);  }