diff --git a/src/main/java/com/covas/Json/Message.java b/src/main/java/com/covas/Json/Message.java deleted file mode 100644 index 57f5d85..0000000 --- a/src/main/java/com/covas/Json/Message.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.covas.Json; - -import io.quarkus.runtime.annotations.RegisterForReflection; - -@RegisterForReflection -public class Message { - - public String name; - public Boolean status; - public String message; - - public Message(){ - name = ""; - status = true; - message = ""; - } - - public Message(String name){ - this.name = name; - status = true; - message = ""; - } - - - - public Message(String name, String message){ - this.name = name; - this.message = message; - status = true; - } - - public Message(String name, Boolean status, String message){ - this.name = name; - this.status = status; - this.message = message; - } - -} diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index 883cc74..f1864f4 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -16,7 +16,6 @@ import javax.ws.rs.core.Response; import com.covas.Classes.Hash; import com.covas.Entity.UsersEntity; -import com.covas.Json.Message; import io.smallrye.jwt.auth.principal.JWTParser; import io.smallrye.jwt.auth.principal.ParseException; @@ -54,14 +53,14 @@ public class TokenRessource { String newJwtCookie = Jwt.issuer("https://example.com/issuer").upn(name).groups(new HashSet<>(Arrays.asList(users.roles))).sign(); // or create a JWT token encrypted using the 'A256KW' algorithm // Jwt.upn("alice").encryptWithSecret(secret); - return Response.status(Response.Status.CREATED).entity(new Message(name, "Token is generated")).cookie(new NewCookie("jwt", newJwtCookie)).build(); + return Response.status(Response.Status.CREATED).cookie(new NewCookie("jwt", newJwtCookie)).build(); } else { - return Response.status(Response.Status.FORBIDDEN).entity(new Message(name, false, "Password is incorrect")).build(); + return Response.status(Response.Status.FORBIDDEN).build(); } } - return Response.status(Response.Status.NOT_FOUND).entity(new Message(name, false, "User not found")).build(); + return Response.status(Response.Status.NOT_FOUND).build(); } else { // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized. @@ -69,10 +68,10 @@ public class TokenRessource { jwt = parser.parse(jwtCookie); } catch(ParseException p){ - return Response.status(Response.Status.NOT_ACCEPTABLE).entity(new Message(name, false, p.getMessage())).build(); + return Response.status(Response.Status.UNAUTHORIZED).build(); } // or jwt = parser.decrypt(jwtCookie, secret); - return Response.status(Response.Status.OK).entity(new Message(jwt.getName(),"Token is still valid")).build(); + return Response.status(Response.Status.OK).build(); } } } diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 39ac060..ade1086 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -2,6 +2,7 @@ package com.covas.Resources; import java.util.UUID; +import javax.annotation.security.RolesAllowed; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -19,11 +20,13 @@ import org.jboss.logging.Logger; public class UsersRessources { private static final Logger LOGGER = Logger.getLogger(UsersRessources.class); @GET + @RolesAllowed({"Admin"}) public Response getUsers(){ return Response.ok(UsersEntity.listAll()).build(); } @GET + @RolesAllowed({"Admin"}) @Path("{id}") public Response getSingleUser(@PathParam("id") String id){ UUID uid = UUID.fromString(id); @@ -34,5 +37,12 @@ public class UsersRessources { return Response.ok(users).build(); } + @GET + @RolesAllowed({"User"}) + @Path("info") + public Response getInfoUser(){ + return Response.ok().build(); + } + }