1 16 17 18 package org.apache.xmlrpc.secure; 19 20 21 import java.io.FileInputStream ; 22 import java.net.InetAddress ; 23 import java.net.ServerSocket ; 24 import java.security.KeyStore ; 25 26 import javax.net.ssl.SSLServerSocket; 27 import javax.net.ssl.SSLServerSocketFactory; 28 29 import org.apache.xmlrpc.WebServer; 30 import org.apache.xmlrpc.XmlRpc; 31 import org.apache.xmlrpc.XmlRpcServer; 32 33 import com.sun.net.ssl.KeyManagerFactory; 34 import com.sun.net.ssl.SSLContext; 35 36 48 public class SecureWebServer 49 extends WebServer 50 implements SecurityConstants 51 { 52 59 public SecureWebServer(int port) 60 { 61 this(port, null); 62 } 63 64 72 public SecureWebServer(int port, InetAddress addr) 73 { 74 super(port, addr); 75 } 76 77 78 82 public SecureWebServer(int port, InetAddress addr, XmlRpcServer xmlrpc) 83 { 84 super(port, addr, xmlrpc); 85 } 86 87 90 protected ServerSocket createServerSocket(int port, int backlog, InetAddress add) 91 throws Exception 92 { 93 SecurityTool.setup(); 94 95 SSLContext context = SSLContext.getInstance(SecurityTool.getSecurityProtocol()); 96 97 KeyManagerFactory keyManagerFactory = 98 KeyManagerFactory.getInstance(SecurityTool.getKeyManagerType()); 99 100 KeyStore keyStore = KeyStore.getInstance(SecurityTool.getKeyStoreType()); 101 102 keyStore.load(new FileInputStream (SecurityTool.getKeyStore()), 103 SecurityTool.getKeyStorePassword().toCharArray()); 104 105 keyManagerFactory.init(keyStore, SecurityTool.getKeyStorePassword().toCharArray()); 106 107 context.init(keyManagerFactory.getKeyManagers(), null, null); 108 SSLServerSocketFactory sslSrvFact = context.getServerSocketFactory(); 109 return (SSLServerSocket) sslSrvFact.createServerSocket(port); 110 } 111 112 118 public static void main(String [] argv) 119 { 120 int p = determinePort(argv, 10000); 121 XmlRpc.setKeepAlive (true); 122 SecureWebServer webserver = new SecureWebServer (p); 123 124 try 125 { 126 webserver.addDefaultHandlers(); 127 webserver.start(); 128 } 129 catch (Exception e) 130 { 131 System.err.println("Error running secure web server"); 132 e.printStackTrace(); 133 System.exit(1); 134 } 135 } 136 } 137 | Popular Tags |