1 17 18 package org.apache.avalon.cornerstone.blocks.sockets; 19 20 import java.io.IOException ; 21 import java.net.InetAddress ; 22 import java.net.ServerSocket ; 23 import javax.net.ssl.SSLServerSocket; 24 import javax.net.ssl.SSLServerSocketFactory; 25 import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory; 26 import org.apache.avalon.framework.configuration.Configuration; 27 import org.apache.avalon.framework.configuration.ConfigurationException; 28 29 56 public class TLSServerSocketFactory 57 extends AbstractTLSSocketFactory 58 implements ServerSocketFactory 59 { 60 private SSLServerSocketFactory m_factory; 61 protected boolean m_keyStoreAuthenticateClients; 62 63 69 public void configure( final Configuration configuration ) 70 throws ConfigurationException 71 { 72 super.configure( configuration ); 73 m_keyStoreAuthenticateClients = 74 configuration.getChild( "authenticate-client" ).getValueAsBoolean( false ); 75 } 76 77 protected void visitBuilder( SSLFactoryBuilder builder ) 78 { 79 m_factory = builder.buildServerSocketFactory(); 80 } 81 82 89 public ServerSocket createServerSocket( final int port ) 90 throws IOException 91 { 92 final ServerSocket serverSocket = m_factory.createServerSocket( port ); 93 initServerSocket( serverSocket ); 94 return serverSocket; 95 } 96 97 105 public ServerSocket createServerSocket( int port, int backLog ) 106 throws IOException 107 { 108 final ServerSocket serverSocket = m_factory.createServerSocket( port, backLog ); 109 initServerSocket( serverSocket ); 110 return serverSocket; 111 } 112 113 123 public ServerSocket createServerSocket( int port, int backLog, InetAddress bindAddress ) 124 throws IOException 125 { 126 final ServerSocket serverSocket = 127 m_factory.createServerSocket( port, backLog, bindAddress ); 128 initServerSocket( serverSocket ); 129 return serverSocket; 130 } 131 132 protected void initServerSocket( final ServerSocket serverSocket ) 133 throws IOException 134 { 135 final SSLServerSocket socket = (SSLServerSocket)serverSocket; 136 137 socket.setNeedClientAuth( m_keyStoreAuthenticateClients ); 139 socket.setSoTimeout( m_socketTimeOut ); 141 } 142 } 143 144 | Popular Tags |