Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created March 18, 2016 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/7120429acb04186da340 to your computer and use it in GitHub Desktop.
Save abhirockzz/7120429acb04186da340 to your computer and use it in GitHub Desktop.
JAX-RS container response filter
public class JWTResponseFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
System.out.println("response filter invoked...");
if (requestContext.getProperty("auth-failed") != null) {
Boolean failed = (Boolean) requestContext.getProperty("auth-failed");
if (failed) {
System.out.println("JWT auth failed. No need to return JWT token");
return;
}
}
List<Object> jwt = new ArrayList<Object>();
jwt.add(requestContext.getHeaderString("Authorization").split(" ")[1]);
responseContext.getHeaders().put("jwt", jwt);
System.out.println("Added JWT to response header 'jwt'");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment