diff --git a/build.gradle b/build.gradle index 79965bd..90fb8e3 100644 --- a/build.gradle +++ b/build.gradle @@ -11,12 +11,25 @@ repositories { mavenCentral() } +jar { + manifest { + attributes 'Main-Class': 'com.wasteinformationserver.main' + } + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } +} + sourceSets { main.java.srcDirs = ['src/java'] main.resources.srcDirs = ['src/resources'] } dependencies { - compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.0.2' + compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.2.2' compile group: 'mysql',name:'mysql-connector-java',version: '8.0.18' } + +task run (type: JavaExec){ + description = "Secure algorythm testing" + main = 'com.wasteinformationserver.main' + classpath = sourceSets.main.runtimeClasspath +} \ No newline at end of file diff --git a/src/java/com/wasteinformationserver/db/MySQLConnector.java b/src/java/com/wasteinformationserver/db/MySQLConnector.java index 8a84cbb..0053679 100755 --- a/src/java/com/wasteinformationserver/db/MySQLConnector.java +++ b/src/java/com/wasteinformationserver/db/MySQLConnector.java @@ -8,7 +8,7 @@ public class MySQLConnector extends Database { static { try { - Class.forName("com.mysql.jdbc.Driver").newInstance(); + Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance(); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/java/com/wasteinformationserver/main.java b/src/java/com/wasteinformationserver/main.java index be98985..d673047 100644 --- a/src/java/com/wasteinformationserver/main.java +++ b/src/java/com/wasteinformationserver/main.java @@ -28,7 +28,8 @@ public class main { Log.message("initial login to db"); new Thread(() -> { try { - JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); + JDCB.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306); + //JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); } catch (IOException e) { //e.printStackTrace(); Log.error("no connection to db"); diff --git a/src/java/com/wasteinformationserver/website/Webserver.java b/src/java/com/wasteinformationserver/website/Webserver.java index 3006404..49369e3 100644 --- a/src/java/com/wasteinformationserver/website/Webserver.java +++ b/src/java/com/wasteinformationserver/website/Webserver.java @@ -23,12 +23,13 @@ public class Webserver { e.printStackTrace(); } + server.createContext("/", new MainPage()); server.createContext("/senddata/loginget", new LoginRequest()); - server.createContext("/senddata/registerpost",new RegisterRequest()); - server.createContext("/senddata/checkloginstate",new CheckLoginState()); - server.createContext("/senddata/wastedata",new DataRequest()); + server.createContext("/senddata/registerpost", new RegisterRequest()); + server.createContext("/senddata/checkloginstate", new CheckLoginState()); + server.createContext("/senddata/wastedata", new DataRequest()); server.createContext("/senddata/admindata", new AdminRequests()); server.createContext("/senddata/newdate", new NewDateRequest()); @@ -36,5 +37,63 @@ public class Webserver { server.start(); Log.info("Server available at http://127.0.0.1:8000 now"); + /* + + try { + server = HttpsServer.create(new InetSocketAddress(8000), 0); + + // initialise the HTTPS server + SSLContext sslContext = SSLContext.getInstance("TLS"); + + // initialise the keystore + char[] password = "password".toCharArray(); + KeyStore ks = KeyStore.getInstance("JKS"); + FileInputStream fis = new FileInputStream("testkey.jks"); + ks.load(fis, password); + + // setup the key manager factory + KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); + kmf.init(ks, password); + + // setup the trust manager factory + TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); + tmf.init(ks); + + // setup the HTTPS context and parameters + sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); + server.setHttpsConfigurator(new HttpsConfigurator(sslContext) { + public void configure(HttpsParameters params) { + try { + // initialise the SSL context + SSLContext context = getSSLContext(); + SSLEngine engine = context.createSSLEngine(); + params.setNeedClientAuth(false); + params.setCipherSuites(engine.getEnabledCipherSuites()); + params.setProtocols(engine.getEnabledProtocols()); + + // Set the SSL parameters + SSLParameters sslParameters = context.getSupportedSSLParameters(); + params.setSSLParameters(sslParameters); + + } catch (Exception ex) { + System.out.println("Failed to create HTTPS port"); + } + } + }); + } catch (IOException e) { + e.printStackTrace(); + } catch (CertificateException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (UnrecoverableKeyException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + */ + } } diff --git a/src/java/com/wasteinformationserver/website/datarequests/login/LoginState.java b/src/java/com/wasteinformationserver/website/datarequests/login/LoginState.java index ebeb75a..128f1d1 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/login/LoginState.java +++ b/src/java/com/wasteinformationserver/website/datarequests/login/LoginState.java @@ -15,7 +15,7 @@ public class LoginState { private String email; private int permission; - boolean loggedin = false; + boolean loggedin = true; public void logIn(){ loggedin=true; diff --git a/src/resources/wwwroot/index.html b/src/resources/wwwroot/index.html index 969a759..9d58a73 100644 --- a/src/resources/wwwroot/index.html +++ b/src/resources/wwwroot/index.html @@ -26,6 +26,8 @@ + +