Created
March 18, 2016 08:22
-
-
Save abhirockzz/7120429acb04186da340 to your computer and use it in GitHub Desktop.
JAX-RS container response filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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