-
-
Save leandrogilvalle/3067f99dab7273f4ec7d25869b7fa45e to your computer and use it in GitHub Desktop.
Autorizador com ContainerRequestFilter do JAX-RS.
This file contains hidden or 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
| package br.com.caelum.payfast.auth; | |
| import java.io.IOException; | |
| import javax.ws.rs.NotAuthorizedException; | |
| import javax.ws.rs.container.ContainerRequestContext; | |
| import javax.ws.rs.container.ContainerRequestFilter; | |
| import javax.ws.rs.ext.Provider; | |
| @Provider | |
| public class Autorizador implements ContainerRequestFilter { | |
| @Override | |
| public void filter(ContainerRequestContext ctx) throws IOException { | |
| String token = ctx.getHeaderString("token"); | |
| if (!"TOKEN123".equals(token)) { | |
| throw new NotAuthorizedException("Token inválido."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment