diff --git a/CloudAppManagerSimple/cloudappman-1663003550820-pub-tcplocalhost/.lck b/CloudAppManagerSimple/cloudappman-1663003550820-pub-tcplocalhost/.lck new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/CloudAppManagerSimple/cloudappman-1663003764784-pub-tcplocalhost/.lck b/CloudAppManagerSimple/cloudappman-1663003764784-pub-tcplocalhost/.lck new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/CloudAppManagerSimple/cloudappman-1663003961575-pub-tcplocalhost/.lck b/CloudAppManagerSimple/cloudappman-1663003961575-pub-tcplocalhost/.lck new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/CloudAppManagerSimple/cloudappman-1663074319287-pub-tcplocalhost/.lck b/CloudAppManagerSimple/cloudappman-1663074319287-pub-tcplocalhost/.lck new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/CloudAppManagerSimple/cloudappman-1663164389395-pub-tcplocalhost/.lck b/CloudAppManagerSimple/cloudappman-1663164389395-pub-tcplocalhost/.lck new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/LuciMicro/src/code/Subscriber.java b/LuciMicro/src/code/Subscriber.java index a93424d4fc2d9c720c7b86e6742c3658d6f303e0..28a5811802d361bd8095a58510cf7bb4524438de 100644 --- a/LuciMicro/src/code/Subscriber.java +++ b/LuciMicro/src/code/Subscriber.java @@ -68,16 +68,16 @@ public class Subscriber implements MqttCallback { @Override public void messageArrived(String topic, MqttMessage message) throws MqttException, JSONException, IOException { - Helper.print("new message: " + topic + " " + message.toString()); + // Helper.print("new message: " + topic + " " + message.toString()); if (topic.equals(Luci.getMqttTree("rpc/", "luci"))) { - Helper.print("invio la mia configurazione"); + // Helper.print("invio la mia configurazione"); sendFile(Luci.getMqttTree("from/", "luci")); return; } if (topic.equals("to/all")) { - Helper.print("invio il mio stato"); + // Helper.print("invio il mio stato"); sendStatus(Luci.getMqttTree("from/", "luci")); return; } @@ -93,7 +93,7 @@ public class Subscriber implements MqttCallback { String nome = msgJson.getString("nome"); for (Luce k : Luci.luciList) { if (k.getNome().equalsIgnoreCase(nome)) { - System.out.println("Nome gia' presente, inserimento annullato\n"); + // System.out.println("Nome gia' presente, inserimento annullato\n"); return; } @@ -125,9 +125,9 @@ public class Subscriber implements MqttCallback { // sensM tempo if (topic.equals(Luci.getMqttTree("from", "gpio/" + sensM))) { - System.out.println(giorno); + // System.out.println(giorno); if(giorno)return; - + if (msgJson.has("event") && msgJson.getInt("event") == 1) { if (runningEsec) { Esecutore.timer.cancel(); @@ -140,7 +140,7 @@ public class Subscriber implements MqttCallback { } runningEsec = true; esec.run(runningEsec); -// +// } return; } @@ -150,7 +150,7 @@ public class Subscriber implements MqttCallback { // prendo l'ultimo pezzo del topic, diventa il mio nome String pezzo = topic.substring(23);// seleziono solo il nome della lamp - System.out.println("nome lamp\t" + pezzo); + // System.out.println("nome lamp\t" + pezzo); for (int i = 0; i < Luci.luciList.size(); i++) { if (Luci.luciList.get(i).getIN().equalsIgnoreCase(pezzo) && msgJson.has("event") @@ -167,7 +167,7 @@ public class Subscriber implements MqttCallback { if (msgJson.has("status")) return; String pezzo = topic.substring(23);// seleziono solo il nome della lamp - System.out.println("nome lamp\t" + pezzo); + // System.out.println("nome lamp\t" + pezzo); for (int i = 0; i < Luci.luciList.size(); i++) { if (Luci.luciList.get(i).getOUT().equalsIgnoreCase(pezzo) && msgJson.has("event")) { @@ -197,18 +197,18 @@ public class Subscriber implements MqttCallback { } return; } - + if (topic.startsWith(Luci.getMqttTree("from", "arduino/AN0"))) { if (msgJson.has("event")){ -// +// // if(msgJson.getInt("event")<200)giorno=false; // else giorno=true; - + giorno=(msgJson.getInt("event")>=200); } return; } - + Helper.print("Impossibile"); } diff --git a/ScenariMicroservizio/res/CONF/zona.json b/ScenariMicroservizio/res/CONF/zona.json index a8066f273f23f0145bc9790e0ee5e8d88e4a7d20..563ebc57ad29887151f50b24703b7a0da1ad76e0 100644 --- a/ScenariMicroservizio/res/CONF/zona.json +++ b/ScenariMicroservizio/res/CONF/zona.json @@ -1,3 +1,3 @@ {"attiva-scenari":"IN7", "learn-trigger":"IN4", -"luce-antifurto":"OUT5"} +"luce-antifurto":"OUT1"} diff --git a/WebServer/bin/code/Helper.class b/WebServer/bin/code/Helper.class index 86dd7fc9a55e63a13e62aff94e8acf0d1ca252a9..6bd7d5b6b5b7978e5a12b325d22e6157c128e468 100644 Binary files a/WebServer/bin/code/Helper.class and b/WebServer/bin/code/Helper.class differ diff --git a/WebServer/bin/code/Home.class b/WebServer/bin/code/Home.class index 44c26f24d03ef7539af8342c18b034c37078b5bc..6c09f94b09cb75af9bab8e792360c2f0e093960d 100644 Binary files a/WebServer/bin/code/Home.class and b/WebServer/bin/code/Home.class differ diff --git a/WebServer/bin/code/ImageRes.class b/WebServer/bin/code/ImageRes.class index 12a6728d9101478be3e3e6c556121a979fe80536..dbea630fa79283942da8b0301e7d631ba032c7a8 100644 Binary files a/WebServer/bin/code/ImageRes.class and b/WebServer/bin/code/ImageRes.class differ diff --git a/WebServer/bin/code/MissingPage.class b/WebServer/bin/code/MissingPage.class index 42e50527a873cc37cd9eae6f17674b384ec80a8e..75b596d29b9aab57513af13b34ed5b4e6036b8e5 100644 Binary files a/WebServer/bin/code/MissingPage.class and b/WebServer/bin/code/MissingPage.class differ diff --git a/WebServer/bin/code/ObtainToken.class b/WebServer/bin/code/ObtainToken.class index 494475d0a087a1bacff6206336cab5a2daeda27c..cebfebf5f5c5a64fbcf426c8d9f7ccfdaa558342 100644 Binary files a/WebServer/bin/code/ObtainToken.class and b/WebServer/bin/code/ObtainToken.class differ diff --git a/WebServer/bin/code/Resources.class b/WebServer/bin/code/Resources.class index 9b9406a88bd155158e7a8363dbd3fec2e5daad1e..529cb039ace458f738d3afb50c2ede06d08ff1cc 100644 Binary files a/WebServer/bin/code/Resources.class and b/WebServer/bin/code/Resources.class differ diff --git a/WebServer/bin/code/Server$1.class b/WebServer/bin/code/Server$1.class new file mode 100644 index 0000000000000000000000000000000000000000..8a95613b4cd86c2f97bbaee3d062e54c890f425c Binary files /dev/null and b/WebServer/bin/code/Server$1.class differ diff --git a/WebServer/bin/code/Server.class b/WebServer/bin/code/Server.class index f8d51543157c6a911b93c8b6ffcfe507b7334403..9a5bb2dca954bb0b713a13fab23299c0e70e94dc 100644 Binary files a/WebServer/bin/code/Server.class and b/WebServer/bin/code/Server.class differ diff --git a/WebServer/gencert.bash b/WebServer/gencert.bash old mode 100644 new mode 100755 diff --git a/WebServer/src/code/Helper.java b/WebServer/src/code/Helper.java index 85699ce101f361a52056d6f9b37f8ba76f50e7db..fb2dee8970030b6b2009dceb233f608428ba937e 100644 --- a/WebServer/src/code/Helper.java +++ b/WebServer/src/code/Helper.java @@ -7,19 +7,20 @@ import java.io.OutputStream; import org.json.JSONException; import org.json.JSONObject; -import com.sun.net.httpserver.HttpExchange; +// import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpsExchange; public class Helper { - - public static void sendResponse(String response, HttpExchange exchange) throws IOException { + + public static void sendResponse(String response, HttpsExchange exchange) throws IOException { System.out.println(response); exchange.sendResponseHeaders(200, response.getBytes().length); OutputStream os = exchange.getResponseBody(); os.write(response.getBytes()); os.close(); } - - public static void badRequest(HttpExchange exchange) throws IOException { + + public static void badRequest(HttpsExchange exchange) throws IOException { System.out.println("Errors in the request!"); // exchange.getResponseHeaders().remove("content-type"); String response = "{\"message\":\"Errors in the request!\"}"; @@ -28,8 +29,8 @@ public class Helper { os.write(response.getBytes()); os.close(); } - - public static void pageNotFound(HttpExchange exchange) throws IOException { + + public static void pageNotFound(HttpsExchange exchange) throws IOException { System.out.println("Page not found!"); // exchange.getResponseHeaders().remove("content-type"); String response = "{\"message\":\"Page not found!\"}"; @@ -38,8 +39,8 @@ public class Helper { os.write(response.getBytes()); os.close(); } - - public static void methodNotAllowed(HttpExchange exchange) throws IOException { + + public static void methodNotAllowed(HttpsExchange exchange) throws IOException { System.out.println("Method not allowed!"); // exchange.getResponseHeaders().remove("content-type"); String response = "{\"message\":\"Method not allowed!\"}"; @@ -48,7 +49,7 @@ public class Helper { os.write(response.getBytes()); os.close(); } - + public static boolean compareText(String a, String b){ return a.compareToIgnoreCase(b) == 0; } @@ -64,7 +65,7 @@ public class Helper { } return sb.toString(); } - + public static boolean checkJSON(String body) { try { new JSONObject(body); diff --git a/WebServer/src/code/Home.java b/WebServer/src/code/Home.java index aba69c7038d7e7b667c0feb6436af97533131349..7fe310e227fb2a2958466ffc60b15a77b458e1c7 100644 --- a/WebServer/src/code/Home.java +++ b/WebServer/src/code/Home.java @@ -5,7 +5,6 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.OutputStream; -import java.net.URI; import java.util.ArrayList; import java.util.List; @@ -14,11 +13,13 @@ import org.json.JSONObject; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpsExchange; public class Home implements HttpHandler { @Override - public void handle(HttpExchange exchange) throws IOException { + public void handle(HttpExchange ex) throws IOException { + HttpsExchange exchange = (HttpsExchange) ex; String requestMethod = exchange.getRequestMethod(); if (Helper.compareText(requestMethod, "GET")) { List<String> strlist = new ArrayList<>(); diff --git a/WebServer/src/code/ImageRes.java b/WebServer/src/code/ImageRes.java index 31a7ed29e1b16be587673bdbaea8266e382993ff..122d268da18b04aa5473cfa8f10fde1cee6a1c0f 100644 --- a/WebServer/src/code/ImageRes.java +++ b/WebServer/src/code/ImageRes.java @@ -5,19 +5,20 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.net.URI; import java.util.ArrayList; import java.util.List; import javax.imageio.ImageIO; import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpsExchange; import com.sun.net.httpserver.HttpHandler; public class ImageRes implements HttpHandler { @Override - public void handle(HttpExchange exchange) throws IOException { + public void handle(HttpExchange ex) throws IOException { + HttpsExchange exchange = (HttpsExchange) ex; String requestURI = exchange.getRequestURI().toASCIIString().replace("/secured/home/", "/"); String requestMethod = exchange.getRequestMethod(); diff --git a/WebServer/src/code/MissingPage.java b/WebServer/src/code/MissingPage.java deleted file mode 100644 index 854ed4f771c59758f4163bae8d7f549b463f4f50..0000000000000000000000000000000000000000 --- a/WebServer/src/code/MissingPage.java +++ /dev/null @@ -1,15 +0,0 @@ -package code; - -import java.io.IOException; - -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; - -public class MissingPage implements HttpHandler { - - @Override - public void handle(HttpExchange exchange) throws IOException { - Helper.pageNotFound(exchange); - } - -} diff --git a/WebServer/src/code/ObtainToken.java b/WebServer/src/code/ObtainToken.java index bd1a5ddd483113cb74b6b40390d69b90f266c5d6..a22b4c1ecd939d6e408e746b4a88cacaa9cf3b59 100644 --- a/WebServer/src/code/ObtainToken.java +++ b/WebServer/src/code/ObtainToken.java @@ -22,6 +22,7 @@ import javax.net.ssl.HttpsURLConnection; import org.apache.commons.codec.binary.Base64; import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpsExchange; import com.sun.net.httpserver.HttpHandler; public class ObtainToken implements HttpHandler{ @@ -33,7 +34,8 @@ public class ObtainToken implements HttpHandler{ } @Override - public void handle(HttpExchange exchange) throws IOException { + public void handle(HttpExchange ex) throws IOException { + HttpsExchange exchange = (HttpsExchange) ex; URI requestURI = exchange.getRequestURI(); String stringURI = requestURI.toString(); boolean wantsRedirectPage = Helper.compareText(stringURI,URI.create("/").toString()); diff --git a/WebServer/src/code/Resources.java b/WebServer/src/code/Resources.java index a05616752b69fec5f88a0c3a9e241b673becb5b8..ca6877060edc13bae263582d2441e58531356758 100644 --- a/WebServer/src/code/Resources.java +++ b/WebServer/src/code/Resources.java @@ -10,18 +10,22 @@ import java.util.ArrayList; import java.util.List; import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpsExchange; import com.sun.net.httpserver.HttpHandler; public class Resources implements HttpHandler { @Override - public void handle(HttpExchange exchange) throws IOException { + public void handle(HttpExchange ex) throws IOException { + HttpsExchange exchange = (HttpsExchange) ex; String requestURI = exchange.getRequestURI().toASCIIString().replace("/secured/home/","/"); String requestMethod = exchange.getRequestMethod(); if (Helper.compareText(requestMethod, "GET")) { String response = getLocalPage(requestURI); + if(requestURI.contains("conf")) + System.out.println("URI: " + requestURI+"\tresponse: "+response); if(response.equals("fail")){ //nel caso in cui non ci sia il file (perche non stato scaricato), allora creo un file fittizzio per non far crashare tutto il resto String[] requestedPath = requestURI.split("/"); diff --git a/WebServer/src/code/Server.java b/WebServer/src/code/Server.java index 81806bf66b3ea004293b4758b989f9058cf4be02..7a484be35574d06781b52f62dbf58f2a6e607be3 100644 --- a/WebServer/src/code/Server.java +++ b/WebServer/src/code/Server.java @@ -1,6 +1,7 @@ package code; -/*import java.io.FileInputStream; +import java.io.FileInputStream; +import java.io.FileInputStream; import java.security.KeyStore; import javax.net.ssl.KeyManagerFactory; @@ -11,11 +12,17 @@ import javax.net.ssl.TrustManagerFactory; import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsParameters; -import com.sun.net.httpserver.HttpsServer;*/ +import com.sun.net.httpserver.HttpsServer; import java.io.IOException; import java.net.InetSocketAddress; +import java.security.KeyStore; import java.util.concurrent.Executors; -import com.sun.net.httpserver.HttpServer; + +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLParameters; +import javax.net.ssl.TrustManagerFactory; public class Server { @@ -31,17 +38,17 @@ public class Server { e.printStackTrace(); } KeyCloak kcs = new KeyCloak(CLIENT_PATH + "/keycloak.json", CLIENT_PATH + "/params.json"); -// HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 0); - HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); + HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 0); + // HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); // initialise the HTTPS server - /*try { + try { SSLContext sslContext = SSLContext.getInstance("TLS"); // initialise the keystore - char[] password = "simulator".toCharArray(); + char[] password = "miapasswd".toCharArray(); KeyStore ks = KeyStore.getInstance("JKS"); - FileInputStream fis = new FileInputStream("testkey.jks"); + FileInputStream fis = new FileInputStream("../lig.keystore"); ks.load(fis, password); // setup the key manager factory @@ -71,50 +78,46 @@ public class Server { } catch (Exception ex) { System.out.println("Failed to create HTTPS port"); + ex.printStackTrace(); } } }); //API del server - server.createContext("/js/",new Resources()); - server.createContext("/css/",new Resources()); - server.createContext("/res/",new ImageRes()); - server.createContext("/",new Home()); + server.createContext("/js/authentication/",new Resources()); + server.createContext("/js/templates/",new Resources()); + server.createContext("/css/",new Resources()); + server.createContext("/conf/",new Resources()); + server.createContext("/res/",new ImageRes()); + server.createContext("/secured/home/js/",new Resources()); + server.createContext("/secured/home/css/",new Resources()); + server.createContext("/secured/home/res/",new ImageRes()); + server.createContext("/secured/home/",new Home()); + server.createContext("/secured",new ObtainToken(kcs)); + server.createContext("/",new ObtainToken(kcs)); -// server.setExecutor(Executors.newFixedThreadPool(11)); server.setExecutor(Executors.newCachedThreadPool()); server.start(); - System.out.println("webserver running on localhost:"+port); + System.out.println("webserver running on https://localhost:"+port); } catch (Exception e) { System.out.println("Failed to create HTTPS server on port " + port + " of localhost"); e.printStackTrace(); - }*/ + } //API del server -// server.createContext("/api/luci/",new Luci());//post, get [put, delete] {luogo e stato di tutte luci} -// server.createContext("/api/luci/stato/",new Luci());//put {aggiorna lo stato di una luce} -// server.createContext("/api/scenari/",new Scenari());//get {nome e data di tutti gli scenari} -// server.createContext("/api/scenari/attiva/",new Scenari());//put {attiva/disattiva} -// server.createContext("/api/scenari/registra/",new Scenari());//put {registra/termina} -// server.createContext("/api/scenari/salva/",new Scenari());//post {conferma salvataggio, altrimenti cancella dopo timer; ritorna i valori dello scenario} -// server.createContext("/api/antifurto/",new Antifurto());//get {stato, allarme, attenzione, soglia, sensori} -// server.createContext("/api/antifurto/stato/",new Antifurto());//get, put {se l'antifurto e' attivo + aggiornamento} -// server.createContext("/api/antifurto/allarme/",new Antifurto());//get, put {se l'allarme sta suonando + aggiornamento} -// server.createContext("/api/antifurto/attenzione/",new Antifurto());//put {valore della progress bar} -// server.createContext("/api/antifurto/soglia/",new Antifurto());//put {valore scelto dall'utente per la soglia} - server.createContext("/js/authentication/",new Resources()); - server.createContext("/js/templates/",new Resources()); - server.createContext("/css/",new Resources()); - server.createContext("/res/",new ImageRes()); - server.createContext("/secured/home/js/",new Resources()); - server.createContext("/secured/home/css/",new Resources()); - server.createContext("/secured/home/res/",new ImageRes()); - server.createContext("/secured/home/",new Home()); - server.createContext("/secured",new ObtainToken(kcs)); - server.createContext("/",new ObtainToken(kcs)); - - server.setExecutor(Executors.newCachedThreadPool()); - server.start(); - System.out.println("webserver running on localhost:"+port); + // server.createContext("/js/authentication/",new Resources()); + // server.createContext("/js/templates/",new Resources()); + // server.createContext("/css/",new Resources()); + // server.createContext("/res/",new ImageRes()); + // server.createContext("/secured/home/js/",new Resources()); + // server.createContext("/secured/home/css/",new Resources()); + // server.createContext("/secured/home/res/",new ImageRes()); + // server.createContext("/secured/home/",new Home()); + // server.createContext("/secured",new ObtainToken(kcs)); + // server.createContext("/",new ObtainToken(kcs)); + + // server.setExecutor(Executors.newCachedThreadPool()); + // server.start(); + // System.out.println("webserver running on http://localhost:"+port); } } diff --git a/WebServer/testcert.pem b/WebServer/testcert.pem new file mode 100644 index 0000000000000000000000000000000000000000..ee1bd413425c9fbb829066d6916221bfbc1bd4f0 --- /dev/null +++ b/WebServer/testcert.pem @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDdzCCAl+gAwIBAgIEMELchTANBgkqhkiG9w0BAQsFADBsMQswCQYDVQQGEwJJ +VDELMAkGA1UECBMCQUwxFDASBgNVBAcTC0FsZXNzYW5kcmlhMQ8wDQYDVQQKEwZV +TklVUE8xDjAMBgNVBAsTBURJU0lUMRkwFwYDVQQDExBhdHRpbGlvIGdpb3JkYW5h +MB4XDTIxMTIyMDIxMDI0NFoXDTIyMDMyMDIxMDI0NFowbDELMAkGA1UEBhMCSVQx +CzAJBgNVBAgTAkFMMRQwEgYDVQQHEwtBbGVzc2FuZHJpYTEPMA0GA1UEChMGVU5J +VVBPMQ4wDAYDVQQLEwVESVNJVDEZMBcGA1UEAxMQYXR0aWxpbyBnaW9yZGFuYTCC +ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIzW4E3AvS/9rpyOCmuxIuA2 +g4Dc6f1DxVzAsuHSglUSW+dI/WZB8AhgFnL42VDBqtRieOLzBmdL+iBcK5ZaRJRK +i7ya68OOKT3L+gcq1lY2HRly54DX+tjw1KVJ6Dh+MzUjL8Y4k872SLpyu2FQGgH+ +iXufrqSCDHWidPDCDA+O2iZ6+5NoGb92jFUPQm7GZz5l9WBorxOR8VqDWNw56ipi +D6Ly7wkn/57SUotcHo6ZlaCh0dRGwLjtgfR2kHlhZ+151MSzeHDCul91QjS23XKf +eEQjxK1uiABUnUj0WC8FJp7MYwwFS4sPA5S5HTali+1C+ROk0zkorH+mYHPv0J8C +AwEAAaMhMB8wHQYDVR0OBBYEFHlvC8ECltT2lXei3X96D2MWikpVMA0GCSqGSIb3 +DQEBCwUAA4IBAQBUmE1aB5ofz0/AQanNg22oAq9gy5G4xOOUbYDhUmuimq7QkrpT +L/3Y4uGDflk2IM3Dj5piBipLJ0EgK6qSudSLWbfM1OcTU112NBf/OUBxa88Yv9II +/zVI1Sw9g1hX88C7stpqKNTtqAAFffmfwUJkxtTUoG9XXrsIY792FX/5YvL0mdgb +HIBEWK21F+38SvaLi/cInnC2BrnwPfOioGXvK/LAGhXV+Rsp/Iq94f6mE1bT2aCD ++rnIPgLkCY0/Px+xpc9rg6q0mfKPXxF/neiURNhcXpWvyfC1W0sZ4eq+3AqIrj2q +sgUc4uC/WGqomJXd/KB4Q+raFuu8QTQgkBdQ +-----END CERTIFICATE----- diff --git a/antifurto/bin/code/Antifurto.class b/antifurto/bin/code/Antifurto.class index 33727972cc17c243c1b19ce2e66030c8aa9b5d45..43b851c415891f675e6187c84cf73694cd7bc082 100644 Binary files a/antifurto/bin/code/Antifurto.class and b/antifurto/bin/code/Antifurto.class differ diff --git a/antifurto/bin/code/Automa.class b/antifurto/bin/code/Automa.class index 9ee24747ba7dfbd2afb48f9cf9bbb09b3eade611..c606cfee341329883be8d41f4f90d6a9e3bc4d65 100644 Binary files a/antifurto/bin/code/Automa.class and b/antifurto/bin/code/Automa.class differ diff --git a/antifurto/bin/code/Esecutore.class b/antifurto/bin/code/Esecutore.class index c3f83b6e06715b453d4252fa25bf721976f07159..5a9a55bbfcd00494cc875ff88c33a56c0e9f1e4b 100644 Binary files a/antifurto/bin/code/Esecutore.class and b/antifurto/bin/code/Esecutore.class differ diff --git a/antifurto/bin/code/Helper.class b/antifurto/bin/code/Helper.class index cbfca13d4240a1884a93c6cbb7ccbb591b612e09..27eb86ed7d768ec518afd3d2d023d10e0143c0aa 100644 Binary files a/antifurto/bin/code/Helper.class and b/antifurto/bin/code/Helper.class differ diff --git a/antifurto/bin/code/MyQueue.class b/antifurto/bin/code/MyQueue.class index 50ac71d1e9f4ea9afa31bd320196bcda41a7245b..9801fb6cbdbcc4c4617ce10657e8202676670f8f 100644 Binary files a/antifurto/bin/code/MyQueue.class and b/antifurto/bin/code/MyQueue.class differ diff --git a/antifurto/bin/code/Pair.class b/antifurto/bin/code/Pair.class index 86b1dcf26b53593f2adc887c6453e5aa817d353f..63c21e1fcc5b31b57a8ebe1d164faa30bbad0c41 100644 Binary files a/antifurto/bin/code/Pair.class and b/antifurto/bin/code/Pair.class differ diff --git a/antifurto/bin/code/Publisher.class b/antifurto/bin/code/Publisher.class index dca9fa9c1be2a8ae0466cd03d57b3b89df74dbad..7f601d48df6a54254ba827d30fb5fe762a636eca 100644 Binary files a/antifurto/bin/code/Publisher.class and b/antifurto/bin/code/Publisher.class differ diff --git a/antifurto/bin/code/SubscribeCallback.class b/antifurto/bin/code/SubscribeCallback.class index 5853d9d9be62175292d7c385314bdc632a7bab33..1d482a3ae71725639e0a6261a65cf3d1aa32831e 100644 Binary files a/antifurto/bin/code/SubscribeCallback.class and b/antifurto/bin/code/SubscribeCallback.class differ diff --git a/antifurto/bin/code/Timer.class b/antifurto/bin/code/Timer.class index 453e7f52694373063e3dfdbee7b4c29d1ec4ba84..2edff9f10d2659030c9ea4fad254d1e005b90b87 100644 Binary files a/antifurto/bin/code/Timer.class and b/antifurto/bin/code/Timer.class differ diff --git a/antifurto/res/stato.json b/antifurto/res/stato.json index f2d5b921dab9836da62d4d6313bf90201ce6222f..2eb08bd04ff59cb55efccf5489dddc6737679734 100644 --- a/antifurto/res/stato.json +++ b/antifurto/res/stato.json @@ -1 +1 @@ -{"soglia":32,"stato":0,"valore":0,"tempoAllarme":"2022-09-12T17:55:30.663368"} \ No newline at end of file +{"soglia":32,"stato":0,"valore":0} \ No newline at end of file diff --git a/antifurto/src/code/Antifurto.java b/antifurto/src/code/Antifurto.java index ab9c2a5a70e0bb116ac7c44e3ea9858c39c53732..9337c6925e43e4a6ba93959e017d2f987ce96715 100644 --- a/antifurto/src/code/Antifurto.java +++ b/antifurto/src/code/Antifurto.java @@ -221,7 +221,7 @@ public class Antifurto { public static void main(String args[]) { - while(true) { + // while(true) { try { startSystem(); } @@ -229,7 +229,7 @@ public class Antifurto { System.out.println("Error: "+ e.getMessage() + "\nRestarting system..."); e.printStackTrace(); } - } + // } } diff --git a/webapp/public/conf/conf.json b/webapp/public/conf/conf.json new file mode 100644 index 0000000000000000000000000000000000000000..589ec440b32d2b297abf5a4dbddae9f83c0f11fb --- /dev/null +++ b/webapp/public/conf/conf.json @@ -0,0 +1,10 @@ +{ + "self-server-url": "https://localhost:3000/", + "keycloak": { + "realm": "test00", + "base-server-url": "http://localhost:8080/" + }, + "domain": { + "base-server-url": "http://localhost:3001/" + } +} \ No newline at end of file diff --git a/webapp/public/js/authentication/configuration.js b/webapp/public/js/authentication/configuration.js new file mode 100644 index 0000000000000000000000000000000000000000..45d85cb72389567b66e03efbc705297dea7d3d65 --- /dev/null +++ b/webapp/public/js/authentication/configuration.js @@ -0,0 +1,27 @@ +"use strict"; + +import conf from '../../conf/conf.json'; + +class Configuration { + static getMyURL() { + return conf["self-server-url"]; + } + + static getKeycloakInfo() { + return conf.keycloak; + } + + static getKeycloakRealm() { + return conf.keycloak.realm; + } + + static getKeycloakURL() { + return conf.keycloak["base-server-url"]; + } + + static getDomainURL() { + return conf.domain["base-domain-url"]; + } +} + +export default Configuration; \ No newline at end of file diff --git a/webapp/public/js/authentication/requests-to-domain.js b/webapp/public/js/authentication/requests-to-domain.js index dfec45520a3c1c85ebcd4ea430d99bb3b0358bf0..6c83e31d116dca78a64832ad9f4e3c354e34211c 100644 --- a/webapp/public/js/authentication/requests-to-domain.js +++ b/webapp/public/js/authentication/requests-to-domain.js @@ -2,6 +2,9 @@ import {getToken} from "./script.js"; import Domain from "./domain.js"; +import Configuration from "./configuration.js"; +const configuration = new Configuration(); + class RequestToDomain { constructor() { @@ -13,22 +16,7 @@ class RequestToDomain { * sui domini dell'utente che ha effettuato il login */ static async getMyDomains() { - /*const div = document.createElement('div'); - div.innerHTML = "cliccami per avere info"; - div.addEventListener('click', async () => { - const responseDomain = await fetch('http://localhost:8080/realms/test00/protocol/openid-connect/userinfo', { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager - method: 'GET', - headers: { - 'Authorization': `Bearer ${await getToken()}` - } - }) ; - const domainsJson = await responseDomain.json(); - if(responseDomain.ok) { - console.log(domainsJson); - } - }); - document.getElementsByTagName('body')[0].appendChild(div);*/ - const responseDomain = await fetch('http://localhost:3001/secured/domains/', { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager + const responseDomain = await fetch(`${configuration.getDomainURL()}secured/domains/`, { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager method: 'GET', headers: { 'Authorization': `Bearer ${await getToken()}` @@ -54,7 +42,7 @@ class RequestToDomain { * false altrimenti. */ static async createNewDomain(json) { - const response = await fetch('http://localhost:3001/install/', { + const response = await fetch(`${configuration.getDomainURL()}install/`, { method: 'POST', headers: { 'Authorization': `Bearer ${await getToken()}` @@ -75,7 +63,7 @@ class RequestToDomain { * disponibili. */ static async getAllServices() { - const responseDomain = await fetch('http://localhost:3001/secured/services', { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager + const responseDomain = await fetch(`${configuration.getDomainURL()}secured/services`, { // DA FARE: controllare che l'uri che ho specificato qui coincida con quello specificato dal domain manager method: 'GET', headers: { 'Authorization': `Bearer ${await getToken()}` @@ -96,7 +84,7 @@ class RequestToDomain { * @returns */ static async getUsedServices(domain) { - const response = await fetch(`http://localhost:3001/secured/services?domain=${domain}`, { + const response = await fetch(`${configuration.getDomainURL()}secured/services?domain=${domain}`, { method: 'GET', headers: { 'Authorization': `Bearer ${await getToken()}` @@ -117,7 +105,7 @@ class RequestToDomain { * false altrimenti. */ static async startDomain(d) { - const response = await fetch('http://localhost:3001/start/', { + const response = await fetch(`${configuration.getDomainURL()}start/`, { method: 'POST', headers: { 'Authorization': `Bearer ${await getToken()}` @@ -140,7 +128,7 @@ class RequestToDomain { * false altrimenti. */ static async stopDomain(d) { - const response = await fetch('http://localhost:3001/stop/', { + const response = await fetch(`${configuration.getDomainURL()}stop/`, { method: 'POST', headers: { 'Authorization': `Bearer ${await getToken()}` @@ -163,7 +151,7 @@ class RequestToDomain { * false altrimenti. */ static async deleteDomain(d) { - const response = await fetch('http://localhost:3001/delete/', { + const response = await fetch(`${configuration.getDomainURL()}delete/`, { method: 'POST', headers: { 'Authorization': `Bearer ${await getToken()}` @@ -183,7 +171,7 @@ class RequestToDomain { * @returns */ static async getUserPriviledges(domain) { - const response = await fetch(`http://localhost:3001/secured/priviledges?domain=${domain}`, { + const response = await fetch(`${configuration.getDomainURL()}secured/priviledges?domain=${domain}`, { method: 'GET', headers: { 'Authorization': `Bearer ${await getToken()}` diff --git a/webapp/public/js/authentication/script.js b/webapp/public/js/authentication/script.js index e03119277437dcb4a758320e297633023425a68f..169cb371c5c59d2ec2239ed65acf6c0be2f9fa55 100644 --- a/webapp/public/js/authentication/script.js +++ b/webapp/public/js/authentication/script.js @@ -4,6 +4,8 @@ import App from './app.js'; import RequestToDomain from './requests-to-domain.js'; // import * as jose from 'jose'; // per la gestione del token +import Configuration from './configuration.js'; +const configuration = new Configuration(); const mySecure = new Secure(); @@ -13,29 +15,29 @@ let alreadyRefreshed = false; // true se ho appena fatto la richiesta del token let oldTimeout = null; const uri = window.location.toString(); -if(!uri.includes('#') && !uri.includes("/secured/home/")) { +if(!uri.includes(`#`) && !uri.includes("/secured/home/")) { const a = document.getElementById("my-link"); a.href = a.href.replace("$MY_CODE_CHALLENGE", mySecure.codeChallenge).replace("$MY_STATE", mySecure.state); - sessionStorage.setItem("stateSent", mySecure.state); // state inviato durante la richiesta dell'authcode + sessionStorage.setItem("stateSent", mySecure.state); // state inviato durante la richiesta dell`authcode sessionStorage.setItem("codeVerifier", mySecure.codeVerifier); //automatically redirect to the login page window.location.href = a.href; } else if(uri.includes("#")){ - // l'uri e' del tipo localhost:3000/secured# seguito da parametri - const uriSplit = uri.split('#'); - const params = uriSplit[1].split('&'); + // l`uri e` del tipo localhost:3000/secured# seguito da parametri + const uriSplit = uri.split(`#`); + const params = uriSplit[1].split(`&`); const uriState = queryStringGetValue(params[0]); const uriAuthCode = queryStringGetValue(params[2]); if(!sessionStorage.stateSent || sessionStorage.stateSent !== uriState) { // get the body element - const body = document.getElementsByTagName('body')[0]; + const body = document.getElementsByTagName(`body`)[0]; body.innerHTML = `Errors in the request!`; } else { await requestFirstToken(uriAuthCode); // post per la richiesta del token if(token !== null) { - expirationTime = moment().add(token.expires_in,'s'); + expirationTime = moment().add(token.expires_in,`s`); sessionStorage.setItem("expirationTime", expirationTime.toJSON()); const myDomains = await RequestToDomain.getMyDomains(); @@ -49,12 +51,12 @@ else if(uri.includes("#")){ // {nome: "casa4", stato:"on", admin: false} // ]; - const app = new App(myDomains); + const app = new App(myDomains,configuration); } } -} else if(uri.includes('/secured/home/')) { - token = JSON.parse(sessionStorage.getItem('token')); - expirationTime = moment(sessionStorage.getItem('expirationTime')); +} else if(uri.includes(`/secured/home/`)) { + token = JSON.parse(sessionStorage.getItem(`token`)); + expirationTime = moment(sessionStorage.getItem(`expirationTime`)); oldTimeout = timeoutRefresh(); } @@ -64,7 +66,7 @@ else if(uri.includes("#")){ * @returns il valore associato al parametro. */ function queryStringGetValue(queryString) { - const arr = queryString.split('='); + const arr = queryString.split(`=`); return arr[1]; } @@ -75,18 +77,18 @@ function queryStringGetValue(queryString) { */ async function requestFirstToken(uriAuthCode) { - const url = 'http://localhost:8080/realms/test00/protocol/openid-connect/token'; + const url = `${configuration.getKeycloakURL()}realms/${configuration.getKeycloakRealm()}/protocol/openid-connect/token`; const response = await fetch(url, { - method: 'POST', + method: `POST`, headers: { - 'Content-type':'application/x-www-form-urlencoded' + 'Content-type':`application/x-www-form-urlencoded` }, body: new URLSearchParams({ - grant_type: 'authorization_code', - client_id: 'myclient', + grant_type: `authorization_code`, + client_id: `myclient`, code_verifier: sessionStorage.getItem("codeVerifier"), code: uriAuthCode, - redirect_uri: 'http://localhost:3000/secured' + redirect_uri: `${configuration.getMyURL()}secured` }) }); token = await response.json(); @@ -113,15 +115,15 @@ async function getToken() { * Post per la richiesta del token usando il refresh token. */ async function requestUsingRefreshToken() { - const url = 'http://localhost:8080/realms/test00/protocol/openid-connect/token'; + const url = `${configuration.getKeycloakURL()}realms/${configuration.getKeycloakRealm()}/protocol/openid-connect/token`; const response = await fetch(url, { - method: 'POST', + method: `POST`, headers: { - 'Content-type':'application/x-www-form-urlencoded' + 'Content-type':`application/x-www-form-urlencoded` }, body: new URLSearchParams({ - grant_type: 'refresh_token', - client_id: 'myclient', + grant_type: `refresh_token`, + client_id: `myclient`, refresh_token: `${token.refresh_token}` }) }); @@ -129,7 +131,7 @@ async function getToken() { if(response.ok) { alreadyRefreshed = true; sessionStorage.setItem("token", JSON.stringify(token)); - expirationTime = moment().add(token.expires_in,'s'); + expirationTime = moment().add(token.expires_in,`s`); sessionStorage.setItem("expirationTime", expirationTime.toJSON()); oldTimeout = timeoutRefresh(); } @@ -163,7 +165,7 @@ async function logoutKeycloak() { if(token == null) return; clearTimeout(oldTimeout); // DA FARE: funziona, ma vedere se fare il redirect alla pagina iniziale. - window.location.href = `http://localhost:8080/realms/test00/protocol/openid-connect/logout?id_token_hint=${await getIdToken()}`; + window.location.href = `${configuration.getKeycloakURL()}realms/${configuration.getKeycloakRealm()}/protocol/openid-connect/logout?id_token_hint=${await getIdToken()}`; } diff --git a/webapp/public/js/scriptIndex.js b/webapp/public/js/scriptIndex.js index eb6474bc5281eda095475594da789ce6bbe09bfe..6895400a1526e86d5bf5cf561798a4c330a54ab2 100644 --- a/webapp/public/js/scriptIndex.js +++ b/webapp/public/js/scriptIndex.js @@ -7,7 +7,6 @@ import Scenari from "./scenari.js"; import Luci from './luci.js'; import Admin from './adminControls.js'; - const logout = document.getElementById("button-logout"); logout.addEventListener('click', () => { logoutKeycloak();