add function base for profile resources
This commit is contained in:
parent
535a89f321
commit
36cf9f5631
49
src/main/java/com/covas/Resources/ProfileRessources.java
Normal file
49
src/main/java/com/covas/Resources/ProfileRessources.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.covas.Resources;
|
||||
|
||||
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.SecurityContext;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64.Base64;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
|
||||
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("profile")
|
||||
public class ProfileRessources {
|
||||
|
||||
@Inject
|
||||
JsonWebToken jwt;
|
||||
|
||||
/// Function
|
||||
private Boolean checkUserCookie(String userCookie, UsersEntity users) {
|
||||
if ((userCookie == null) || (users == null)) {
|
||||
return false;
|
||||
}
|
||||
String name = new String(Base64.decode(userCookie), StandardCharsets.UTF_8);
|
||||
if (!name.equals(users.pseudo) && (users.status != 1)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Response.Status getResponseCheck(SecurityContext ctx, String userCookie, UsersEntity users) {
|
||||
if (!ctx.getUserPrincipal().getName().equals(jwt.getName())) {
|
||||
return Response.Status.INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
if (!checkUserCookie(userCookie, users)) {
|
||||
return Response.Status.FORBIDDEN;
|
||||
}
|
||||
return Response.Status.OK;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user