From 50f2cf44fa397904928a882f735b3bf15d337020 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 6 Jul 2022 23:40:10 +0200 Subject: [PATCH 01/27] add cors authorized --- src/main/resources/application.properties | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fd57f68..e494ca8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,5 +23,9 @@ quarkus.mailer.password=aohrpmqvxldwyebs quarkus.mailer.mock=false - quarkus.redis.hosts=redis://redis:6379 + +quarkus.http.cors=true +quarkus.http.origins=http://localhost:8084 +quarkus.http.cors.methods=GET,PUT,POST +quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with,x-foobar \ No newline at end of file From 37205291ad03c8f5966e63109c0921b9e7169a8f Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 13 Jul 2022 23:57:05 +0200 Subject: [PATCH 02/27] authorize credentials from axios --- src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e494ca8..60797ac 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -28,4 +28,5 @@ quarkus.redis.hosts=redis://redis:6379 quarkus.http.cors=true quarkus.http.origins=http://localhost:8084 quarkus.http.cors.methods=GET,PUT,POST -quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with,x-foobar \ No newline at end of file +quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with,x-foobar +quarkus.http.cors.access-control-allow-credentials=true \ No newline at end of file From d1c84d52617db552c90d77e2dd63888e61a6b8bb Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 19 Jul 2022 23:36:57 +0200 Subject: [PATCH 03/27] add maxages for cookie --- src/main/java/com/covas/Resources/TokenRessource.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index 9daf5e3..cd77c7a 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -10,10 +10,13 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.NewCookie; +import javax.ws.rs.core.Cookie; + import javax.ws.rs.core.Response; import com.covas.Classes.Hash; import com.covas.Entity.UsersEntity; +import com.fasterxml.jackson.datatype.jsr310.deser.DurationDeserializer; import io.smallrye.jwt.auth.principal.JWTParser; import io.smallrye.jwt.auth.principal.ParseException; @@ -64,13 +67,15 @@ public class TokenRessource { // or create a JWT token encrypted using the 'A256KW' algorithm // Jwt.upn("alice").encryptWithSecret(secret); String nameEncoded = Base64.toBase64String(name.getBytes(StandardCharsets.UTF_8)); - return Response.status(Response.Status.CREATED).cookie(new NewCookie("jwt", newJwtCookie), new NewCookie("user", nameEncoded)).build(); + return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", 60, false), new NewCookie(new Cookie("user", nameEncoded), "Username", 60, false)).build(); } // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized. + LOGGER.info(jwtCookie); try { jwt = parser.parse(jwtCookie); } catch(ParseException p){ + LOGGER.info(p); return Response.status(Response.Status.NOT_ACCEPTABLE).build(); } // or jwt = parser.decrypt(jwtCookie, secret); From bf627b304b04984007f350d87b8abd1d9dccedac Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 20 Jul 2022 19:34:29 +0200 Subject: [PATCH 04/27] remove logger --- src/main/java/com/covas/Resources/TokenRessource.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index cd77c7a..ad37588 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -70,12 +70,10 @@ public class TokenRessource { return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", 60, false), new NewCookie(new Cookie("user", nameEncoded), "Username", 60, false)).build(); } // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized. - LOGGER.info(jwtCookie); try { jwt = parser.parse(jwtCookie); } catch(ParseException p){ - LOGGER.info(p); return Response.status(Response.Status.NOT_ACCEPTABLE).build(); } // or jwt = parser.decrypt(jwtCookie, secret); From da6a38f66e26c82005dd9e3583bfcd304afd44d7 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 20 Jul 2022 19:52:14 +0200 Subject: [PATCH 05/27] change token properties --- src/main/resources/application.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 60797ac..475a250 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,6 +3,8 @@ smallrye.jwt.sign.key.location=privateKey.pem mp.jwt.verify.publickey.location=publicKey.pem mp.jwt.verify.issuer=https://example.com/issuer +mp.jwt.token.header=Cookie +mp.jwt.token.cookie=jwt quarkus.datasource.db-kind = postgresql quarkus.datasource.username = toto From 8625dd44e70ad577aad01642cd6493127e7e8590 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 20 Jul 2022 23:36:02 +0200 Subject: [PATCH 06/27] nouveaux erreurs --- src/main/java/com/covas/Entity/UsersEntity.java | 2 +- src/main/java/com/covas/Resources/TokenRessource.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 1f1d2e9..2f4f302 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -64,7 +64,7 @@ public class UsersEntity extends PanacheEntityBase { users.name = name; users.firstName = firstName; users.birth = birth; - users.status = false; + users.status = true; users.password = Hash.encryptSHA512(password); users.roles = roles; users.created_at = LocalDateTime.now(); diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index ad37588..8e3322e 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -59,8 +59,11 @@ public class TokenRessource { return Response.status(Response.Status.NOT_FOUND).build(); } if (jwtCookie == null) { - if((!password.equals(users.password)) && (!users.status)) { - return Response.status(Response.Status.FORBIDDEN).build(); + if(!password.equals(users.password)) { + return Response.status(Response.Status.NOT_ACCEPTABLE).build(); + } + if(!users.status){ + return Response.status(Response.Status.FORBIDDEN).build(); } // Create a JWT token signed using the 'HS256' algorithm String newJwtCookie = Jwt.issuer("https://example.com/issuer").upn(name).groups(users.roles).claim(Claims.kid, users.id.toString()).expiresIn(Duration.ofMinutes(1)).sign(); @@ -74,7 +77,7 @@ public class TokenRessource { jwt = parser.parse(jwtCookie); } catch(ParseException p){ - return Response.status(Response.Status.NOT_ACCEPTABLE).build(); + return Response.status(Response.Status.GONE).build(); } // or jwt = parser.decrypt(jwtCookie, secret); String kid = jwt.getClaim(Claims.kid).toString(); From 53eb700afb88b9483d298479409902e02b7a2b11 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 26 Jul 2022 00:09:17 +0200 Subject: [PATCH 07/27] add function count for admin --- .../java/com/covas/Resources/UsersRessources.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 9392a36..5aec4d8 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -77,6 +77,20 @@ public class UsersRessources { return responseHttp; } + @GET + @RolesAllowed("Admin") + @Path("count") + public Response getCount(@CookieParam("user") String userCookie, @Context SecurityContext ctx){ + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(status).build(); + if (status.equals(Response.Status.OK)){ + responseHttp = Response.ok(UsersEntity.count()).build(); + } + return responseHttp; + } + @GET @RolesAllowed("Admin") @Path("{id}") From 9bd03daf0eb8a0172b509aab8e7ac2b16f1c1c0d Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 28 Jul 2022 00:50:14 +0200 Subject: [PATCH 08/27] WIP page --- .../java/com/covas/Resources/UsersRessources.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 5aec4d8..92a4792 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -19,6 +19,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -27,6 +28,8 @@ import com.covas.Classes.Hash; import com.covas.Entity.UsersEntity; import com.covas.Json.UserSingle; +import io.quarkus.panache.common.Page; + import org.eclipse.microprofile.jwt.Claims; import org.eclipse.microprofile.jwt.JsonWebToken; import org.jboss.logging.Logger; @@ -66,13 +69,19 @@ public class UsersRessources { /// GET @GET @RolesAllowed("Admin") - public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx) { + public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages) { + if(nbPages == null){ + nbPages = 20; + } + if(page == null){ + page = 1; + } UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); Response responseHttp = Response.status(status).build(); if (status.equals(Response.Status.OK)) { - responseHttp = Response.ok(UsersEntity.listAll()).build(); + responseHttp = Response.ok(UsersEntity.findAll().page(Page.of(page, nbPages)).list()).build(); } return responseHttp; } From 948e35ae1245ff665851e1673b14f203bdc681c0 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 29 Jul 2022 23:57:41 +0200 Subject: [PATCH 09/27] change page index default --- src/main/java/com/covas/Resources/UsersRessources.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 92a4792..f2d9251 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -74,7 +74,7 @@ public class UsersRessources { nbPages = 20; } if(page == null){ - page = 1; + page = 0; } UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); From d6939de924b248b8f607acd4baaee6f27cd106c6 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 30 Jul 2022 00:20:04 +0200 Subject: [PATCH 10/27] remove token --- .../java/com/covas/Resources/TokenRessource.java | 16 ++++++++++++++-- src/main/resources/application.properties | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index 8e3322e..f975e87 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -5,6 +5,7 @@ import java.time.Duration; import javax.inject.Inject; import javax.ws.rs.CookieParam; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -66,11 +67,11 @@ public class TokenRessource { return Response.status(Response.Status.FORBIDDEN).build(); } // Create a JWT token signed using the 'HS256' algorithm - String newJwtCookie = Jwt.issuer("https://example.com/issuer").upn(name).groups(users.roles).claim(Claims.kid, users.id.toString()).expiresIn(Duration.ofMinutes(1)).sign(); + String newJwtCookie = Jwt.issuer("https://example.com/issuer").upn(name).groups(users.roles).claim(Claims.kid, users.id.toString()).expiresIn(Duration.ofMinutes(5)).sign(); // or create a JWT token encrypted using the 'A256KW' algorithm // Jwt.upn("alice").encryptWithSecret(secret); String nameEncoded = Base64.toBase64String(name.getBytes(StandardCharsets.UTF_8)); - return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", 60, false), new NewCookie(new Cookie("user", nameEncoded), "Username", 60, false)).build(); + return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", 300, false), new NewCookie(new Cookie("user", nameEncoded), "Username", 60, false)).build(); } // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized. try { @@ -86,5 +87,16 @@ public class TokenRessource { } return Response.status(Response.Status.OK).build(); } + + @DELETE + public Response deleteToken(@CookieParam("jwt") String jwtCookie) { + if(jwtCookie == null){ + return Response.status(Response.Status.BAD_REQUEST).build(); + } + + return Response.ok().cookie(new NewCookie(new Cookie("jwt", null), "", 0, false)).build(); + } + + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 475a250..edaf415 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -29,6 +29,6 @@ quarkus.redis.hosts=redis://redis:6379 quarkus.http.cors=true quarkus.http.origins=http://localhost:8084 -quarkus.http.cors.methods=GET,PUT,POST +quarkus.http.cors.methods=GET,PUT,POST,DELETE quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with,x-foobar quarkus.http.cors.access-control-allow-credentials=true \ No newline at end of file From ea34ae37c05ccc819fbeaee48aa4a1e4cf6f1a6a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 2 Aug 2022 23:21:40 +0200 Subject: [PATCH 11/27] token expire variable --- src/main/java/com/covas/Resources/TokenRessource.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index f975e87..a9ef3c6 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -42,6 +42,7 @@ public class TokenRessource { @GET @Produces(MediaType.APPLICATION_JSON) public Response tokenRefresh(@HeaderParam("Authorization") String auth, @CookieParam("user") String user, @CookieParam("jwt") String jwtCookie) { + final int expires = 300; String name = "anonymous"; String password = ""; if(auth == null){ @@ -71,7 +72,7 @@ public class TokenRessource { // or create a JWT token encrypted using the 'A256KW' algorithm // Jwt.upn("alice").encryptWithSecret(secret); String nameEncoded = Base64.toBase64String(name.getBytes(StandardCharsets.UTF_8)); - return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", 300, false), new NewCookie(new Cookie("user", nameEncoded), "Username", 60, false)).build(); + return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", expires, false), new NewCookie(new Cookie("user", nameEncoded), "Username", expires, false)).build(); } // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized. try { From 55da7253db445077a9a403cce9332248a3d5d893 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 4 Aug 2022 23:14:21 +0200 Subject: [PATCH 12/27] change status bool to short and remove active_mail --- README.md | 61 +++---------------- .../java/com/covas/Entity/UsersEntity.java | 8 +-- .../com/covas/Resources/MailRessource.java | 4 +- .../com/covas/Resources/TokenRessource.java | 2 +- .../com/covas/Resources/UsersRessources.java | 16 +++-- 5 files changed, 20 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 3824fc5..bbc54ea 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,12 @@ -# covas-quarkus Project +# Backend COVAS -This project uses Quarkus, the Supersonic Subatomic Java Framework. +C'est la partie backend du projet COVAS généré par le générateur fourni par le framework QUARKUS (Projet semblable à Spring boot de RedHat) -If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ . +## Statut de l'utilisateur -## Running the application in dev mode - -You can run your application in dev mode that enables live coding using: -```shell script -./mvnw compile quarkus:dev -``` - -> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/. - -## Packaging and running the application - -The application can be packaged using: -```shell script -./mvnw package -``` -It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory. -Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory. - -The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`. - -If you want to build an _über-jar_, execute the following command: -```shell script -./mvnw package -Dquarkus.package.type=uber-jar -``` - -The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`. - -## Creating a native executable - -You can create a native executable using: -```shell script -./mvnw package -Pnative -``` - -Or, if you don't have GraalVM installed, you can run the native executable build in a container using: -```shell script -./mvnw package -Pnative -Dquarkus.native.container-build=true -``` - -You can then execute your native executable with: `./target/covas-quarkus-1.0-runner` - -If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling. - -## Related Guides +-1 : suppression +0 : desactivé +1 : activé +2 : en attente de confirmation -## Provided Code - -### RESTEasy JAX-RS - -Easily start your RESTful Web Services - -[Related guide section...](https://quarkus.io/guides/getting-started#the-jax-rs-resources) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 2f4f302..364beae 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -37,10 +37,8 @@ public class UsersEntity extends PanacheEntityBase { public String firstName; @Column(nullable = false) public LocalDate birth; - @ColumnDefault("false") - public Boolean status; - @ColumnDefault("false") - public Boolean active_mail; + @ColumnDefault("0") + public Short status; @Column(nullable = false) public String password; @Column(nullable = false) @@ -64,7 +62,7 @@ public class UsersEntity extends PanacheEntityBase { users.name = name; users.firstName = firstName; users.birth = birth; - users.status = true; + users.status = 2; users.password = Hash.encryptSHA512(password); users.roles = roles; users.created_at = LocalDateTime.now(); diff --git a/src/main/java/com/covas/Resources/MailRessource.java b/src/main/java/com/covas/Resources/MailRessource.java index 66731fc..a126c8a 100644 --- a/src/main/java/com/covas/Resources/MailRessource.java +++ b/src/main/java/com/covas/Resources/MailRessource.java @@ -59,11 +59,11 @@ public class MailRessource { return Response.status(Response.Status.NOT_ACCEPTABLE).build(); } redisClient.del(Arrays.asList(id)); - if(users.active_mail){ + if(users.status == 1){ return Response.status(Response.Status.NOT_MODIFIED).build(); } - users.active_mail = true; + users.status = 1; users.persist(); if(users.isPersistent()){ diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index a9ef3c6..20404e8 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -64,7 +64,7 @@ public class TokenRessource { if(!password.equals(users.password)) { return Response.status(Response.Status.NOT_ACCEPTABLE).build(); } - if(!users.status){ + if(users.status != 1){ return Response.status(Response.Status.FORBIDDEN).build(); } // Create a JWT token signed using the 'HS256' algorithm diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index f2d9251..cefe303 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -48,7 +48,7 @@ public class UsersRessources { return false; } String name = new String(Base64.decode(userCookie), StandardCharsets.UTF_8); - if (!name.equals(users.pseudo) && (!users.status)) { + if (!name.equals(users.pseudo) && (users.status != 1)) { return false; } return true; @@ -166,8 +166,7 @@ public class UsersRessources { usersNew.password = Hash .encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8))); usersNew.roles = users.roles; - usersNew.status = false; - usersNew.active_mail = false; + usersNew.status = 2; usersNew.persist(); if (usersNew.isPersistent()) { status = Response.Status.CREATED; @@ -209,8 +208,7 @@ public class UsersRessources { usersNew.password = Hash .encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8))); usersNew.roles = users.roles; - usersNew.status = false; - usersNew.active_mail = true; + usersNew.status = 2; usersNew.persist(); if (usersNew.isPersistent()) { status = Response.Status.CREATED; @@ -233,7 +231,7 @@ public class UsersRessources { Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - user.status = false; + user.status = 0; user.updated_at = LocalDateTime.now(); user.deleted_at = LocalDateTime.now(); user.persist(); @@ -258,7 +256,7 @@ public class UsersRessources { if (singleUser == null) { status = Response.Status.NOT_FOUND; } else { - singleUser.status = false; + singleUser.status = 0; singleUser.updated_at = LocalDateTime.now(); singleUser.deleted_at = LocalDateTime.now(); singleUser.persist(); @@ -296,9 +294,9 @@ public class UsersRessources { usersOrig.password = Hash .encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8))); usersOrig.roles = users.roles; - if(users.status){ + if(users.status == 1){ usersOrig.deleted_at = null; - usersOrig.status = true; + usersOrig.status = 1; } usersOrig.persist(); if (!usersOrig.isPersistent()) { From c20ca0723cda197a0ec2ee7f4dc64eca5a188177 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 4 Aug 2022 23:23:29 +0200 Subject: [PATCH 13/27] change status compte default --- src/main/java/com/covas/Entity/UsersEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 364beae..4d707d5 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -62,7 +62,7 @@ public class UsersEntity extends PanacheEntityBase { users.name = name; users.firstName = firstName; users.birth = birth; - users.status = 2; + users.status = 1; users.password = Hash.encryptSHA512(password); users.roles = roles; users.created_at = LocalDateTime.now(); From be11abbd9f86c060fc3d8b866eb5deb3bdfff042 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 5 Aug 2022 21:03:28 +0200 Subject: [PATCH 14/27] add function to disable and delete --- src/main/java/com/covas/Json/UserSingle.java | 2 - .../com/covas/Resources/TokenRessource.java | 1 - .../com/covas/Resources/UsersRessources.java | 83 ++++++++++++++++++- 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/covas/Json/UserSingle.java b/src/main/java/com/covas/Json/UserSingle.java index 22ea520..ef003d0 100644 --- a/src/main/java/com/covas/Json/UserSingle.java +++ b/src/main/java/com/covas/Json/UserSingle.java @@ -1,7 +1,5 @@ package com.covas.Json; -import java.time.LocalDate; - import io.quarkus.runtime.annotations.RegisterForReflection; @RegisterForReflection diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index 20404e8..b77b216 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -17,7 +17,6 @@ import javax.ws.rs.core.Response; import com.covas.Classes.Hash; import com.covas.Entity.UsersEntity; -import com.fasterxml.jackson.datatype.jsr310.deser.DurationDeserializer; import io.smallrye.jwt.auth.principal.JWTParser; import io.smallrye.jwt.auth.principal.ParseException; diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index cefe303..47c2f9b 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -224,14 +224,14 @@ public class UsersRessources { @DELETE @RolesAllowed("User") @Transactional - public Response changeStatus(@Context SecurityContext ctx, @CookieParam("user") String userCookie) { + public Response changeStatusToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - user.status = 0; + user.status = -1; user.updated_at = LocalDateTime.now(); user.deleted_at = LocalDateTime.now(); user.persist(); @@ -246,7 +246,57 @@ public class UsersRessources { @Path("{id}") @RolesAllowed("Admin") @Transactional - public Response changeStatusSingleUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + public Response changeStatusSingleUserToDelete(@Context SecurityContext ctx, @CookieParam("user") String userCookie, + @PathParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + if (status.equals(Response.Status.OK)) { + UsersEntity singleUser = UsersEntity.find("id", UUID.fromString(id)).firstResult(); + if (singleUser == null) { + status = Response.Status.NOT_FOUND; + } else { + singleUser.status = -1; + singleUser.updated_at = LocalDateTime.now(); + singleUser.deleted_at = LocalDateTime.now(); + singleUser.persist(); + if (!singleUser.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } + + + + @DELETE + @RolesAllowed("User") + @Transactional + @Path("disable") + public Response changeStatusToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + + Response.Status status = getResponseCheck(ctx, userCookie, user); + + if (status.equals(Response.Status.OK)) { + user.status = -1; + user.updated_at = LocalDateTime.now(); + user.deleted_at = LocalDateTime.now(); + user.persist(); + if (!user.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + return Response.status(status).build(); + } + + @DELETE + @Path("/disable/{id}") + @RolesAllowed("Admin") + @Transactional + public Response changeStatusSingleUserToDisable(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -307,6 +357,33 @@ public class UsersRessources { return Response.status(status).build(); } + + + @PATCH + @RolesAllowed("Admin") + @Consumes(MediaType.APPLICATION_JSON) + @Transactional + @Path("enable/{id}") + public Response enableUserAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @QueryParam("id") String id) { + UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); + UsersEntity user = UsersEntity.findById(kid); + Response.Status status = getResponseCheck(ctx, userCookie, user); + if (status.equals(Response.Status.OK)) { + + UsersEntity usersOrig = UsersEntity.findById(UUID.fromString(id)); + if (usersOrig == null) { + status = Response.Status.NOT_FOUND; + } else { + usersOrig.status = 1; + usersOrig.persist(); + if (!usersOrig.isPersistent()) { + status = Response.Status.NOT_MODIFIED; + } + } + } + return Response.status(status).build(); + } + @PATCH @RolesAllowed("User") @Consumes(MediaType.APPLICATION_JSON) From 3a70c5e7675ee00d24e097b9347de7366c28c031 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 7 Aug 2022 00:15:13 +0200 Subject: [PATCH 15/27] add PATCH and fix variable --- .../java/com/covas/ApplicationScoped/ApplicationLifeCycle.java | 2 +- src/main/java/com/covas/Resources/UsersRessources.java | 2 +- src/main/resources/application.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/covas/ApplicationScoped/ApplicationLifeCycle.java b/src/main/java/com/covas/ApplicationScoped/ApplicationLifeCycle.java index d617bf8..f0fd3bb 100644 --- a/src/main/java/com/covas/ApplicationScoped/ApplicationLifeCycle.java +++ b/src/main/java/com/covas/ApplicationScoped/ApplicationLifeCycle.java @@ -35,7 +35,7 @@ public class ApplicationLifeCycle { LOGGER.info("Robert80 user is created"); UsersEntity.add("robert80", "robert80@gmail.com", "titi", "robert", LocalDate.of(1990, Month.JANUARY, 23), "toto", "User"); LOGGER.info("Peter93 user is created"); - UsersEntity.add("peter93", "valcze80@gmail.com", "yollo", "peter", LocalDate.of(1993, Month.FEBRUARY, 26), "toto", "Admin"); + UsersEntity.add("peter93", "valcze80@gmail.com", "yollo", "peter", LocalDate.of(1993, Month.FEBRUARY, 26), "toto", "Admin"); } else { LOGGER.info("DB init wassn't created"); } diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 47c2f9b..122fe7d 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -364,7 +364,7 @@ public class UsersRessources { @Consumes(MediaType.APPLICATION_JSON) @Transactional @Path("enable/{id}") - public Response enableUserAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @QueryParam("id") String id) { + public Response enableUserAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index edaf415..8af1028 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -29,6 +29,6 @@ quarkus.redis.hosts=redis://redis:6379 quarkus.http.cors=true quarkus.http.origins=http://localhost:8084 -quarkus.http.cors.methods=GET,PUT,POST,DELETE +quarkus.http.cors.methods=GET,PUT,POST,DELETE,PATCH quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with,x-foobar quarkus.http.cors.access-control-allow-credentials=true \ No newline at end of file From a55523951460478ededb73cf1b085858da5f013f Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 7 Aug 2022 17:38:36 +0200 Subject: [PATCH 16/27] add connected_at --- src/main/java/com/covas/Entity/UsersEntity.java | 2 ++ src/main/java/com/covas/Resources/TokenRessource.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 4d707d5..ef8d610 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -49,6 +49,8 @@ public class UsersEntity extends PanacheEntityBase { public LocalDateTime updated_at; @ColumnDefault("null") public LocalDateTime deleted_at; + @ColumnDefault("null") + public LocalDateTime connected_at; public static UsersEntity findByPseudo(String pseudo){ return find("pseudo", pseudo).firstResult(); diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index b77b216..1b2bd20 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -2,6 +2,7 @@ package com.covas.Resources; import java.nio.charset.StandardCharsets; import java.time.Duration; +import java.time.LocalDateTime; import javax.inject.Inject; import javax.ws.rs.CookieParam; @@ -71,6 +72,8 @@ public class TokenRessource { // or create a JWT token encrypted using the 'A256KW' algorithm // Jwt.upn("alice").encryptWithSecret(secret); String nameEncoded = Base64.toBase64String(name.getBytes(StandardCharsets.UTF_8)); + users.connected_at = LocalDateTime.now(); + users.persist(); return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", expires, false), new NewCookie(new Cookie("user", nameEncoded), "Username", expires, false)).build(); } // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized. From dfe75ea0409a958f1b61b5a172b366e13c4368d2 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 7 Aug 2022 18:11:13 +0200 Subject: [PATCH 17/27] add transactional --- src/main/java/com/covas/Resources/TokenRessource.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index 1b2bd20..77ccf7d 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -5,6 +5,7 @@ import java.time.Duration; import java.time.LocalDateTime; import javax.inject.Inject; +import javax.transaction.Transactional; import javax.ws.rs.CookieParam; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -41,6 +42,7 @@ public class TokenRessource { @GET @Produces(MediaType.APPLICATION_JSON) + @Transactional public Response tokenRefresh(@HeaderParam("Authorization") String auth, @CookieParam("user") String user, @CookieParam("jwt") String jwtCookie) { final int expires = 300; String name = "anonymous"; From 6a7e8b056374ede39ddeeefe456364f8a735909c Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 11 Aug 2022 00:11:49 +0200 Subject: [PATCH 18/27] add pathparam --- src/main/java/com/covas/Resources/UsersRessources.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 122fe7d..00a7461 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -323,15 +323,16 @@ public class UsersRessources { @RolesAllowed("Admin") @Consumes(MediaType.APPLICATION_JSON) @Transactional + @Path("{id}") public Response updateUserAdmin(@Context SecurityContext ctx, @CookieParam("user") String userCookie, - UsersEntity users) { + UsersEntity users, @PathParam("id") String id) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); if (status.equals(Response.Status.OK)) { - UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo); + UsersEntity usersOrig = UsersEntity.findById(UUID.fromString(id)); if (usersOrig == null) { status = Response.Status.NOT_FOUND; } else { @@ -341,8 +342,10 @@ public class UsersRessources { usersOrig.birth = LocalDate.of(users.birth.getYear(), users.birth.getMonth(), users.birth.getDayOfMonth()); usersOrig.updated_at = LocalDateTime.now(); - usersOrig.password = Hash + if(users.password.length() > 0){ + usersOrig.password = Hash .encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8))); + } usersOrig.roles = users.roles; if(users.status == 1){ usersOrig.deleted_at = null; From a147315851488edf91c1497273e2ae22d6702542 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 11 Aug 2022 21:35:02 +0200 Subject: [PATCH 19/27] add transactionnal --- .../java/com/covas/Resources/TokenRessource.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/covas/Resources/TokenRessource.java b/src/main/java/com/covas/Resources/TokenRessource.java index 77ccf7d..41836ee 100644 --- a/src/main/java/com/covas/Resources/TokenRessource.java +++ b/src/main/java/com/covas/Resources/TokenRessource.java @@ -77,14 +77,14 @@ public class TokenRessource { users.connected_at = LocalDateTime.now(); users.persist(); return Response.status(Response.Status.CREATED).cookie(new NewCookie(new Cookie("jwt", newJwtCookie), "Token JWT", expires, false), new NewCookie(new Cookie("user", nameEncoded), "Username", expires, false)).build(); - } - // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized. - try { - jwt = parser.parse(jwtCookie); - } - catch(ParseException p){ - return Response.status(Response.Status.GONE).build(); - } + } + // All mp.jwt and smallrye.jwt properties are still effective, only the verification key is customized. + try { + jwt = parser.parse(jwtCookie); + } + catch(ParseException p){ + return Response.status(Response.Status.GONE).build(); + } // or jwt = parser.decrypt(jwtCookie, secret); String kid = jwt.getClaim(Claims.kid).toString(); if(!kid.equals(users.id.toString())){ From f64640db45af69e110e126048034e4ce8d9ce838 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Fri, 12 Aug 2022 22:18:25 +0200 Subject: [PATCH 20/27] remove path for put method --- src/main/java/com/covas/Resources/UsersRessources.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 00a7461..633b592 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -180,11 +180,10 @@ public class UsersRessources { // PUT @PUT - @Path("{pseudo}") @RolesAllowed("Admin") @Consumes(MediaType.APPLICATION_JSON) @Transactional - public Response addUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("pseudo") String pseudo, + public Response addUser(@Context SecurityContext ctx, @CookieParam("user") String userCookie, UsersEntity users) { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); @@ -192,13 +191,13 @@ public class UsersRessources { if (status.equals(Response.Status.OK)) { - UsersEntity usersOrig = UsersEntity.findByPseudo(pseudo); + UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo); if (usersOrig != null) { status = Response.Status.UNAUTHORIZED; } else { UsersEntity usersNew = new UsersEntity(); usersNew.name = users.name; - usersNew.pseudo = pseudo; + usersNew.pseudo = users.pseudo; usersNew.firstName = users.firstName; usersNew.email = users.email; usersNew.birth = LocalDate.of(users.birth.getYear(), users.birth.getMonth(), @@ -208,7 +207,7 @@ public class UsersRessources { usersNew.password = Hash .encryptSHA512(Base64.toBase64String(users.password.getBytes(StandardCharsets.UTF_8))); usersNew.roles = users.roles; - usersNew.status = 2; + usersNew.status = 1; usersNew.persist(); if (usersNew.isPersistent()) { status = Response.Status.CREATED; From 2d6953dc298d955ca8aba6096fd6e28add5809bb Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 14 Aug 2022 18:21:09 +0200 Subject: [PATCH 21/27] add check email and pseudo --- .../java/com/covas/Entity/UsersEntity.java | 5 ++++ src/main/java/com/covas/Json/UserExist.java | 16 +++++++++++++ .../com/covas/Resources/UsersRessources.java | 23 +++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/covas/Json/UserExist.java diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index ef8d610..11d5f6d 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -8,6 +8,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; + import javax.persistence.Table; import com.covas.Classes.Hash; @@ -56,6 +57,10 @@ public class UsersEntity extends PanacheEntityBase { return find("pseudo", pseudo).firstResult(); } + public static UsersEntity findByEmail(String email){ + return find("email", email).firstResult(); + } + public static void add(String pseudo, String email, String name, String firstName, LocalDate birth, String password, String roles){ UsersEntity users = new UsersEntity(); diff --git a/src/main/java/com/covas/Json/UserExist.java b/src/main/java/com/covas/Json/UserExist.java new file mode 100644 index 0000000..da737b8 --- /dev/null +++ b/src/main/java/com/covas/Json/UserExist.java @@ -0,0 +1,16 @@ +package com.covas.Json; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +public class UserExist { + + public final Boolean email; + public final Boolean pseudo; + + public UserExist(Boolean email, Boolean pseudo){ + this.email = email; + this.pseudo = pseudo; + } + +} diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 633b592..3f4b8c4 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -9,6 +9,7 @@ import javax.annotation.security.RolesAllowed; import javax.inject.Inject; import javax.transaction.Transactional; import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.Response.Status; import javax.ws.rs.Consumes; import javax.ws.rs.CookieParam; import javax.ws.rs.DELETE; @@ -26,6 +27,7 @@ import javax.ws.rs.core.Response; import com.covas.Classes.Hash; import com.covas.Entity.UsersEntity; +import com.covas.Json.UserExist; import com.covas.Json.UserSingle; import io.quarkus.panache.common.Page; @@ -150,10 +152,23 @@ public class UsersRessources { @Transactional public Response createUser(UsersEntity users) { Response.Status status = Response.Status.OK; - UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo); - if (usersOrig != null) { + UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo); + UsersEntity usersEmail = UsersEntity.findByPseudo(users.email); + Boolean createUserBool = true; + Boolean pseudoExist = false; + Boolean emailExist = false; + if (usersPseudo != null) { + createUserBool = false; status = Response.Status.UNAUTHORIZED; - } else { + pseudoExist = true; + } + if(usersEmail != null){ + createUserBool = false; + status = Response.Status.UNAUTHORIZED; + emailExist = true; + } + UserExist userExist = new UserExist(emailExist, pseudoExist); + if(createUserBool) { UsersEntity usersNew = new UsersEntity(); usersNew.name = users.name; usersNew.pseudo = users.pseudo; @@ -174,7 +189,7 @@ public class UsersRessources { status = Response.Status.NO_CONTENT; } } - return Response.status(status).build(); + return Response.status(status).entity(userExist).build(); } From a85e6b161ef96c4c51b843bd320e4ec36265e7a2 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 14 Aug 2022 18:52:20 +0200 Subject: [PATCH 22/27] add check email and pseudo --- .../com/covas/Resources/UsersRessources.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 3f4b8c4..e734e59 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -153,7 +153,7 @@ public class UsersRessources { public Response createUser(UsersEntity users) { Response.Status status = Response.Status.OK; UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo); - UsersEntity usersEmail = UsersEntity.findByPseudo(users.email); + UsersEntity usersEmail = UsersEntity.findByEmail(users.email); Boolean createUserBool = true; Boolean pseudoExist = false; Boolean emailExist = false; @@ -167,7 +167,6 @@ public class UsersRessources { status = Response.Status.UNAUTHORIZED; emailExist = true; } - UserExist userExist = new UserExist(emailExist, pseudoExist); if(createUserBool) { UsersEntity usersNew = new UsersEntity(); usersNew.name = users.name; @@ -189,7 +188,7 @@ public class UsersRessources { status = Response.Status.NO_CONTENT; } } - return Response.status(status).entity(userExist).build(); + return Response.status(status).entity(new UserExist(emailExist, pseudoExist)).build(); } @@ -203,13 +202,26 @@ public class UsersRessources { UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); Response.Status status = getResponseCheck(ctx, userCookie, user); + Boolean pseudoExist = false; + Boolean emailExist = false; if (status.equals(Response.Status.OK)) { - UsersEntity usersOrig = UsersEntity.findByPseudo(users.pseudo); - if (usersOrig != null) { + UsersEntity usersPseudo = UsersEntity.findByPseudo(users.pseudo); + UsersEntity usersEmail = UsersEntity.findByEmail(users.email); + Boolean createUserBool = true; + + if (usersPseudo != null) { + createUserBool = false; status = Response.Status.UNAUTHORIZED; - } else { + pseudoExist = true; + } + if(usersEmail != null){ + createUserBool = false; + status = Response.Status.UNAUTHORIZED; + emailExist = true; + } + if(createUserBool) { UsersEntity usersNew = new UsersEntity(); usersNew.name = users.name; usersNew.pseudo = users.pseudo; @@ -231,7 +243,7 @@ public class UsersRessources { } } } - return Response.status(status).build(); + return Response.status(status).entity(new UserExist(emailExist, pseudoExist)).build(); } // Delete From 4e39c5e8e71a15545a58118bd02b889ee6eaf32a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 23 Aug 2022 00:27:33 +0200 Subject: [PATCH 23/27] add find email and uuid --- .../java/com/covas/Entity/UsersEntity.java | 11 +++++- .../com/covas/Resources/UsersRessources.java | 36 ++++++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 11d5f6d..5b7b585 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -8,7 +8,8 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; - +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.Table; import com.covas.Classes.Hash; @@ -21,6 +22,14 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; @Entity @Table(name = "users") +@NamedQueries({ + @NamedQuery(name = "Users.byUUIDandRoles", query = "from UsersEntity u where u.id = :id and u.roles = :roles"), + @NamedQuery(name = "Users.byUUIDandStatus", query = "from UsersEntity u where u.id = :id and u.status = :status"), + @NamedQuery(name = "Users.byUUIDandRolesandStatus", query = "from UsersEntity u where u.id = :id and u.roles = :roles and u.status = :status"), + @NamedQuery(name = "Users.byEmailandRoles", query = "from UsersEntity u where u.email = :email and u.roles = :roles"), + @NamedQuery(name = "Users.byEmailandStatus", query = "from UsersEntity u where u.email = :email and u.status = :status"), + @NamedQuery(name = "Users.byEmailandRolesandStatus", query = "from UsersEntity u where u.email = :email and u.roles = :roles and u.status = :status") +}) public class UsersEntity extends PanacheEntityBase { @Id @Column(name = "id") diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index e734e59..8f9c904 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -31,6 +31,7 @@ import com.covas.Json.UserExist; import com.covas.Json.UserSingle; import io.quarkus.panache.common.Page; +import io.quarkus.panache.common.Parameters; import org.eclipse.microprofile.jwt.Claims; import org.eclipse.microprofile.jwt.JsonWebToken; @@ -71,7 +72,7 @@ public class UsersRessources { /// GET @GET @RolesAllowed("Admin") - public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages) { + public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, @QueryParam("status") Integer status, @QueryParam("roles") String roles, @QueryParam("email") String email, @QueryParam("search") String search, @QueryParam("uuid") String uuid) { if(nbPages == null){ nbPages = 20; } @@ -80,10 +81,37 @@ public class UsersRessources { } UUID kid = UUID.fromString(jwt.getClaim(Claims.kid)); UsersEntity user = UsersEntity.findById(kid); - Response.Status status = getResponseCheck(ctx, userCookie, user); - Response responseHttp = Response.status(status).build(); - if (status.equals(Response.Status.OK)) { + Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); + Response responseHttp = Response.status(statusHttp).build(); + if (statusHttp.equals(Response.Status.OK)) { responseHttp = Response.ok(UsersEntity.findAll().page(Page.of(page, nbPages)).list()).build(); + if(uuid != null){ + UsersEntity userSingle = UsersEntity.findById(UUID.fromString(uuid)); + if((roles != null) && (status == null)){ + userSingle = UsersEntity.find("Users.byUUIDandRoles", Parameters.with("id", UUID.fromString(uuid)).and("roles",roles)).firstResult(); + } + if((roles == null) && (status != null)){ + userSingle = UsersEntity.find("Users.byUUIDandStatus", Parameters.with("id", UUID.fromString(uuid)).and("status",status)).firstResult(); + } + if((roles != null) && (status != null)){ + userSingle = UsersEntity.find("Users.byUUIDandRolesandStatus", Parameters.with("id", UUID.fromString(uuid)).and("status",status).and("roles", roles)).firstResult(); + } + responseHttp = Response.ok(userSingle).build(); + + } + if(email != null){ + UsersEntity userSingle = UsersEntity.findByEmail(email); + if((roles != null) && (status == null)){ + userSingle = UsersEntity.find("Users.byEmailandRoles", Parameters.with("email", UUID.fromString(uuid)).and("roles",roles)).firstResult(); + } + if((roles == null) && (status != null)){ + userSingle = UsersEntity.find("Users.byEmailandStatus", Parameters.with("email", UUID.fromString(uuid)).and("status",status)).firstResult(); + } + if((roles != null) && (status != null)){ + userSingle = UsersEntity.find("Users.byEmailandRolesandStatus", Parameters.with("email", UUID.fromString(uuid)).and("status",status).and("roles", roles)).firstResult(); + } + responseHttp = Response.ok(userSingle).build(); + } } return responseHttp; } From e18ddd2a2382ec4a7d952307fcee96c419b7715b Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 23 Aug 2022 23:41:55 +0200 Subject: [PATCH 24/27] add search name, firstname end pseudo --- .../java/com/covas/Entity/UsersEntity.java | 6 +++++- .../com/covas/Resources/UsersRessources.java | 21 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 5b7b585..535f7c2 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -28,7 +28,11 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; @NamedQuery(name = "Users.byUUIDandRolesandStatus", query = "from UsersEntity u where u.id = :id and u.roles = :roles and u.status = :status"), @NamedQuery(name = "Users.byEmailandRoles", query = "from UsersEntity u where u.email = :email and u.roles = :roles"), @NamedQuery(name = "Users.byEmailandStatus", query = "from UsersEntity u where u.email = :email and u.status = :status"), - @NamedQuery(name = "Users.byEmailandRolesandStatus", query = "from UsersEntity u where u.email = :email and u.roles = :roles and u.status = :status") + @NamedQuery(name = "Users.byEmailandRolesandStatus", query = "from UsersEntity u where u.email = :email and u.roles = :roles and u.status = :status"), + @NamedQuery(name = "Users.bySearch", query = "from UsersEntity u where u.pseudo = :search or u.name = :search or u.firstName = :search"), + @NamedQuery(name = "Users.bySearchandRoles", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.roles = :roles"), + @NamedQuery(name = "Users.bySearchandStatus", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.status = :status"), + @NamedQuery(name = "Users.bySearchandRolesandStatus", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.roles = :roles and u.status = :status") }) public class UsersEntity extends PanacheEntityBase { @Id diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index 8f9c904..d016f33 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -3,6 +3,7 @@ package com.covas.Resources; import java.nio.charset.StandardCharsets; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; import java.util.UUID; import javax.annotation.security.RolesAllowed; @@ -102,16 +103,30 @@ public class UsersRessources { if(email != null){ UsersEntity userSingle = UsersEntity.findByEmail(email); if((roles != null) && (status == null)){ - userSingle = UsersEntity.find("Users.byEmailandRoles", Parameters.with("email", UUID.fromString(uuid)).and("roles",roles)).firstResult(); + userSingle = UsersEntity.find("Users.byEmailandRoles", Parameters.with("email", email).and("roles",roles)).firstResult(); } if((roles == null) && (status != null)){ - userSingle = UsersEntity.find("Users.byEmailandStatus", Parameters.with("email", UUID.fromString(uuid)).and("status",status)).firstResult(); + userSingle = UsersEntity.find("Users.byEmailandStatus", Parameters.with("email", email).and("status",status)).firstResult(); } if((roles != null) && (status != null)){ - userSingle = UsersEntity.find("Users.byEmailandRolesandStatus", Parameters.with("email", UUID.fromString(uuid)).and("status",status).and("roles", roles)).firstResult(); + userSingle = UsersEntity.find("Users.byEmailandRolesandStatus", Parameters.with("email", email).and("status",status).and("roles", roles)).firstResult(); } responseHttp = Response.ok(userSingle).build(); } + if(search != null){ + List usersList = UsersEntity.list("Users.bySearch", Parameters.with("search", search)); + if((roles != null) && (status == null)){ + usersList = UsersEntity.find("Users.bySearchandRoles", Parameters.with("search", search).and("roles",roles)).list(); + } + if((roles == null) && (status != null)){ + usersList = UsersEntity.find("Users.bySearchandStatus", Parameters.with("search", search).and("status",status)).firstResult(); + } + if((roles != null) && (status != null)){ + usersList = UsersEntity.find("Users.bySearchandRolesandStatus", Parameters.with("search", search).and("status",status).and("roles", roles)).firstResult(); + } + responseHttp = Response.ok(usersList).build(); + + } } return responseHttp; } From 2866e15129c4cda1e9e24fda8190b121500d515e Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Aug 2022 00:19:53 +0200 Subject: [PATCH 25/27] add clause like --- src/main/java/com/covas/Entity/UsersEntity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 535f7c2..8ea7694 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -29,10 +29,10 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; @NamedQuery(name = "Users.byEmailandRoles", query = "from UsersEntity u where u.email = :email and u.roles = :roles"), @NamedQuery(name = "Users.byEmailandStatus", query = "from UsersEntity u where u.email = :email and u.status = :status"), @NamedQuery(name = "Users.byEmailandRolesandStatus", query = "from UsersEntity u where u.email = :email and u.roles = :roles and u.status = :status"), - @NamedQuery(name = "Users.bySearch", query = "from UsersEntity u where u.pseudo = :search or u.name = :search or u.firstName = :search"), - @NamedQuery(name = "Users.bySearchandRoles", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.roles = :roles"), - @NamedQuery(name = "Users.bySearchandStatus", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.status = :status"), - @NamedQuery(name = "Users.bySearchandRolesandStatus", query = "from UsersEntity u where (u.pseudo = :search or u.name = :search or u.firstName = :search) and u.roles = :roles and u.status = :status") + @NamedQuery(name = "Users.bySearch", query = "from UsersEntity u where u.pseudo like :search or u.name like :search or u.firstName like :search"), + @NamedQuery(name = "Users.bySearchandRoles", query = "from UsersEntity u where (u.pseudo like :search or u.name like :search or u.firstName like :search) and u.roles = :roles"), + @NamedQuery(name = "Users.bySearchandStatus", query = "from UsersEntity u where (u.pseudo like :search or u.name like :search or u.firstName like :search) and u.status = :status"), + @NamedQuery(name = "Users.bySearchandRolesandStatus", query = "from UsersEntity u where (u.pseudo like :search or u.name like :search or u.firstName like :search) and u.roles = :roles and u.status = :status") }) public class UsersEntity extends PanacheEntityBase { @Id From 9892959b3630e27a460dbf0abd97434652716e3a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Aug 2022 15:06:15 +0200 Subject: [PATCH 26/27] fix find by namedqueries --- .../com/covas/Resources/UsersRessources.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index d016f33..f48d260 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -73,7 +73,11 @@ public class UsersRessources { /// GET @GET @RolesAllowed("Admin") - public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, @QueryParam("status") Integer status, @QueryParam("roles") String roles, @QueryParam("email") String email, @QueryParam("search") String search, @QueryParam("uuid") String uuid) { + public Response getUsers(@CookieParam("user") String userCookie, @Context SecurityContext ctx, + @QueryParam("page") Integer page, @QueryParam("nbPages") Integer nbPages, + @QueryParam("status") Short status, @QueryParam("roles") String roles, + @QueryParam("email") String email, @QueryParam("search") String search, + @QueryParam("uuid") String uuid) { if(nbPages == null){ nbPages = 20; } @@ -89,13 +93,13 @@ public class UsersRessources { if(uuid != null){ UsersEntity userSingle = UsersEntity.findById(UUID.fromString(uuid)); if((roles != null) && (status == null)){ - userSingle = UsersEntity.find("Users.byUUIDandRoles", Parameters.with("id", UUID.fromString(uuid)).and("roles",roles)).firstResult(); + userSingle = UsersEntity.find("#Users.byUUIDandRoles", Parameters.with("id", UUID.fromString(uuid)).and("roles",roles)).firstResult(); } if((roles == null) && (status != null)){ - userSingle = UsersEntity.find("Users.byUUIDandStatus", Parameters.with("id", UUID.fromString(uuid)).and("status",status)).firstResult(); + userSingle = UsersEntity.find("#Users.byUUIDandStatus", Parameters.with("id", UUID.fromString(uuid)).and("status",status)).firstResult(); } if((roles != null) && (status != null)){ - userSingle = UsersEntity.find("Users.byUUIDandRolesandStatus", Parameters.with("id", UUID.fromString(uuid)).and("status",status).and("roles", roles)).firstResult(); + userSingle = UsersEntity.find("#Users.byUUIDandRolesandStatus", Parameters.with("id", UUID.fromString(uuid)).and("status",status).and("roles", roles)).firstResult(); } responseHttp = Response.ok(userSingle).build(); @@ -103,26 +107,26 @@ public class UsersRessources { if(email != null){ UsersEntity userSingle = UsersEntity.findByEmail(email); if((roles != null) && (status == null)){ - userSingle = UsersEntity.find("Users.byEmailandRoles", Parameters.with("email", email).and("roles",roles)).firstResult(); + userSingle = UsersEntity.find("#Users.byEmailandRoles", Parameters.with("email", email).and("roles",roles)).firstResult(); } if((roles == null) && (status != null)){ - userSingle = UsersEntity.find("Users.byEmailandStatus", Parameters.with("email", email).and("status",status)).firstResult(); + userSingle = UsersEntity.find("#Users.byEmailandStatus", Parameters.with("email", email).and("status",status)).firstResult(); } if((roles != null) && (status != null)){ - userSingle = UsersEntity.find("Users.byEmailandRolesandStatus", Parameters.with("email", email).and("status",status).and("roles", roles)).firstResult(); + userSingle = UsersEntity.find("#Users.byEmailandRolesandStatus", Parameters.with("email", email).and("status",status).and("roles", roles)).firstResult(); } responseHttp = Response.ok(userSingle).build(); } if(search != null){ - List usersList = UsersEntity.list("Users.bySearch", Parameters.with("search", search)); + List usersList = UsersEntity.find("#Users.bySearch", Parameters.with("search", search)).page(Page.of(page, nbPages)).list(); if((roles != null) && (status == null)){ - usersList = UsersEntity.find("Users.bySearchandRoles", Parameters.with("search", search).and("roles",roles)).list(); + usersList = UsersEntity.find("#Users.bySearchandRoles", Parameters.with("search", search).and("roles",roles)).page(Page.of(page, nbPages)).list(); } if((roles == null) && (status != null)){ - usersList = UsersEntity.find("Users.bySearchandStatus", Parameters.with("search", search).and("status",status)).firstResult(); + usersList = UsersEntity.find("#Users.bySearchandStatus", Parameters.with("search", search).and("status",status)).page(Page.of(page, nbPages)).list(); } if((roles != null) && (status != null)){ - usersList = UsersEntity.find("Users.bySearchandRolesandStatus", Parameters.with("search", search).and("status",status).and("roles", roles)).firstResult(); + usersList = UsersEntity.find("#Users.bySearchandRolesandStatus", Parameters.with("search", search).and("status",status).and("roles", roles)).page(Page.of(page, nbPages)).list(); } responseHttp = Response.ok(usersList).build(); From 596582231c7b998e76aaca9db1ef79c73895d087 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Thu, 25 Aug 2022 15:19:57 +0200 Subject: [PATCH 27/27] add condition by roles and status --- src/main/java/com/covas/Entity/UsersEntity.java | 3 +++ .../java/com/covas/Resources/UsersRessources.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/covas/Entity/UsersEntity.java b/src/main/java/com/covas/Entity/UsersEntity.java index 8ea7694..08843f7 100644 --- a/src/main/java/com/covas/Entity/UsersEntity.java +++ b/src/main/java/com/covas/Entity/UsersEntity.java @@ -26,6 +26,9 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; @NamedQuery(name = "Users.byUUIDandRoles", query = "from UsersEntity u where u.id = :id and u.roles = :roles"), @NamedQuery(name = "Users.byUUIDandStatus", query = "from UsersEntity u where u.id = :id and u.status = :status"), @NamedQuery(name = "Users.byUUIDandRolesandStatus", query = "from UsersEntity u where u.id = :id and u.roles = :roles and u.status = :status"), + @NamedQuery(name = "Users.byRoles", query = "from UsersEntity u where u.roles = :roles"), + @NamedQuery(name = "Users.byStatus", query = "from UsersEntity u where u.status = :status"), + @NamedQuery(name = "Users.byRolesandStatus", query = "from UsersEntity u where u.roles = :roles and u.status = :status"), @NamedQuery(name = "Users.byEmailandRoles", query = "from UsersEntity u where u.email = :email and u.roles = :roles"), @NamedQuery(name = "Users.byEmailandStatus", query = "from UsersEntity u where u.email = :email and u.status = :status"), @NamedQuery(name = "Users.byEmailandRolesandStatus", query = "from UsersEntity u where u.email = :email and u.roles = :roles and u.status = :status"), diff --git a/src/main/java/com/covas/Resources/UsersRessources.java b/src/main/java/com/covas/Resources/UsersRessources.java index f48d260..e2e4199 100644 --- a/src/main/java/com/covas/Resources/UsersRessources.java +++ b/src/main/java/com/covas/Resources/UsersRessources.java @@ -89,7 +89,18 @@ public class UsersRessources { Response.Status statusHttp = getResponseCheck(ctx, userCookie, user); Response responseHttp = Response.status(statusHttp).build(); if (statusHttp.equals(Response.Status.OK)) { - responseHttp = Response.ok(UsersEntity.findAll().page(Page.of(page, nbPages)).list()).build(); + List listUsers = UsersEntity.findAll().page(Page.of(page, nbPages)).list(); + + if((roles != null) && (status == null)){ + listUsers = UsersEntity.find("#Users.byRoles", Parameters.with("roles",roles)).page(Page.of(page, nbPages)).list(); + } + if((roles == null) && (status != null)){ + listUsers = UsersEntity.find("#Users.byStatus", Parameters.with("status",status)).page(Page.of(page, nbPages)).list(); + } + if((roles != null) && (status != null)){ + listUsers = UsersEntity.find("#Users.byRolesandStatus", Parameters.with("roles",roles).and("status", status)).page(Page.of(page, nbPages)).list(); + } + responseHttp = Response.ok(listUsers).build(); if(uuid != null){ UsersEntity userSingle = UsersEntity.findById(UUID.fromString(uuid)); if((roles != null) && (status == null)){