From 23a46b4be35277e06ec89f48730eeb694e686be8 Mon Sep 17 00:00:00 2001
From: Kenmegne <stephanie.kenmegne@gmail.com>
Date: Thu, 18 Jun 2026 15:40:06 +0000
Subject: [PATCH] add fdx-commons and fdx-consultation
---
apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/impl/authentication/AuthenticationRSImpl.java | 90 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 90 insertions(+), 0 deletions(-)
diff --git a/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/impl/authentication/AuthenticationRSImpl.java b/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/impl/authentication/AuthenticationRSImpl.java
new file mode 100644
index 0000000..77e8563
--- /dev/null
+++ b/apifdxweb/api/apifdxweb-service-impl/src/main/java/com/megatim/apifdxweb/impl/authentication/AuthenticationRSImpl.java
@@ -0,0 +1,90 @@
+package com.megatim.apifdxweb.impl.authentication;
+
+import com.megatim.apifdxweb.core.ifaces.administration.TokenGenerationManager;
+import com.megatim.apifdxweb.core.ifaces.administration.UserManager;
+import com.megatim.apifdxweb.model.administration.User;
+import com.megatim.apifdxweb.model.dtos.EditPasswordDto;
+import com.megatim.apifdxweb.model.dtos.TokenAuthentificationRequest;
+import com.megatim.apifdxweb.service.ifaces.authentication.AuthenticationRS;
+import com.mgt.rs.security.core.common.AuthenticatedUser;
+import com.mgt.rs.security.core.exception.AuthenticationException;
+import com.mgt.rs.security.core.model.AuthenticationToken;
+import com.mgt.rs.security.core.service.AuthenticationTokenService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+
+/**
+ *
+ * @author Gabuntu
+ */
+@Path("auth")
+@RequestScoped
+@Api(value = "Ressources pour l'authentification de l'API")
+public class AuthenticationRSImpl implements AuthenticationRS {
+
+ @Inject
+ private AuthenticationTokenService authenticationTokenService;
+
+ @Inject
+ private UserManager userManager;
+
+ @Inject
+ private TokenGenerationManager tokenGenerationManager;
+
+ private String codeParticipant;
+
+ public void handleAuthenticationEvent(@Observes @AuthenticatedUser String connectedUserName) {
+ this.codeParticipant = connectedUserName;
+ }
+
+ @ApiOperation(value = "Génère un token si les identifiants du participant passé en paramètre sont corrects")
+ @Override
+ public Response authenticate(TokenAuthentificationRequest authentificationRequest) {
+ authentificationRequest.setValidite(authentificationRequest.getValidite() * 3600 * 1000);
+
+ //On recupère l'utilisateur
+ User user = validateCredentials(authentificationRequest.getCodeParticipant(), authentificationRequest.getPassword());
+
+ //On génère le token
+ String token = authenticationTokenService.issueToken(user.getUserName(), authentificationRequest.getValidite());
+
+ //On enregistre le token généré en base de donné car c'est le seul valide pour connexion pour cet utilisateur
+ tokenGenerationManager.createTokenGeneration(user, token, authentificationRequest.getValidite());
+
+ //On cree une instance
+ AuthenticationToken authenticationToken = new AuthenticationToken();
+ authenticationToken.setToken(token);
+
+ return Response.ok(authenticationToken).build();
+
+ }
+
+ @ApiOperation(value = "Génère un token si les identifiants du participant passé en paramètre sont corrects")
+ @Override
+ public Response editPassword(HttpHeaders headers, EditPasswordDto editPasswordDto) {
+ userManager.editPassword(codeParticipant, editPasswordDto);
+ return Response.ok().build();
+ }
+
+ /**
+ * Validate username and password.
+ *
+ * @param username
+ * @param password
+ * @return
+ */
+ private User validateCredentials(String username, String password) {
+ User user = userManager.recuperUtilisateur(username, password);
+ if (user == null) {
+ throw new AuthenticationException("Identifiants de connexion incorrects.");
+ }
+ return user;
+ }
+
+}
--
Gitblit v1.10.0