Acq communication
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>MASI 3DSecure</title>
|
||||
|
||||
<style>
|
||||
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
header, footer {
|
||||
header,
|
||||
footer {
|
||||
background: #f4f4f4;
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
@@ -22,13 +23,12 @@
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
#payment
|
||||
{
|
||||
#payment {
|
||||
display: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<main>
|
||||
@@ -44,14 +44,13 @@
|
||||
<h2>Payment</h2>
|
||||
<input id="token-input" placeholder="Token">
|
||||
<br>
|
||||
<button>Pay</button>
|
||||
<button id="connect-button-pay">Pay</button>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
|
||||
let btnConnect = document.getElementById("connect-button");
|
||||
let btnPay = document.getElementById("connect-button");
|
||||
let btnPay = document.getElementById("connect-button-pay");
|
||||
|
||||
btnConnect.addEventListener("click", async() => {
|
||||
let username = document.getElementById("username-field").value;
|
||||
@@ -67,7 +66,8 @@
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(data)})
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
localStorage.setItem("creds", JSON.stringify(data));
|
||||
@@ -81,6 +81,30 @@
|
||||
});
|
||||
});
|
||||
|
||||
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>
|
||||
|
||||
</html>
|
||||
@@ -8,6 +8,8 @@ import javax.net.ssl.*;
|
||||
|
||||
import static common.common.src.ports.Ports.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static final String HOST = "127.0.0.1";
|
||||
@@ -51,10 +53,19 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
src/main/java/acq/acq/src/json/Token.java
Normal file
10
src/main/java/acq/acq/src/json/Token.java
Normal 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) {
|
||||
}
|
||||
@@ -48,6 +48,10 @@ public class Main {
|
||||
authThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gére les requets de vérification de token
|
||||
* @param clientSocket SSLsocket to listen to
|
||||
*/
|
||||
private static void handleRequest(SSLSocket clientSocket) {
|
||||
try{
|
||||
String response = SocketManager.readResponse(clientSocket);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package httpServer.httpServer.src.handlers;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import common.common.src.html.HtmlManager;
|
||||
import common.common.src.logger.Logger;
|
||||
import common.common.src.json.JsonManager;
|
||||
import httpServer.httpServer.src.annotations.AllowedVerb;
|
||||
import httpServer.httpServer.src.annotations.OnlyAuthorizedClients;
|
||||
import httpServer.httpServer.src.authorization.AuthorizedClients;
|
||||
@@ -11,6 +13,7 @@ import httpServer.httpServer.src.authorization.Client;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
public class RequestHandler implements IRequestHandler {
|
||||
|
||||
@@ -25,12 +28,38 @@ public class RequestHandler implements IRequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@AllowedVerb(name = "GET")
|
||||
@OnlyAuthorizedClients
|
||||
@AllowedVerb(name = "POST")
|
||||
//@OnlyAuthorizedClients
|
||||
public void handlePayment(HttpExchange exchange) {
|
||||
Logger.displayReceived("/payment request");
|
||||
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){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user