feat: add keycloak account creation and club groupe set
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.rest.data.UserInfo;
|
||||
import io.quarkus.security.Authenticated;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -9,6 +10,7 @@ import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -22,6 +24,9 @@ public class AuthEndpoints {
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
@Inject
|
||||
JsonWebToken accessToken;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Boolean auth() {
|
||||
@@ -30,9 +35,10 @@ public class AuthEndpoints {
|
||||
|
||||
@GET
|
||||
@Path("/userinfo")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String userinfo() {
|
||||
return securityIdentity.getPrincipal().getName();
|
||||
@Authenticated
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public UserInfo userinfo() {
|
||||
return UserInfo.makeUserInfo(accessToken, securityIdentity);
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
31
src/main/java/fr/titionfire/ffsaf/rest/CompteEndpoints.java
Normal file
31
src/main/java/fr/titionfire/ffsaf/rest/CompteEndpoints.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.KeycloakService;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.PUT;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
|
||||
@Path("api/compte")
|
||||
public class CompteEndpoints {
|
||||
|
||||
@Inject
|
||||
KeycloakService service;
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
public Uni<?> getCompte(@PathParam("id") String id) {
|
||||
return service.fetchCompte(id);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}/init")
|
||||
@RolesAllowed("federation_admin")
|
||||
public Uni<?> initCompte(@PathParam("id") long id) {
|
||||
return service.initCompte(id);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import java.util.Date;
|
||||
@RegisterForReflection
|
||||
public class SimpleMembre {
|
||||
private long id;
|
||||
private String userId;
|
||||
private String lname = "";
|
||||
private String fname = "";
|
||||
private Categorie categorie;
|
||||
@@ -38,6 +39,7 @@ public class SimpleMembre {
|
||||
|
||||
return new SimpleMembreBuilder()
|
||||
.id(model.getId())
|
||||
.userId(model.getUserId())
|
||||
.lname(model.getLname())
|
||||
.fname(model.getFname())
|
||||
.categorie(model.getCategorie())
|
||||
|
||||
38
src/main/java/fr/titionfire/ffsaf/rest/data/UserInfo.java
Normal file
38
src/main/java/fr/titionfire/ffsaf/rest/data/UserInfo.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import io.quarkus.security.identity.SecurityIdentity;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@RegisterForReflection
|
||||
public class UserInfo {
|
||||
String id;
|
||||
String name;
|
||||
String givenName;
|
||||
String familyName;
|
||||
String email;
|
||||
boolean emailVerified;
|
||||
long expiration;
|
||||
Set<String> groups;
|
||||
Set<String> roles;
|
||||
|
||||
public static UserInfo makeUserInfo(JsonWebToken accessToken, SecurityIdentity securityIdentity) {
|
||||
UserInfo.UserInfoBuilder builder = UserInfo.builder();
|
||||
builder.id(accessToken.getSubject());
|
||||
builder.name(accessToken.getName());
|
||||
builder.givenName(accessToken.getClaim("given_name"));
|
||||
builder.familyName(accessToken.getClaim("family_name"));
|
||||
builder.email(accessToken.getClaim("email"));
|
||||
builder.emailVerified(accessToken.getClaim("email_verified"));
|
||||
builder.expiration(accessToken.getExpirationTime());
|
||||
builder.groups(accessToken.getGroups());
|
||||
builder.roles(securityIdentity.getRoles());
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user