2024-10-10 08:07:17 +02:00

83 lines
2.4 KiB
Java

package fr.la_banquise.backend;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.SecurityContext;
import io.quarkus.security.Authenticated;
@Path("/api/user")
@Authenticated
public class UsersResource {
@GET
@Path("/me")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("user")
// public Response<Map<String, Object>> me(@Context SecurityContext
// securityContext) {
public Response me() {
// OidcJwtCallerPrincipal principal = (OidcJwtCallerPrincipal)
// securityContext.getUserPrincipal();
// Map<String, Object> claims = principal.getClaims().getClaimsMap();
// System.out.println(claims);
// Map<String, Object> userInfo = new HashMap<>();
// userInfo.put("username", claims.get("name"));
// userInfo.put("username", "malo");
// userInfo.put("email", token.getEmail());
// userInfo.put("firstName", token.getGivenName());
// userInfo.put("lastName", token.getFamilyName());
String test = "yess";
return Response.ok(test).build();
}
// @Inject
// SecurityIdentity identity;
//
// @GET
// @Path("/me")
// public User me() {
// return new User(identity);
// }
//
// public static class User {
// private final String userName;
// private final Set<String> roles;
// private final String sshKey;
//
// User(SecurityIdentity identity) {
// this.userName = identity.getPrincipal().getName();
// this.roles = identity.getRoles();
//
// if (identity.getPrincipal() instanceof OidcJwtCallerPrincipal) {
// OidcJwtCallerPrincipal oidcJwtCallerPrincipal = (OidcJwtCallerPrincipal)
// identity.getPrincipal();
// // Map<String, Object> claims =
// oidcJwtCallerPrincipal.getClaims().getClaimsMap();
// // System.out.println(claims.get("ssh-key"));
// this.sshKey = (String) oidcJwtCallerPrincipal.getClaim("ssh-key");
// } else {
// this.sshKey = null;
// }
// }
//
// public String getUserName() {
// return userName;
// }
//
// public Set<String> getRoles() {
// return roles;
// }
//
// public String getSshKey() {
// return sshKey;
// }
// }
}