KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > connector > jrmps > JRMPSServerSocketFactory


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6 package org.jfox.ioc.connector.jrmps;
7
8 import java.io.IOException JavaDoc;
9 import java.io.Serializable JavaDoc;
10 import java.net.ServerSocket JavaDoc;
11 import java.rmi.server.RMIServerSocketFactory JavaDoc;
12 import java.security.KeyStore JavaDoc;
13 import javax.net.ssl.KeyManagerFactory;
14 import javax.net.ssl.SSLContext;
15
16 /**
17  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
18  */

19
20 public class JRMPSServerSocketFactory implements RMIServerSocketFactory JavaDoc, Serializable JavaDoc {
21     private String JavaDoc SSLKeyFile = "jfox.keystore";
22     private String JavaDoc password = "jfox.org";
23
24     public JRMPSServerSocketFactory(String JavaDoc SSLKeyFile, String JavaDoc password) {
25         this.SSLKeyFile = SSLKeyFile;
26         this.password = password;
27     }
28
29     public ServerSocket JavaDoc createServerSocket(int port) throws IOException JavaDoc {
30         try {
31             KeyStore JavaDoc keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
32             keyStore.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(SSLKeyFile), password.toCharArray());
33             KeyManagerFactory keyMgr = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
34             keyMgr.init(keyStore, password.toCharArray());
35
36 // TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
37
// tmf.init(keyStore);
38

39             SSLContext sslCtx = SSLContext.getInstance("TLS");
40             sslCtx.init(keyMgr.getKeyManagers(), null, null);
41             return sslCtx.getServerSocketFactory().createServerSocket(port);
42         }
43         catch(Exception JavaDoc e) {
44             e.printStackTrace();
45             return null;
46         }
47     }
48
49     public static void main(String JavaDoc[] args) {
50
51     }
52 }
53
54
Popular Tags