Acq communication

This commit is contained in:
Cédric
2025-12-07 20:52:41 +01:00
parent d32e892095
commit 2621ffd618
6 changed files with 140 additions and 60 deletions

View File

@@ -1,18 +1,19 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MASI 3DSecure</title> <title>MASI 3DSecure</title>
<style> <style>
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
header, footer { header,
footer {
background: #f4f4f4; background: #f4f4f4;
padding: 15px; padding: 15px;
text-align: center; text-align: center;
@@ -22,16 +23,15 @@
padding: 20px; padding: 20px;
} }
#payment #payment {
{
display: none; display: none;
} }
</style> </style>
</head> </head>
<body> <body>
<main> <main>
<div id="login"> <div id="login">
<h2>Login</h2> <h2>Login</h2>
<input id="username-field" placeholder="Username"> <input id="username-field" placeholder="Username">
@@ -44,16 +44,15 @@
<h2>Payment</h2> <h2>Payment</h2>
<input id="token-input" placeholder="Token"> <input id="token-input" placeholder="Token">
<br> <br>
<button>Pay</button> <button id="connect-button-pay">Pay</button>
</div> </div>
</main> </main>
<script>
<script>
let btnConnect = document.getElementById("connect-button"); let btnConnect = document.getElementById("connect-button");
let btnPay = document.getElementById("connect-button"); let btnPay = document.getElementById("connect-button-pay");
btnConnect.addEventListener("click", async () => { btnConnect.addEventListener("click", async() => {
let username = document.getElementById("username-field").value; let username = document.getElementById("username-field").value;
let pwd = document.getElementById("password-field").value; let pwd = document.getElementById("password-field").value;
@@ -67,9 +66,10 @@
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
body: JSON.stringify(data)}) body: JSON.stringify(data)
})
.then(response => { .then(response => {
if(response.ok) { if (response.ok) {
localStorage.setItem("creds", JSON.stringify(data)); localStorage.setItem("creds", JSON.stringify(data));
document.getElementById("payment").style.display = 'block'; document.getElementById("payment").style.display = 'block';
} else { } else {
@@ -81,6 +81,30 @@
}); });
}); });
</script> btnPay.addEventListener("click", async() => {
let token = document.getElementById("token-input").value;
await fetch("/payement", {
method: "POST",
headers: {
"Content-Type": "application/json"
//"Authorization" : "username:password"
},
body: JSON.stringify(token)
})
.then(response => {
if (response.ok) {
//Logique à executer si serveur répond avec 200 HTTP
} else {
throw new Error("Payment request failed")
}
})
.catch(error => {
console.error(error);
});
})
</script>
</body> </body>
</html> </html>

View File

@@ -8,6 +8,8 @@ import javax.net.ssl.*;
import static common.common.src.ports.Ports.*; import static common.common.src.ports.Ports.*;
import java.io.IOException;
public class Main { public class Main {
private static final String HOST = "127.0.0.1"; private static final String HOST = "127.0.0.1";
@@ -51,10 +53,19 @@ public class Main {
} }
} }
public static void handleRequest(SSLSocket serverSocket) { public static void handleRequest(SSLSocket serverSocket) {
Logger.displayInfo("Request handled"); try{
String request = SocketManager.readResponse(serverSocket);
Logger.displayReceived(request);
}catch (IOException ioe){
throw new RuntimeException(ioe);
}
} }
} }

View File

@@ -0,0 +1,10 @@
package acq.acq.src.json;
import com.fasterxml.jackson.annotation.JsonProperty;
public record Token(
@JsonProperty("token")
String token,
@JsonProperty("signature")
String signature) {
}

View File

@@ -48,6 +48,10 @@ public class Main {
authThread.start(); authThread.start();
} }
/**
* Gére les requets de vérification de token
* @param clientSocket SSLsocket to listen to
*/
private static void handleRequest(SSLSocket clientSocket) { private static void handleRequest(SSLSocket clientSocket) {
try{ try{
String response = SocketManager.readResponse(clientSocket); String response = SocketManager.readResponse(clientSocket);

View File

@@ -1,5 +1,7 @@
package httpServer.httpServer.src; package httpServer.httpServer.src;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsParameters; import com.sun.net.httpserver.HttpsParameters;
import com.sun.net.httpserver.HttpsServer; import com.sun.net.httpserver.HttpsServer;

View File

@@ -1,9 +1,11 @@
package httpServer.httpServer.src.handlers; package httpServer.httpServer.src.handlers;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpExchange;
import common.common.src.html.HtmlManager; import common.common.src.html.HtmlManager;
import common.common.src.logger.Logger; import common.common.src.logger.Logger;
import common.common.src.json.JsonManager;
import httpServer.httpServer.src.annotations.AllowedVerb; import httpServer.httpServer.src.annotations.AllowedVerb;
import httpServer.httpServer.src.annotations.OnlyAuthorizedClients; import httpServer.httpServer.src.annotations.OnlyAuthorizedClients;
import httpServer.httpServer.src.authorization.AuthorizedClients; import httpServer.httpServer.src.authorization.AuthorizedClients;
@@ -11,6 +13,7 @@ import httpServer.httpServer.src.authorization.Client;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Map;
public class RequestHandler implements IRequestHandler { public class RequestHandler implements IRequestHandler {
@@ -25,12 +28,38 @@ public class RequestHandler implements IRequestHandler {
} }
} }
@AllowedVerb(name = "GET") @AllowedVerb(name = "POST")
@OnlyAuthorizedClients //@OnlyAuthorizedClients
public void handlePayment(HttpExchange exchange) { public void handlePayment(HttpExchange exchange) {
Logger.displayReceived("/payment request"); Logger.displayReceived("/payment request");
try{ try{
respondToGet(exchange, "./assets/pages/payment.html"); InputStream is = exchange.getRequestBody();
String body = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))
.lines()
.reduce("", (acc, line) -> acc + line + "\n");
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(body);
String token = node.get("token").asText();
System.out.println("Received Payement POST data:\n" + token);
// Build json payload
Map<String, Object> map = Map.of("token", token);
String jsonString = JsonManager.serialize(map);
// Send request to ACQ
// Wait ACQ ACK or NAK
// Return result
} catch(Exception e){ } catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }