Skip to content

Instantly share code, notes, and snippets.

@yarinb
Created June 22, 2012 18:49
Show Gist options
  • Save yarinb/2974484 to your computer and use it in GitHub Desktop.
Save yarinb/2974484 to your computer and use it in GitHub Desktop.
Simple authentication for jax-rs resources
@Path("/secret")
public class SecretResource {
@GET
@Path("/secured")
public String showSecret(@Auth User user) {
return "Hello " + user.getUsername() + ". This is secret!";
}
@GET
@Path("/free")
public String showFree(@Auth(required = false) User user) {
if (user == null) {
return "Hello anonymous";
}
return "Hello " + user.getUsername() + ". This is a freely accessible page";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment