@GET @Path("login") public Response login() { LOGGER.log(Level.INFO, "login"); if (securityContext.getCallerPrincipal() != null) { JsonObject result = Json.createObjectBuilder() .add("user", securityContext.getCallerPrincipal().getName()) .build(); return Response.ok(result).build(); } return Response.status(UNAUTHORIZED).build(); }
@GET @Path("read") @PermitAll public Response read() { LOGGER.log(Level.INFO, "read"); JsonObject result = Json.createObjectBuilder() .add("user", securityContext.getCallerPrincipal() != null ? securityContext.getCallerPrincipal().getName() : "Anonymous") .add("message", "Read resource") .build(); return Response.ok(result).build(); }
@POST @Path("write") // @RolesAllowed({USER, ADMIN}) public Response write() { LOGGER.log(Level.INFO, "write"); JsonObject result = Json.createObjectBuilder() .add("user", securityContext.getCallerPrincipal().getName()) .add("message", "Write resource") .build(); return Response.ok(result).build(); }
@DELETE @Path("delete") // @RolesAllowed({ADMIN}) public Response delete() { LOGGER.log(Level.INFO, "delete"); JsonObject result = Json.createObjectBuilder() .add("user", securityContext.getCallerPrincipal().getName()) .add("message", "Delete resource") .build(); return Response.ok(result).build(); } }