From: Scott M S. <st...@us...> - 2002-08-15 23:43:14
|
User: starksm Date: 02/08/15 16:43:13 Modified: src/main/org/jboss/security/ssl Tag: Branch_3_0 DomainServerSocketFactory.java Log: Change this to extend the javax.net.ssl.SSLServerSocketFactory class so that it may be used in more contexts Revision Changes Path No revision No revision 1.2.2.2 +69 -30 jbosssx/src/main/org/jboss/security/ssl/DomainServerSocketFactory.java Index: DomainServerSocketFactory.java =================================================================== RCS file: /cvsroot/jboss/jbosssx/src/main/org/jboss/security/ssl/DomainServerSocketFactory.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -r1.2.2.1 -r1.2.2.2 --- DomainServerSocketFactory.java 14 Jul 2002 09:05:29 -0000 1.2.2.1 +++ DomainServerSocketFactory.java 15 Aug 2002 23:43:13 -0000 1.2.2.2 @@ -11,6 +11,7 @@ import javax.naming.InitialContext; import javax.net.ServerSocketFactory; import javax.net.ssl.SSLServerSocket; +import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSocket; import com.sun.net.ssl.KeyManager; @@ -32,13 +33,14 @@ @see org.jboss.security.SecurityDomain @author Sco...@jb... -@version $Revision: 1.2.2.1 $ +@version $Revision: 1.2.2.2 $ */ -public class DomainServerSocketFactory extends ServerSocketFactory +public class DomainServerSocketFactory extends SSLServerSocketFactory { private static Logger log = Logger.getLogger(DomainServerSocketFactory.class); private transient SecurityDomain securityDomain; private transient InetAddress bindAddress; + private transient SSLContext sslCtx = null; /** A default constructor for use when created by Class.newInstance. The factory is not usable until its SecurityDomain has been established. @@ -77,7 +79,7 @@ this.securityDomain = securityDomain; } -// --- Begin ServerSocketFactory interface methods +// --- Begin SSLServerSocketFactory interface methods public ServerSocket createServerSocket(int port) throws IOException { return createServerSocket(port, 50, bindAddress); @@ -102,7 +104,70 @@ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException { - SSLContext sslCtx = null; + initSSLContext(); + ServerSocketFactory factory = sslCtx.getServerSocketFactory(); + ServerSocket socket = factory.createServerSocket(port, backlog, ifAddress); + return socket; + } + + /** The default ServerSocketFactory which looks to the java:/jaas/other + security domain configuration. + */ + public static ServerSocketFactory getDefault() + { + DomainServerSocketFactory ssf = null; + try + { + InitialContext iniCtx = new InitialContext(); + SecurityDomain sd = (SecurityDomain) iniCtx.lookup("java:/jaas/other"); + ssf = new DomainServerSocketFactory(sd); + } + catch(Exception e) + { + log.error("Failed to create default ServerSocketFactory", e); + } + return ssf; + } + + public String[] getDefaultCipherSuites() + { + String[] cipherSuites = {}; + try + { + initSSLContext(); + SSLServerSocketFactory factory = (SSLServerSocketFactory) sslCtx.getServerSocketFactory(); + cipherSuites = factory.getDefaultCipherSuites(); + } + catch(IOException e) + { + log.error("Failed to get default SSLServerSocketFactory", e); + } + return cipherSuites; + } + + public String[] getSupportedCipherSuites() + { + String[] cipherSuites = {}; + try + { + initSSLContext(); + SSLServerSocketFactory factory = (SSLServerSocketFactory) sslCtx.getServerSocketFactory(); + cipherSuites = factory.getSupportedCipherSuites(); + } + catch(IOException e) + { + log.error("Failed to get default SSLServerSocketFactory", e); + } + return cipherSuites; + } + +// --- End SSLServerSocketFactory interface methods + + private void initSSLContext() + throws IOException + { + if( sslCtx != null ) + return; try { @@ -131,31 +196,5 @@ log.error("Failed to init SSLContext", e); throw new IOException("Failed to init SSLContext"); } - - ServerSocketFactory factory = sslCtx.getServerSocketFactory(); - ServerSocket socket = factory.createServerSocket(port, backlog, ifAddress); - return socket; } - - /** The default ServerSocketFactory which looks to the java:/jaas/other - security domain configuration. - */ - public static ServerSocketFactory getDefault() - { - DomainServerSocketFactory ssf = null; - try - { - InitialContext iniCtx = new InitialContext(); - SecurityDomain sd = (SecurityDomain) iniCtx.lookup("java:/jaas/other"); - ssf = new DomainServerSocketFactory(sd); - } - catch(Exception e) - { - log.error("Failed to create default ServerSocketFactory", e); - } - return ssf; - } - -// --- End ServerSocketFactory interface methods - } |