Skip to content

Instantly share code, notes, and snippets.

@leandrogilvalle
Forked from alexandreaquiles/Autorizador.java
Created April 14, 2016 14:09
Show Gist options
  • Select an option

  • Save leandrogilvalle/3067f99dab7273f4ec7d25869b7fa45e to your computer and use it in GitHub Desktop.

Select an option

Save leandrogilvalle/3067f99dab7273f4ec7d25869b7fa45e to your computer and use it in GitHub Desktop.
Autorizador com ContainerRequestFilter do JAX-RS.
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