Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created December 8, 2015 17:23
Show Gist options
  • Select an option

  • Save alexandreaquiles/d9ae77e2bb8af040c30b to your computer and use it in GitHub Desktop.

Select an option

Save alexandreaquiles/d9ae77e2bb8af040c30b 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