001: /*
002: * Factory for creating appropriate scoket wrappers. The code above this layer
003: * depends only on java.net.Socket inteface however the actual implementation
004: * can be of any Socket type Eg: KSSL, JSSE, Plain sockets
005: *
006: * @author Rajesh
007: * @date 16-July-2003
008: */
009: package com.sun.portal.netlet.client.common;
010:
011: import java.net.Socket;
012:
013: public class NetletSocketFactory {
014:
015: private static boolean isHTTPSGW = true;
016: private NetletSocketWrapper nsw = null;
017: private static NetletSocketFactory nsf = null;
018: private boolean isJSSEEnabled = false;
019: private boolean requireClientCert = false;
020:
021: /*
022: * Creates a new instance of NetletSocketFactory.
023: * Creating only instance of Factory per Netlet Applet
024: * Instance
025: */
026:
027: private NetletSocketFactory(String gwProtocol,
028: boolean isJSSEEnabled, boolean requireClientCert) {
029: if (gwProtocol.equalsIgnoreCase("https")) {
030: isHTTPSGW = true;
031: } else {
032: isHTTPSGW = false;
033: }
034: this .isJSSEEnabled = isJSSEEnabled;
035: this .requireClientCert = requireClientCert;
036: init();
037: }
038:
039: /*
040: *
041: */
042:
043: public Socket getSocket(String destHost, int destPort,
044: String[] cipherSuites) {
045: return nsw.getSocket(destHost, destPort, cipherSuites);
046: }
047:
048: /*
049: * Wraps around a plain socket that was used for Proxy tunneling.
050: * Proxy tunneling uses plain sockets to communicate. Basically this method
051: * just upgrades a Plain Socket to the underlying actual encryption socket
052: */
053:
054: public Socket getSocket(Socket tunnelSocket, String host, int port,
055: String[] cipherSuites) {
056: return nsw.getSocket(tunnelSocket, host, port, cipherSuites);
057: }
058:
059: /*
060: * Creates and returns a reference to the SocketFactory.
061: */
062:
063: public synchronized static NetletSocketFactory getNetletSocketFactory(
064: String gwProtocol, boolean isJSSE, boolean requireClientCert) {
065: if (nsf == null) {
066: nsf = new NetletSocketFactory(gwProtocol, isJSSE,
067: requireClientCert);
068: }
069: return nsf;
070: }
071:
072: /*
073: * Dynamically Loading the wrappers as its not alway necessary all the socket
074: * implementation are available/downloaded as the part of Netlet Applet.
075: * For Eg : On Java 1 VM there is no need to download JSSE wrapper implementations
076: */
077:
078: private void init() {
079:
080: try {
081: if (!isHTTPSGW) {
082: nsw = (NetletSocketWrapper) Class
083: .forName(
084: "com.sun.portal.netlet.client.common.PlainSocketWrapper")
085: .newInstance();
086: } else if (!isJSSEEnabled) {
087: nsw = (NetletSocketWrapper) Class
088: .forName(
089: "com.sun.portal.netlet.client.common.KSSLSocketWrapper")
090: .newInstance();
091: } else {
092: nsw = (NetletSocketWrapper) Class
093: .forName(
094: "com.sun.portal.netlet.client.common.JSSEWrapper")
095: .newInstance();
096: }
097: nsw.init(this .requireClientCert);
098: } catch (Exception e) {
099: e.printStackTrace();
100: }
101: }
102: }
|