update
This commit is contained in:
parent
2992f4f408
commit
4f46de8d00
3330 changed files with 394553 additions and 76939 deletions
101
.config/Code/User/History/-61e372a/0CIN.java
Normal file
101
.config/Code/User/History/-61e372a/0CIN.java
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
124
.config/Code/User/History/-61e372a/0ILB.java
Normal file
124
.config/Code/User/History/-61e372a/0ILB.java
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
139
.config/Code/User/History/-61e372a/181O.java
Normal file
139
.config/Code/User/History/-61e372a/181O.java
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
String response = Integer.toString(1);
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
103
.config/Code/User/History/-61e372a/1zzn.java
Normal file
103
.config/Code/User/History/-61e372a/1zzn.java
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) return 1;
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
83
.config/Code/User/History/-61e372a/577P.java
Normal file
83
.config/Code/User/History/-61e372a/577P.java
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
108
.config/Code/User/History/-61e372a/6CWC.java
Normal file
108
.config/Code/User/History/-61e372a/6CWC.java
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else{
|
||||
response = Integer.toString(0); // user not registered
|
||||
}
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
87
.config/Code/User/History/-61e372a/7Wsx.java
Normal file
87
.config/Code/User/History/-61e372a/7Wsx.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new GreetHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class GreetHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
System.out.println("worked");
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
System.out.println(username);
|
||||
System.out.println(password);
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
103
.config/Code/User/History/-61e372a/8TGt.java
Normal file
103
.config/Code/User/History/-61e372a/8TGt.java
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
106
.config/Code/User/History/-61e372a/994V.java
Normal file
106
.config/Code/User/History/-61e372a/994V.java
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
93
.config/Code/User/History/-61e372a/AERf.java
Normal file
93
.config/Code/User/History/-61e372a/AERf.java
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;
|
||||
|
||||
import antlr.debug.TraceAdapter;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
SessionFactory session = HibernateUtil.getSessionfactory();
|
||||
session.openSession();
|
||||
|
||||
Transaction transaction = session.beginTransaction();
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
97
.config/Code/User/History/-61e372a/C5na.java
Normal file
97
.config/Code/User/History/-61e372a/C5na.java
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
tx.rollback();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
147
.config/Code/User/History/-61e372a/CSoo.java
Normal file
147
.config/Code/User/History/-61e372a/CSoo.java
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
String response = Integer.toString(1);
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
124
.config/Code/User/History/-61e372a/Cyh0.java
Normal file
124
.config/Code/User/History/-61e372a/Cyh0.java
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
100
.config/Code/User/History/-61e372a/DuoE.java
Normal file
100
.config/Code/User/History/-61e372a/DuoE.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
100
.config/Code/User/History/-61e372a/EgLB.java
Normal file
100
.config/Code/User/History/-61e372a/EgLB.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
134
.config/Code/User/History/-61e372a/F1Lh.java
Normal file
134
.config/Code/User/History/-61e372a/F1Lh.java
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
122
.config/Code/User/History/-61e372a/GCq2.java
Normal file
122
.config/Code/User/History/-61e372a/GCq2.java
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
149
.config/Code/User/History/-61e372a/H5D3.java
Normal file
149
.config/Code/User/History/-61e372a/H5D3.java
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
System.err.println("line 85 server");
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
String response = Integer.toString(1);
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
134
.config/Code/User/History/-61e372a/J1Tb.java
Normal file
134
.config/Code/User/History/-61e372a/J1Tb.java
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
114
.config/Code/User/History/-61e372a/JCl3.java
Normal file
114
.config/Code/User/History/-61e372a/JCl3.java
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
126
.config/Code/User/History/-61e372a/M3PG.java
Normal file
126
.config/Code/User/History/-61e372a/M3PG.java
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
103
.config/Code/User/History/-61e372a/Nf6m.java
Normal file
103
.config/Code/User/History/-61e372a/Nf6m.java
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response;
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
120
.config/Code/User/History/-61e372a/S0m8.java
Normal file
120
.config/Code/User/History/-61e372a/S0m8.java
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
100
.config/Code/User/History/-61e372a/SpUg.java
Normal file
100
.config/Code/User/History/-61e372a/SpUg.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
100
.config/Code/User/History/-61e372a/VPmI.java
Normal file
100
.config/Code/User/History/-61e372a/VPmI.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
// Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
// Transaction tx = null;
|
||||
|
||||
// try{
|
||||
// tx = session.beginTransaction();
|
||||
|
||||
// }
|
||||
// catch(Exception e){
|
||||
// if(tx != null) tx.rollback();
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// finally{
|
||||
// session.close();
|
||||
// }
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
85
.config/Code/User/History/-61e372a/VX9s.java
Normal file
85
.config/Code/User/History/-61e372a/VX9s.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new GreetHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class GreetHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
System.out.println("worked");
|
||||
JSONObject jsonObject = new JSONObject(exchange.getRequestBody());
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
System.out.println(username);
|
||||
System.out.println(password);
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
103
.config/Code/User/History/-61e372a/biEU.java
Normal file
103
.config/Code/User/History/-61e372a/biEU.java
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response;
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
106
.config/Code/User/History/-61e372a/ceIg.java
Normal file
106
.config/Code/User/History/-61e372a/ceIg.java
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response;
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
}
|
||||
else{
|
||||
response = Integer.toString(0); // user not registered
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
103
.config/Code/User/History/-61e372a/eG5X.java
Normal file
103
.config/Code/User/History/-61e372a/eG5X.java
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response;
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password)
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
107
.config/Code/User/History/-61e372a/eXVu.java
Normal file
107
.config/Code/User/History/-61e372a/eXVu.java
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response;
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else{
|
||||
response = Integer.toString(0); // user not registered
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
1
.config/Code/User/History/-61e372a/entries.json
Normal file
1
.config/Code/User/History/-61e372a/entries.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":1,"resource":"file:///home/rafayahmad/Stuff/Coding/Java/HCloud/hcloudserver/src/main/java/com/rutils/Main.java","entries":[{"id":"pPKv.java","timestamp":1720435140555},{"id":"VX9s.java","timestamp":1720435189171},{"id":"jGdD.java","timestamp":1720435255431},{"id":"pPWn.java","timestamp":1720435294091},{"id":"pPvX.java","timestamp":1720435350760},{"id":"7Wsx.java","timestamp":1720435397497},{"id":"fZrq.java","timestamp":1720435422504},{"id":"577P.java","timestamp":1720769364234},{"id":"knsh.java","timestamp":1720769403746},{"id":"AERf.java","timestamp":1720769482802},{"id":"zkAR.java","timestamp":1720769505251},{"id":"C5na.java","timestamp":1720769545488},{"id":"fN16.java","timestamp":1720769556354},{"id":"0CIN.java","timestamp":1720769579104},{"id":"SpUg.java","timestamp":1720769590488},{"id":"VPmI.java","timestamp":1720773736127},{"id":"EgLB.java","timestamp":1720774241892},{"id":"kLRL.java","timestamp":1720774281670},{"id":"gLsw.java","timestamp":1720774408790},{"id":"DuoE.java","timestamp":1720774431447},{"id":"8TGt.java","timestamp":1720774489894},{"id":"1zzn.java","timestamp":1720774625118},{"id":"eG5X.java","timestamp":1720774654509},{"id":"biEU.java","timestamp":1720774688820},{"id":"Nf6m.java","timestamp":1720774711147},{"id":"ceIg.java","timestamp":1720774734711},{"id":"eXVu.java","timestamp":1720774759609},{"id":"6CWC.java","timestamp":1720774786193},{"id":"994V.java","timestamp":1720774797397},{"id":"qe8s.java","timestamp":1720775708132},{"id":"JCl3.java","timestamp":1720775729975},{"id":"S0m8.java","timestamp":1720775759138},{"id":"vQlP.java","timestamp":1720775779338},{"id":"GCq2.java","timestamp":1720775864581},{"id":"0ILB.java","timestamp":1720775874605},{"id":"Cyh0.java","timestamp":1720776048802},{"id":"M3PG.java","timestamp":1720776066866},{"id":"pQ4j.java","timestamp":1720776154253},{"id":"F1Lh.java","timestamp":1720777251563},{"id":"xvI3.java","timestamp":1720777263007},{"id":"gJi0.java","timestamp":1720777298204},{"id":"x4Wn.java","timestamp":1720777320364},{"id":"J1Tb.java","timestamp":1720778841323},{"id":"qvxT.java","timestamp":1720778991904},{"id":"qbzc.java","timestamp":1720779019797},{"id":"181O.java","timestamp":1720779046724},{"id":"kg5P.java","timestamp":1720779182355},{"id":"CSoo.java","timestamp":1720779211701},{"id":"H5D3.java","timestamp":1720779242352},{"id":"y2Yd.java","timestamp":1720780559773}]}
|
||||
97
.config/Code/User/History/-61e372a/fN16.java
Normal file
97
.config/Code/User/History/-61e372a/fN16.java
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
83
.config/Code/User/History/-61e372a/fZrq.java
Normal file
83
.config/Code/User/History/-61e372a/fZrq.java
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new GreetHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class GreetHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
134
.config/Code/User/History/-61e372a/gJi0.java
Normal file
134
.config/Code/User/History/-61e372a/gJi0.java
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
100
.config/Code/User/History/-61e372a/gLsw.java
Normal file
100
.config/Code/User/History/-61e372a/gLsw.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(username, User.class);
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
86
.config/Code/User/History/-61e372a/jGdD.java
Normal file
86
.config/Code/User/History/-61e372a/jGdD.java
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new GreetHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class GreetHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
System.out.println("worked");
|
||||
JSONObject jsonObject = new JSONObject(exchange.getRequestBody());
|
||||
System.out.println(exchange.getRequestBody());
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
System.out.println(username);
|
||||
System.out.println(password);
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
99
.config/Code/User/History/-61e372a/kLRL.java
Normal file
99
.config/Code/User/History/-61e372a/kLRL.java
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
145
.config/Code/User/History/-61e372a/kg5P.java
Normal file
145
.config/Code/User/History/-61e372a/kg5P.java
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
}
|
||||
|
||||
String response = Integer.toString(1);
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
87
.config/Code/User/History/-61e372a/knsh.java
Normal file
87
.config/Code/User/History/-61e372a/knsh.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
SessionFactory session = HibernateUtil.getSessionfactory();
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
86
.config/Code/User/History/-61e372a/pPKv.java
Normal file
86
.config/Code/User/History/-61e372a/pPKv.java
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new GreetHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class GreetHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
System.out.println("worked");
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
System.out.println("worked");
|
||||
JSONObject jsonObject = new JSONObject(exchange.getRequestBody());
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
System.out.println(username);
|
||||
System.out.println(password);
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
87
.config/Code/User/History/-61e372a/pPWn.java
Normal file
87
.config/Code/User/History/-61e372a/pPWn.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new GreetHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class GreetHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
System.out.println("worked");
|
||||
|
||||
JSONObject jsonObject = new JSONObject(exchange.getRequestBody());
|
||||
System.out.println(exchange.getRequestBody());
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
System.out.println(username);
|
||||
System.out.println(password);
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
87
.config/Code/User/History/-61e372a/pPvX.java
Normal file
87
.config/Code/User/History/-61e372a/pPvX.java
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new GreetHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class GreetHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
System.out.println("worked");
|
||||
JSONObject jsonObject = new JSONObject(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
System.out.println(exchange.getRequestBody());
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
System.out.println(username);
|
||||
System.out.println(password);
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
126
.config/Code/User/History/-61e372a/pQ4j.java
Normal file
126
.config/Code/User/History/-61e372a/pQ4j.java
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
137
.config/Code/User/History/-61e372a/qbzc.java
Normal file
137
.config/Code/User/History/-61e372a/qbzc.java
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
String response = Integer.toString(1);
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
115
.config/Code/User/History/-61e372a/qe8s.java
Normal file
115
.config/Code/User/History/-61e372a/qe8s.java
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
137
.config/Code/User/History/-61e372a/qvxT.java
Normal file
137
.config/Code/User/History/-61e372a/qvxT.java
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
String response = Integer.toString(1);
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
122
.config/Code/User/History/-61e372a/vQlP.java
Normal file
122
.config/Code/User/History/-61e372a/vQlP.java
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
136
.config/Code/User/History/-61e372a/x4Wn.java
Normal file
136
.config/Code/User/History/-61e372a/x4Wn.java
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
133
.config/Code/User/History/-61e372a/xvI3.java
Normal file
133
.config/Code/User/History/-61e372a/xvI3.java
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
session.close();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
149
.config/Code/User/History/-61e372a/y2Yd.java
Normal file
149
.config/Code/User/History/-61e372a/y2Yd.java
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.createContext("/register", new RegisterHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class RegisterHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
User user = new User(username, password);
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
session.save(user);
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
System.err.println("line 85 server");
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
String response = Integer.toString(1);
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Integer.toString(1);
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
Transaction tx = null;
|
||||
|
||||
try{
|
||||
tx = session.beginTransaction();
|
||||
User user = session.get(User.class, username);
|
||||
if(user != null){
|
||||
if(user.getPassword() == password) response = Integer.toString(1); // successful verification
|
||||
else response = Integer.toString(2); // incorrect password
|
||||
}
|
||||
else response = Integer.toString(0); // user not registered
|
||||
tx.commit();
|
||||
}
|
||||
catch(Exception e){
|
||||
if(tx != null) tx.rollback();
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally{
|
||||
session.close();
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
86
.config/Code/User/History/-61e372a/zkAR.java
Normal file
86
.config/Code/User/History/-61e372a/zkAR.java
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
package com.rutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
import com.sun.net.httpserver.HttpsConfigurator;
|
||||
import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;;
|
||||
|
||||
public class Main{
|
||||
|
||||
static HttpsServer server;
|
||||
|
||||
static{
|
||||
try{
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
keyStore.load(Main.class.getClassLoader().getResourceAsStream("server.p12"), "ksserver7548".toCharArray());
|
||||
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(keyStore, "ksserver7548".toCharArray());
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(kmf.getKeyManagers(), null, null);
|
||||
|
||||
server = HttpsServer.create(new InetSocketAddress(8000), 0);
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(sslContext){
|
||||
@Override
|
||||
public void configure(HttpsParameters params){
|
||||
// InetSocketAddress remote = params.getClientAddress();
|
||||
SSLContext c = getSSLContext();
|
||||
SSLParameters sslParameters = c.getDefaultSSLParameters();
|
||||
// if(remote.equals()){
|
||||
|
||||
// }
|
||||
params.setSSLParameters(sslParameters);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public static void main(String[] args){
|
||||
server.createContext("/login", new LoginHandler());
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
}
|
||||
|
||||
static class LoginHandler implements HttpHandler{
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException{
|
||||
if("POST".equals(exchange.getRequestMethod())){
|
||||
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = new JSONObject(body);
|
||||
String username = jsonObject.getString("username");
|
||||
String password = jsonObject.getString("password");
|
||||
|
||||
String response = Boolean.toString("test".equals(username));
|
||||
|
||||
Session session = HibernateUtil.getSessionfactory().openSession();
|
||||
|
||||
exchange.sendResponseHeaders(200, response.length());
|
||||
OutputStream os = exchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
else{
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue