Created
May 12, 2020 12:48
-
-
Save dmi3coder/b38836b065c8164a86a7908d53b1a16a to your computer and use it in GitHub Desktop.
ExampleResource with security enabled
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 tech.donau.quarkify; | |
import tech.donau.quarkify.data.User; | |
import tech.donau.quarkify.security.Roles; | |
import javax.annotation.security.*; | |
import javax.ws.rs.*; | |
import javax.ws.rs.core.*; | |
@Path("/hello") | |
@Produces(MediaType.APPLICATION_JSON) | |
public class ExampleResource { | |
@Context | |
SecurityContext securityContext; | |
@GET | |
@Produces(MediaType.TEXT_PLAIN) | |
@PermitAll | |
public String hello() { | |
return "hello"; | |
} | |
@GET | |
@Path("/me") | |
@RolesAllowed({Roles.USER, Roles.SERVICE}) | |
public User me() { | |
return User.find("email", securityContext.getUserPrincipal().getName()).firstResult(); | |
} | |
@GET | |
@Path("/admin") | |
@RolesAllowed(Roles.ADMIN) | |
public String adminTest() { | |
return "If you see this text as a user, then something is broke"; | |
} | |
@GET | |
@Path("/void") | |
@DenyAll | |
public String nothing() { | |
return "This method should always return 403"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment