if ( createKdcServer == null )
{
return null;
}
KdcServer kdcServer = new KdcServer();
kdcServer.setServiceName( createKdcServer.name() );
kdcServer.setKdcPrincipal( createKdcServer.kdcPrincipal() );
kdcServer.setPrimaryRealm( createKdcServer.primaryRealm() );
kdcServer.setMaximumTicketLifetime( createKdcServer.maxTicketLifetime() );
kdcServer.setMaximumRenewableLifetime( createKdcServer.maxRenewableLifetime() );
CreateTransport[] transportBuilders = createKdcServer.transports();
if ( transportBuilders == null )
{
// create only UDP transport if none specified
UdpTransport defaultTransport = new UdpTransport( AvailablePortFinder.getNextAvailable( startPort ) );
kdcServer.addTransports( defaultTransport );
}
else if ( transportBuilders.length > 0 )
{
for ( CreateTransport transportBuilder : transportBuilders )
{
String protocol = transportBuilder.protocol();
int port = transportBuilder.port();
int nbThreads = transportBuilder.nbThreads();
int backlog = transportBuilder.backlog();
String address = transportBuilder.address();
if ( port == -1 )
{
port = AvailablePortFinder.getNextAvailable( startPort );
startPort = port + 1;
}
if ( protocol.equalsIgnoreCase( "TCP" ) )
{
Transport tcp = new TcpTransport( address, port, nbThreads, backlog );
kdcServer.addTransports( tcp );
}
else if ( protocol.equalsIgnoreCase( "UDP" ) )
{
UdpTransport udp = new UdpTransport( address, port );
kdcServer.addTransports( udp );
}
else
{
throw new IllegalArgumentException( I18n.err( I18n.ERR_689, protocol ) );
}
}
}
kdcServer.setDirectoryService( directoryService );
// Launch the server
try
{
kdcServer.start();
}
catch ( Exception e )
{
e.printStackTrace();
}