DirContext ctx = null;
try {
if (!(ldapServer instanceof ApacheLDAPServer)) {
throw new DirectoryServerException("Apache KDC server is only compatible with " +
"ApacheLDAPServer");
}
ApacheLDAPServer apacheLDAP = (ApacheLDAPServer)ldapServer;
// Get a context, create the ou=users subcontext, then create the 3 principals.
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(DirectoryService.JNDI_KEY, apacheLDAP.getService());
env.put(Context.INITIAL_CONTEXT_FACTORY,
ConfigurationConstants.LDAP_INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, ConfigurationConstants.USER_SUB_CONTEXT + "," +
partitionInfo.getRootDN());
env.put(Context.SECURITY_PRINCIPAL, partitionInfo.getAdminDomainName());
env.put(Context.SECURITY_CREDENTIALS,
partitionInfo.getPartitionAdministrator().getAdminPassword());
env.put(Context.SECURITY_AUTHENTICATION, ConfigurationConstants.SIMPLE_AUTHENTICATION);
ctx = new InitialDirContext(env);
// Set KDC principle for this partition
Attributes attrs = getPrincipalAttributes(ConfigurationConstants.SERVER_PRINCIPLE,
ConfigurationConstants.KDC_SERVER_COMMON_NAME,
ConfigurationConstants.KDC_SERVER_UID,
partitionInfo.getPartitionKdcPassword(),
getKDCPrincipleName(partitionInfo));
ctx.createSubcontext("uid=" + ConfigurationConstants.KDC_SERVER_UID, attrs);
// Set LDAP principle for this partition
attrs = getPrincipalAttributes(ConfigurationConstants.SERVER_PRINCIPLE,
ConfigurationConstants.LDAP_SERVER_COMMON_NAME,
ConfigurationConstants.LDAP_SERVER_UID,
partitionInfo.getLdapServerPrinciplePassword(),
getLDAPPrincipleName(partitionInfo));
ctx.createSubcontext("uid=" + ConfigurationConstants.LDAP_SERVER_UID, attrs);
} catch (NamingException e) {
String msg = "Unable to add server principles for KDC and LDAP. " +
"Incorrect domain names.";
logger.error(msg, e);
throw new DirectoryServerException(msg, e);
} finally {
if (ctx != null) {
try {
ctx.close();