use of org.apache.directory.server.kerberos.kdc.KdcServer in project undertow by undertow-io.
the class KerberosKDCUtil method startKDC.
private static void startKDC() throws Exception {
kdcServer = new KdcServer();
kdcServer.setServiceName("Test KDC");
kdcServer.setSearchBaseDn("ou=users,dc=undertow,dc=io");
KerberosConfig config = kdcServer.getConfig();
config.setServicePrincipal("krbtgt/UNDERTOW.IO@UNDERTOW.IO");
config.setPrimaryRealm("UNDERTOW.IO");
config.setPaEncTimestampRequired(false);
UdpTransport udp = new UdpTransport("0.0.0.0", KDC_PORT);
kdcServer.addTransports(udp);
kdcServer.setDirectoryService(directoryService);
kdcServer.start();
}
use of org.apache.directory.server.kerberos.kdc.KdcServer in project wildfly by wildfly.
the class NoReplayKdcServer method createKdcServer.
// Private methods -------------------------------------------------------
/**
* Creates and starts {@link KdcServer} instance based on given configuration.
*
* @param createKdcServer
* @param directoryService
* @param startPort
* @return
*/
private static KdcServer createKdcServer(CreateKdcServer createKdcServer, DirectoryService directoryService, int startPort, String bindAddress) {
if (createKdcServer == null) {
return null;
}
KerberosConfig kdcConfig = new KerberosConfig();
kdcConfig.setServicePrincipal(createKdcServer.kdcPrincipal());
kdcConfig.setPrimaryRealm(createKdcServer.primaryRealm());
kdcConfig.setMaximumTicketLifetime(createKdcServer.maxTicketLifetime());
kdcConfig.setMaximumRenewableLifetime(createKdcServer.maxRenewableLifetime());
kdcConfig.setPaEncTimestampRequired(false);
KdcServer kdcServer = new NoReplayKdcServer(kdcConfig);
kdcServer.setSearchBaseDn(createKdcServer.searchBaseDn());
CreateTransport[] transportBuilders = createKdcServer.transports();
if (transportBuilders == null) {
// create only UDP transport if none specified
UdpTransport defaultTransport = new UdpTransport(bindAddress, 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();
final String address = bindAddress != null ? bindAddress : 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));
}
}
}
CreateChngPwdServer[] createChngPwdServers = createKdcServer.chngPwdServer();
if (createChngPwdServers.length > 0) {
CreateChngPwdServer createChngPwdServer = createChngPwdServers[0];
ChangePasswordConfig config = new ChangePasswordConfig(kdcConfig);
config.setServicePrincipal(createChngPwdServer.srvPrincipal());
ChangePasswordServer chngPwdServer = new ChangePasswordServer(config);
for (CreateTransport transportBuilder : createChngPwdServer.transports()) {
Transport t = createTransport(transportBuilder, startPort);
startPort = t.getPort() + 1;
chngPwdServer.addTransports(t);
}
chngPwdServer.setDirectoryService(directoryService);
kdcServer.setChangePwdServer(chngPwdServer);
}
kdcServer.setDirectoryService(directoryService);
// Launch the server
try {
kdcServer.start();
} catch (Exception e) {
e.printStackTrace();
}
return kdcServer;
}
use of org.apache.directory.server.kerberos.kdc.KdcServer in project sonarqube by SonarSource.
the class ApacheDS method startKdcServer.
private ApacheDS startKdcServer() throws IOException, LdapOperationException {
int port = AvailablePortFinder.getNextAvailable(6088);
KerberosConfig kdcConfig = new KerberosConfig();
kdcConfig.setServicePrincipal("krbtgt/EXAMPLE.ORG@EXAMPLE.ORG");
kdcConfig.setPrimaryRealm("EXAMPLE.ORG");
kdcConfig.setPaEncTimestampRequired(false);
kdcServer = new KdcServer(kdcConfig);
kdcServer.setSearchBaseDn("dc=example,dc=org");
kdcServer.addTransports(new UdpTransport("localhost", port));
kdcServer.setDirectoryService(directoryService);
kdcServer.start();
FileUtils.writeStringToFile(new File("target/krb5.conf"), "" + "[libdefaults]\n" + " default_realm = EXAMPLE.ORG\n" + "\n" + "[realms]\n" + " EXAMPLE.ORG = {\n" + " kdc = localhost:" + port + "\n" + " }\n" + "\n" + "[domain_realm]\n" + " .example.org = EXAMPLE.ORG\n" + " example.org = EXAMPLE.ORG\n", StandardCharsets.UTF_8.name());
return this;
}
use of org.apache.directory.server.kerberos.kdc.KdcServer in project qpid-broker-j by apache.
the class SimpleLDAPAuthenticationManagerTest method setUpKerberos.
private void setUpKerberos() throws Exception {
final LdapServer ldapServer = LDAP.getLdapServer();
final KdcServer kdcServer = ServerAnnotationProcessor.getKdcServer(LDAP.getDirectoryService(), ldapServer.getPort() + 1);
kdcServer.getConfig().setPaEncTimestampRequired(false);
final int port = kdcServer.getTransports()[0].getPort();
final String krb5confPath = createKrb5Conf(port);
SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.conf", krb5confPath);
SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.realm", null);
SYSTEM_PROPERTY_SETTER.setSystemProperty("java.security.krb5.kdc", null);
final KerberosPrincipal servicePrincipal = new KerberosPrincipal(LDAP_SERVICE_NAME + "/" + HOSTNAME + "@" + REALM, KerberosPrincipal.KRB_NT_SRV_HST);
final String servicePrincipalName = servicePrincipal.getName();
ldapServer.setSaslHost(servicePrincipalName.substring(servicePrincipalName.indexOf("/") + 1, servicePrincipalName.indexOf("@")));
ldapServer.setSaslPrincipal(servicePrincipalName);
ldapServer.setSearchBaseDn(USERS_DN);
createPrincipal("KDC", "KDC", "krbtgt", UUID.randomUUID().toString(), "krbtgt/" + REALM + "@" + REALM);
createPrincipal("Service", "LDAP Service", "ldap", UUID.randomUUID().toString(), servicePrincipalName);
}
use of org.apache.directory.server.kerberos.kdc.KdcServer in project sonarqube by SonarSource.
the class ApacheDS method startKdcServer.
private ApacheDS startKdcServer() throws IOException, LdapOperationException {
int port = AvailablePortFinder.getNextAvailable(6088);
KerberosConfig kdcConfig = new KerberosConfig();
kdcConfig.setServicePrincipal("krbtgt/EXAMPLE.ORG@EXAMPLE.ORG");
kdcConfig.setPrimaryRealm("EXAMPLE.ORG");
kdcConfig.setPaEncTimestampRequired(false);
kdcServer = new KdcServer(kdcConfig);
kdcServer.setSearchBaseDn("dc=example,dc=org");
kdcServer.addTransports(new UdpTransport("localhost", port));
kdcServer.setDirectoryService(directoryService);
kdcServer.start();
FileUtils.writeStringToFile(new File("target/krb5.conf"), "" + "[libdefaults]\n" + " default_realm = EXAMPLE.ORG\n" + "\n" + "[realms]\n" + " EXAMPLE.ORG = {\n" + " kdc = localhost:" + port + "\n" + " }\n" + "\n" + "[domain_realm]\n" + " .example.org = EXAMPLE.ORG\n" + " example.org = EXAMPLE.ORG\n", StandardCharsets.UTF_8.name());
return this;
}
Aggregations