1 7 package org.jboss.remoting.transport.socket.ssl; 8 9 import java.io.IOException ; 10 import java.net.InetAddress ; 11 import java.net.ServerSocket ; 12 import java.util.Map ; 13 import java.util.Properties ; 14 import javax.management.MBeanServer ; 15 import javax.management.MBeanServerInvocationHandler ; 16 import javax.management.MalformedObjectNameException ; 17 import javax.management.ObjectName ; 18 import javax.net.ServerSocketFactory; 19 import javax.net.ssl.SSLServerSocketFactory; 20 import org.jboss.remoting.InvokerLocator; 21 import org.jboss.remoting.security.ServerSocketFactoryMBean; 22 import org.jboss.remoting.transport.socket.SocketServerInvoker; 23 24 27 public class SSLSocketServerInvoker extends SocketServerInvoker implements SSLSocketServerInvokerMBean 28 { 29 protected ServerSocketFactory serverSocketFactory = null; 30 31 32 public SSLSocketServerInvoker(InvokerLocator locator) 33 { 34 super(locator); 35 } 36 37 public SSLSocketServerInvoker(InvokerLocator locator, Map configuration) 38 { 39 super(locator, configuration); 40 } 41 42 protected ServerSocket createServerSocket(int serverBindPort, int backlog, InetAddress bindAddress) throws IOException 43 { 44 ServerSocket svrSocket = null; 45 Properties props = getProperties(); 46 47 52 if(serverSocketFactory != null) 53 { 54 svrSocket = serverSocketFactory.createServerSocket(serverBindPort, backlog, bindAddress); 55 } 56 else 57 { 58 59 67 if(props.getProperty("serverSocketFactory") != null) 68 { 69 try 70 { 71 String serverSocketFactoryString = props.getProperty("serverSocketFactory"); 72 if(serverSocketFactoryString != null) 73 { 74 MBeanServer server = getMBeanServer(); 75 ObjectName serverSocketFactoryObjName = new ObjectName (serverSocketFactoryString); 76 if(server != null) 77 { 78 try 79 { 80 ServerSocketFactoryMBean serverSocketFactory = (ServerSocketFactoryMBean) MBeanServerInvocationHandler.newProxyInstance(server, 81 serverSocketFactoryObjName, 82 ServerSocketFactoryMBean.class, 83 false); 84 svrSocket = serverSocketFactory.createServerSocket(serverBindPort, backlog, bindAddress); 85 } 86 catch(Exception e) 87 { 88 log.error("Error creating mbean proxy for server socket factory for object name: " + serverSocketFactoryObjName, e); 89 throw new IOException ("Error createing custom server socket factory."); 90 } 91 } 92 else 93 { 94 log.error("The 'serverSocketFactory' attribute was set with a value, but the MBeanServer reference is null."); 95 throw new IOException ("Error creating custom server socket factory. The invoker does not have a reference to the mbean server."); 96 } 97 } 98 } 99 catch(MalformedObjectNameException e) 100 { 101 log.error("Error setting the server socket factory due to the attibute value passed not being a valid ObjectName.", e); 102 throw new IOException ("Error creating custom server socket factory. The attributed value passed is not a valid object name."); 103 } 104 catch(NullPointerException e) 105 { 106 log.error("Error setting the server socket factory due to null pointer exception.", e); 107 throw new IOException ("Error creating custom server socket factory."); 108 } 109 } 110 } 111 112 if(svrSocket == null) 113 { 114 log.debug("Creating default server socket."); 115 serverSocketFactory = SSLServerSocketFactory.getDefault(); 116 svrSocket = serverSocketFactory.createServerSocket(serverBindPort, backlog, bindAddress); 117 } 118 119 log.debug("Created server socket: " + svrSocket); 120 121 return svrSocket; 122 123 } 124 125 132 public void setServerSocketFactory(ServerSocketFactory serverSocketFactory) 133 { 134 this.serverSocketFactory = serverSocketFactory; 135 } 136 137 } | Popular Tags |