Created
June 22, 2012 18:49
-
-
Save yarinb/2974484 to your computer and use it in GitHub Desktop.
Simple authentication for jax-rs resources
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
@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