Authentification fonctionnelle via security.lions.dev
This commit is contained in:
@@ -9,8 +9,6 @@ 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 java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.Principal;
|
||||
import java.util.Map;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
@@ -21,12 +19,14 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Resource REST pour l'authentification et les informations utilisateur
|
||||
* Permet de récupérer les informations de l'utilisateur connecté depuis le token JWT Keycloak
|
||||
* Resource REST pour les informations utilisateur
|
||||
* Permet de récupérer les informations de l'utilisateur connecté depuis le token JWT envoyé par le frontend
|
||||
* Architecture Frontend-Centric: Le frontend gère l'authentification OAuth avec Keycloak,
|
||||
* le backend valide uniquement les tokens JWT
|
||||
*/
|
||||
@Path("/api/v1/auth")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Tag(name = "Authentification", description = "Gestion de l'authentification et informations utilisateur")
|
||||
@Tag(name = "Authentification", description = "Informations utilisateur et statut d'authentification")
|
||||
public class AuthResource {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AuthResource.class);
|
||||
@@ -34,52 +34,6 @@ public class AuthResource {
|
||||
@Inject
|
||||
JsonWebToken jwt;
|
||||
|
||||
/**
|
||||
* Redirige vers Keycloak pour l'authentification
|
||||
* Architecture 2025 : Redirection directe vers https://security.lions.dev pour l'authentification
|
||||
*/
|
||||
@GET
|
||||
@Path("/login")
|
||||
@PermitAll
|
||||
@Operation(
|
||||
summary = "Initier l'authentification Keycloak",
|
||||
description = "Redirige l'utilisateur vers Keycloak (https://security.lions.dev) pour l'authentification OAuth2/OIDC")
|
||||
@APIResponse(responseCode = "302", description = "Redirection vers Keycloak pour authentification")
|
||||
public Response login(@Context SecurityContext securityContext) {
|
||||
try {
|
||||
logger.info("Redirection vers Keycloak pour authentification");
|
||||
|
||||
// Construction de l'URL Keycloak pour l'authentification
|
||||
String keycloakUrl = "https://security.lions.dev/realms/btpxpress/protocol/openid_connect/auth";
|
||||
String clientId = "btpxpress-backend";
|
||||
String redirectUri = "http://localhost:8080/api/v1/auth/callback"; // Peut être configuré dynamiquement
|
||||
String responseType = "code";
|
||||
String scope = "openid profile email";
|
||||
|
||||
// Construction de l'URL complète avec paramètres
|
||||
java.net.URI authUri = java.net.URI.create(
|
||||
String.format(
|
||||
"%s?client_id=%s&redirect_uri=%s&response_type=%s&scope=%s",
|
||||
keycloakUrl,
|
||||
clientId,
|
||||
URLEncoder.encode(redirectUri, StandardCharsets.UTF_8),
|
||||
responseType,
|
||||
URLEncoder.encode(scope, StandardCharsets.UTF_8)
|
||||
)
|
||||
);
|
||||
|
||||
logger.debug("Redirection vers Keycloak: {}", authUri);
|
||||
return Response.status(Response.Status.FOUND)
|
||||
.location(authUri)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
logger.error("Erreur lors de la redirection vers Keycloak", e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.entity(Map.of("error", "Erreur lors de la redirection vers Keycloak", "message", e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les informations de l'utilisateur connecté depuis le token JWT
|
||||
*/
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
# Configuration OIDC spécifique au mode développement
|
||||
# Ce fichier surcharge application.properties pour le profil %dev
|
||||
|
||||
# Activation de OIDC
|
||||
quarkus.oidc.enabled=true
|
||||
quarkus.oidc.auth-server-url=https://security.lions.dev/realms/btpxpress
|
||||
quarkus.oidc.client-id=btpxpress-backend
|
||||
quarkus.oidc.credentials.secret=${KEYCLOAK_CLIENT_SECRET:fCSqFPsnyrUUljAAGY8ailGKp1u6mutv}
|
||||
|
||||
# Type d'application: web-app pour gérer les sessions
|
||||
quarkus.oidc.application-type=web-app
|
||||
|
||||
# Configuration TLS
|
||||
quarkus.oidc.tls.verification=required
|
||||
|
||||
# Configuration des redirections
|
||||
quarkus.oidc.authentication.redirect-path=/
|
||||
quarkus.oidc.authentication.restore-path-after-redirect=true
|
||||
|
||||
# Configuration des cookies pour cross-origin (localhost:3000 -> localhost:8080)
|
||||
quarkus.oidc.authentication.cookie-path=/
|
||||
quarkus.oidc.authentication.cookie-domain=localhost
|
||||
quarkus.oidc.authentication.session-age-extension=PT30M
|
||||
|
||||
# Configuration Keycloak
|
||||
quarkus.oidc.token.issuer=https://security.lions.dev/realms/btpxpress
|
||||
quarkus.oidc.discovery-enabled=true
|
||||
|
||||
# Activation de la sécurité en mode dev
|
||||
quarkus.security.auth.enabled=true
|
||||
Reference in New Issue
Block a user