1 22 package org.jboss.iiop.jacorb; 23 24 import java.io.IOException ; 25 import java.net.InetAddress ; 26 import java.net.ServerSocket ; 27 import javax.net.ssl.SSLServerSocket; 28 29 import org.jboss.iiop.CorbaORBService; 30 import org.jboss.logging.Logger; 31 import org.jboss.security.SecurityDomain; 32 import org.jboss.security.ssl.DomainServerSocketFactory; 33 import org.jboss.system.Registry; 34 35 46 public class SSLServerSocketFactory 47 implements org.jacorb.orb.factory.SSLServerSocketFactory, 48 org.apache.avalon.framework.configuration.Configurable 49 { 50 52 private static Logger log = Logger.getLogger(SSLServerSocketFactory.class); 53 54 56 private DomainServerSocketFactory domainFactory = null; 57 private boolean require_mutual_auth = false; 58 private boolean request_mutual_auth = false; 59 60 62 public SSLServerSocketFactory(org.jacorb.orb.ORB orb) 63 throws IOException 64 { 65 log.info("Creating"); 66 67 SecurityDomain securityDomain = 68 (SecurityDomain)Registry.lookup(CorbaORBService.SSL_DOMAIN); 69 70 try 71 { 72 domainFactory = new DomainServerSocketFactory(securityDomain); 73 } 74 catch (IOException e) 75 { 76 log.warn("Could not create DomainServerSocketFactory: " + e); 77 log.debug("Exception creating DomainServerSockedFactory: ", e); 78 throw e; 79 } 80 81 short serverSupportedOptions = Short.parseShort( 82 orb.getConfiguration().getAttribute( 83 "jacorb.security.ssl.server.supported_options","20"), 84 16); short serverRequiredOptions = Short.parseShort( 86 orb.getConfiguration().getAttribute( 87 "jacorb.security.ssl.server.required_options","0"), 88 16); 90 91 if ((serverSupportedOptions & 0x40) != 0) 92 { 93 request_mutual_auth = true; 96 } 97 if ((serverRequiredOptions & 0x40) != 0) 98 { 99 require_mutual_auth = true; 102 request_mutual_auth = false; 103 } 104 if (request_mutual_auth) 105 log.info("Will create SSL sockets that support client authentication"); 106 else if (require_mutual_auth) 107 log.info("Will create SSL sockets that require client authentication"); 108 log.info("Created"); 109 } 110 111 114 public ServerSocket createServerSocket(int port) 115 throws IOException 116 { 117 SSLServerSocket s = 118 (SSLServerSocket)domainFactory.createServerSocket(port); 119 120 if (request_mutual_auth) 121 s.setWantClientAuth(request_mutual_auth); 122 else if (require_mutual_auth) 123 s.setNeedClientAuth(require_mutual_auth); 124 125 return s; 126 } 127 128 public ServerSocket createServerSocket(int port, int backlog) 129 throws IOException 130 { 131 SSLServerSocket s = 132 (SSLServerSocket)domainFactory.createServerSocket(port, backlog); 133 134 if (request_mutual_auth) 135 s.setWantClientAuth(request_mutual_auth); 136 else if (require_mutual_auth) 137 s.setNeedClientAuth(require_mutual_auth); 138 139 return s; 140 } 141 142 public ServerSocket createServerSocket(int port, 143 int backlog, 144 InetAddress ifAddress) 145 throws IOException 146 { 147 SSLServerSocket s = 148 (SSLServerSocket)domainFactory.createServerSocket(port, 149 backlog, ifAddress); 150 151 if (request_mutual_auth) 152 s.setWantClientAuth(request_mutual_auth); 153 else if (require_mutual_auth) 154 s.setNeedClientAuth(require_mutual_auth); 155 156 return s; 157 } 158 159 public boolean isSSL(java.net.ServerSocket s) 160 { 161 return (s instanceof SSLServerSocket); 162 } 163 164 public void switchToClientMode(java.net.Socket socket) 165 { 166 } 168 169 171 public void configure( 172 org.apache.avalon.framework.configuration.Configuration configuration) 173 throws org.apache.avalon.framework.configuration.ConfigurationException 174 { 175 } 177 } 178 | Popular Tags |