package org.jboss.iiop.jacorb;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import javax.net.ssl.SSLServerSocket;
import org.jboss.iiop.CorbaORBService;
import org.jboss.logging.Logger;
import org.jboss.security.SecurityDomain;
import org.jboss.security.ssl.DomainServerSocketFactory;
import org.jboss.system.Registry;
public class SSLServerSocketFactory
implements org.jacorb.orb.factory.SSLServerSocketFactory,
org.apache.avalon.framework.configuration.Configurable
{
private static Logger log = Logger.getLogger(SSLServerSocketFactory.class);
private DomainServerSocketFactory domainFactory = null;
private boolean require_mutual_auth = false;
private boolean request_mutual_auth = false;
public SSLServerSocketFactory(org.jacorb.orb.ORB orb)
throws IOException
{
log.info("Creating");
SecurityDomain securityDomain =
(SecurityDomain)Registry.lookup(CorbaORBService.SSL_DOMAIN);
try
{
domainFactory = new DomainServerSocketFactory(securityDomain);
}
catch (IOException e)
{
log.warn("Could not create DomainServerSocketFactory: " + e);
if (log.isDebugEnabled())
log.debug("Exception creating DomainServerSockedFactory: ", e);
throw e;
}
short serverSupportedOptions = Short.parseShort(
orb.getConfiguration().getAttribute(
"jacorb.security.ssl.server.supported_options","20"),
16); short serverRequiredOptions = Short.parseShort(
orb.getConfiguration().getAttribute(
"jacorb.security.ssl.server.required_options","0"),
16);
if ((serverSupportedOptions & 0x40) != 0)
{
request_mutual_auth = true;
}
if ((serverRequiredOptions & 0x40) != 0)
{
require_mutual_auth = true;
request_mutual_auth = false;
}
if (request_mutual_auth)
log.info("Will create SSL sockets that support client authentication");
else if (require_mutual_auth)
log.info("Will create SSL sockets that require client authentication");
log.info("Created");
}
public ServerSocket createServerSocket(int port)
throws IOException
{
SSLServerSocket s =
(SSLServerSocket)domainFactory.createServerSocket(port);
if (request_mutual_auth)
s.setWantClientAuth(request_mutual_auth);
else if (require_mutual_auth)
s.setNeedClientAuth(require_mutual_auth);
return s;
}
public ServerSocket createServerSocket(int port, int backlog)
throws IOException
{
SSLServerSocket s =
(SSLServerSocket)domainFactory.createServerSocket(port, backlog);
if (request_mutual_auth)
s.setWantClientAuth(request_mutual_auth);
else if (require_mutual_auth)
s.setNeedClientAuth(require_mutual_auth);
return s;
}
public ServerSocket createServerSocket(int port,
int backlog,
InetAddress ifAddress)
throws IOException
{
SSLServerSocket s =
(SSLServerSocket)domainFactory.createServerSocket(port,
backlog, ifAddress);
if (request_mutual_auth)
s.setWantClientAuth(request_mutual_auth);
else if (require_mutual_auth)
s.setNeedClientAuth(require_mutual_auth);
return s;
}
public boolean isSSL(java.net.ServerSocket s)
{
return (s instanceof SSLServerSocket);
}
public void switchToClientMode(java.net.Socket socket)
{
}
public void configure(
org.apache.avalon.framework.configuration.Configuration configuration)
throws org.apache.avalon.framework.configuration.ConfigurationException
{
}
}