Acq communication
This commit is contained in:
@@ -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,65 +23,88 @@
|
|||||||
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">
|
||||||
<br>
|
<br>
|
||||||
<input id="password-field" placeholder="Password">
|
<input id="password-field" placeholder="Password">
|
||||||
<br>
|
<br>
|
||||||
<button id="connect-button">Connect</button>
|
<button id="connect-button">Connect</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="payment">
|
<div id="payment">
|
||||||
<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 btnPay = document.getElementById("connect-button-pay");
|
||||||
|
|
||||||
let btnConnect = document.getElementById("connect-button");
|
btnConnect.addEventListener("click", async() => {
|
||||||
let btnPay = document.getElementById("connect-button");
|
let username = document.getElementById("username-field").value;
|
||||||
|
let pwd = document.getElementById("password-field").value;
|
||||||
|
|
||||||
btnConnect.addEventListener("click", async () => {
|
let data = {
|
||||||
let username = document.getElementById("username-field").value;
|
username: username,
|
||||||
let pwd = document.getElementById("password-field").value;
|
password: pwd
|
||||||
|
};
|
||||||
|
|
||||||
let data = {
|
await fetch("/login", {
|
||||||
username: username,
|
method: "POST",
|
||||||
password: pwd
|
headers: {
|
||||||
};
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
localStorage.setItem("creds", JSON.stringify(data));
|
||||||
|
document.getElementById("payment").style.display = 'block';
|
||||||
|
} else {
|
||||||
|
throw new Error("Authentication request failed")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
await fetch("/login", {
|
btnPay.addEventListener("click", async() => {
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data)})
|
|
||||||
.then(response => {
|
|
||||||
if(response.ok) {
|
|
||||||
localStorage.setItem("creds", JSON.stringify(data));
|
|
||||||
document.getElementById("payment").style.display = 'block';
|
|
||||||
} else {
|
|
||||||
throw new Error("Authentication request failed")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
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>
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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();
|
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);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user