Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package org.dropwizard.auth.resource;
  2.  
  3. import com.google.common.base.Optional;
  4. import io.dropwizard.auth.Auth;
  5. import org.dropwizard.auth.core.User;
  6.  
  7. import javax.annotation.security.DenyAll;
  8. import javax.annotation.security.PermitAll;
  9. import javax.annotation.security.RolesAllowed;
  10. import javax.ws.rs.Consumes;
  11. import javax.ws.rs.GET;
  12. import javax.ws.rs.Path;
  13. import javax.ws.rs.Produces;
  14. import javax.ws.rs.core.MediaType;
  15.  
  16. @Path(AuthenticatedResource.AUTHENTICATED_PATH)
  17. @Produces(MediaType.APPLICATION_JSON)
  18. @Consumes(MediaType.APPLICATION_JSON)
  19. public class AuthenticatedResource {
  20.  
  21.     public static final String AUTHENTICATED_PATH  = "/auth";
  22.  
  23.     @Path("/anyone")
  24.     @GET
  25.     @PermitAll
  26.     public User isAnyone(@Auth User user) {
  27.         return user;
  28.     }
  29.  
  30.     @Path("/role")
  31.     @GET
  32.     @RolesAllowed("ADMIN")
  33.     public User isAdmin(@Auth User user) {
  34.         return user;
  35.     }
  36.  
  37.     @Path("/deny")
  38.     @GET
  39.     @DenyAll
  40.     public User isDenied(@Auth User user) {
  41.         return user;
  42.     }
  43.  
  44.     @Path("/optional")
  45.     @GET
  46.     public Optional<User> isOptionalAuth(@Auth Optional<User> user) {
  47.         return user.isPresent() ? user : Optional.<User>absent();
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement