import java.io.*;
import java.net.*;
import java.security.*;
import javax.crypto.*;
public class ServerThreadSocketHandler extends Thread {
private int id;
private Socket socket;
private ServerSecuredComm ssc;
private ServerInfo si;
private String AHost;
private int APort;
private int RPort;
private ServerSecrets ss;
private String rs;
private static String cipherAlgorithm = "DES/ECB/PKCS5Padding";
private static String htmlPath = "/home/B7D/globus/IRIX-Apache/htdocs/WebFlowGate/";
// private static String htmlPath = "/home/B8D/cyoun/WEBFLOW3/JAVA/";
private static String pubPath = "http://terminator.npac.syr.edu:2955/WebFlowGate/";
// private static String pubPath = "http://knothead.npac.syr.edu:2956/WebFlowGate/";
private static String rmipath = "//terminator.npac.syr.edu:";
public ServerThreadSocketHandler(int i, int j, Socket s, ServerInfo inf,
ServerKeyPair skp, ThreadGroup g, String ahost, int aport, int rport,
ServerSecrets se) {
super(g, Integer.toString(i));
id = j;
socket = s;
si = inf;
ssc = new ServerSecuredComm(socket, skp);
AHost = ahost;
APort = aport;
RPort = rport;
ss = se;
}
protected void printHTML(String u) {
try {
PrintWriter p = new PrintWriter(new FileOutputStream(htmlPath + rs + ".html"), true);
// PrintWriter p = new PrintWriter(new FileOutputStream(htmlPath + "demo" + ".html"), true);
p.println("");
p.println("
");
p.println(" WebFlow GateKeeper
");
p.println("");
p.println("");
p.println("");
p.close();
} catch (Exception e) {
System.err.println("ServerThreadSocketHandler.printHTML() Exception-> " + e);
}
}
protected boolean verification(String u, String p) {
Socket socket;
ObjectOutputStream oos;
ObjectInputStream ois;
try {
// open connection to Authenticator to verify username/password
socket = new Socket(AHost, APort);
ois = new ObjectInputStream(socket.getInputStream());
oos = new ObjectOutputStream(socket.getOutputStream());
oos.flush();
} catch (Exception ex) {
System.err.println("ServerThreadSocketHandler: verification() Exception-> " + ex);
ois= null;
oos= null;
socket = null;
return false;
}
try {
Cipher cipher = Cipher.getInstance(cipherAlgorithm);
cipher.init(Cipher.ENCRYPT_MODE, ss.getSecretKey());
WFUserPassMessage wfupm = new WFUserPassMessage(u, p);
SealedObject so = new SealedObject(wfupm, cipher);
WFVerification wfv = new WFVerification(id, so);
oos.writeObject(wfv);
oos.flush();
WFMessage wfm = (WFMessage) ois.readObject();
ois.close();
oos.close();
socket.close();
if (wfm.type == 1) {
rs = wfm.msg;
printHTML(u);
return true;
}
return false;
} catch (Exception ex) {
System.err.println("ServerThreadSocketHandler: verification() Exception-> " + ex);
}
try {
ois.close();
oos.close();
socket.close();
} catch (Exception ex) {
System.err.println("ServerThreadSocketHandler: verification() Exception-> " + ex);
}
return false;
}
public void run() {
try {
// initialize the socket connection and all message control objects
int i = 0;
if (!ssc.init()) {
System.err.println("ServerSecuredComm.init(): failed");
ssc.done();
}
// check the message type
if (ssc.receive()) {
WFUserPassMessage wfupm = (WFUserPassMessage)ssc.getMessage();
if (verification(wfupm.username, wfupm.password)) {
// get the dynamic URL from WebFlow server and retrun
// to the client
ssc.setupMessage(1, pubPath + rs + ".html");
// ssc.setupMessage(1, pubPath + "demo" + ".html");
} else {
System.err.println("ServerThread: authentication failed");
ssc.setupMessage(0, "verification failed");
}
ssc.send();
}
} catch (Exception ex) {
System.err.println("ServerThread Exception-> " + ex);
}
ssc.done();
si.decrease();
}
}