Created
March 18, 2016 08:03
-
-
Save abhirockzz/b9a23f6d2de35842ad80 to your computer and use it in GitHub Desktop.
Code snippet of a JAX-RS container filter validating a JWT token
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
@Priority(Priorities.AUTHENTICATION) | |
public class JWTAuthFilter implements ContainerRequestFilter{ | |
@Override | |
public void filter(ContainerRequestContext requestContext) throws IOException { | |
String authHeaderVal = requestContext.getHeaderString("Authorization"); | |
//consume JWT i.e. execute signature validation | |
if(authHeaderVal.startsWith("Bearer")){ | |
try { | |
validate(authHeaderVal.split(" ")[1]); | |
} catch (InvalidJwtException ex) { | |
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build()); | |
} | |
}else{ | |
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment