Add users ressources

This commit is contained in:
Valentin CZERYBA 2022-05-07 00:03:43 +02:00
parent 5c83694bce
commit 0adf2a3e31
2 changed files with 38 additions and 5 deletions

View File

@ -4,15 +4,12 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashSet;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.ws.rs.CookieParam;
import javax.ws.rs.GET;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.NewCookie;
import javax.ws.rs.core.Response;
@ -29,7 +26,7 @@ import org.eclipse.microprofile.jwt.JsonWebToken;
import org.jboss.resteasy.annotations.jaxrs.HeaderParam;
import org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64.Base64;
@Path("/token")
@Path("/api")
public class TokenRessource {
@Inject
JsonWebToken jwt;
@ -39,6 +36,7 @@ public class TokenRessource {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("token")
public Response getUserName(@HeaderParam("Authorization") String auth, @CookieParam("jwt") String jwtCookie) {
String name = "anonymous";
String password = "";

View File

@ -0,0 +1,35 @@
package com.covas.Resources;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.covas.Entity.UsersEntity;
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/api")
public class UsersRessources {
@GET
@Path("users")
public Response getUsers(){
return Response.ok(UsersEntity.listAll()).build();
}
@GET
@Path("user/{id}")
public Response getSingleUser(Long id){
UsersEntity users = UsersEntity.findById(id);
if(users == null){
return Response.status(Response.Status.NOT_FOUND).build();
}
return Response.ok(users).build();
}
}