use of org.platformlayer.ops.ldap.LdapDN in project platformlayer by platformlayer.
the class GitServerController method getLdapDomain.
LdapDomain getLdapDomain() throws OpsException {
if (ldapDomain == null) {
GitService model = OpsContext.get().getInstance(GitService.class);
LdapDN ldapGroup = LdapDN.parseLdifEncoded(model.ldapGroup);
LdapDomain best = null;
for (LdapDomain candidate : platformLayer.listItems(LdapDomain.class)) {
switch(candidate.getState()) {
case DELETE_REQUESTED:
case DELETED:
continue;
}
LdapDN organizationName = LdapDN.fromDomainName(candidate.organizationName);
if (!organizationName.isParentOf(ldapGroup)) {
log.info("LdapDomain does not match: " + organizationName + " vs " + ldapGroup);
continue;
}
log.info("Found matching LdapDomain: " + organizationName + " vs " + ldapGroup);
if (best == null) {
best = candidate;
continue;
}
throw new UnsupportedOperationException("Selecting between matching LDAP domains not yet implemented");
}
if (best == null) {
throw new IllegalStateException("Cannot find LDAP domain: " + model.ldapGroup);
}
ldapDomain = best;
}
return ldapDomain;
}
use of org.platformlayer.ops.ldap.LdapDN in project platformlayer by platformlayer.
the class LdapEntry method queryCurrentRecord.
protected LdifRecord queryCurrentRecord(OpsTarget target) throws OpsException {
LdapService ldapService = OpsContext.get().getInstance(LdapService.class);
String ldapPassword = ldapService.ldapServerPassword.plaintext();
String filter = null;
LdapDN searchBaseDN = getLdapDN();
return OpenLdapManager.doLdapQuerySingle(target, OpenLdapServer.ADMIN_DN, ldapPassword, searchBaseDN, filter);
}
use of org.platformlayer.ops.ldap.LdapDN in project platformlayer by platformlayer.
the class LdifRecord method parse.
public static List<LdifRecord> parse(String ldif) {
// ldapsearch wraps at 78 chars, we unwrap this using the replacement below
ldif = ldif.replace("\n ", "");
List<LdifRecord> records = Lists.newArrayList();
LdifRecord current = null;
int lineNumber = 0;
for (String line : ldif.split("\n")) {
String trimmed = line.trim();
if (trimmed.length() == 0) {
continue;
}
if (trimmed.startsWith("#")) {
continue;
}
lineNumber++;
int delimIndex = trimmed.indexOf(':');
if (delimIndex == -1) {
log.warn("Line did not contain delimiter: " + line);
}
String key = trimmed.substring(0, delimIndex);
String value = trimmed.substring(delimIndex + 1);
key = key.trim();
value = value.trim();
if (key.equals("version")) {
if (lineNumber != 1) {
throw new IllegalArgumentException("Unexpected version attribute in " + ldif);
}
// Ignore
continue;
}
if (key.equals("dn")) {
LdapDN ldapDN = LdapDN.parseLdifEncoded(value);
current = new LdifRecord(ldapDN);
records.add(current);
continue;
}
if (key.equals("objectClass")) {
current.getObjectClasses().add(value);
continue;
}
current.getProperties().put(key, value);
}
return records;
}
use of org.platformlayer.ops.ldap.LdapDN in project platformlayer by platformlayer.
the class LdapSchemaEntry method build.
public static LdapSchemaEntry build(String schemaName) {
LdapSchemaEntry ldapSchemaEntry = OpsContext.get().getOpsSystem().getInjector().getInstance(LdapSchemaEntry.class);
LdapDN ldapDN = OpenLdapServer.CONFIG_DN.childDN(LdapAttributes.LDAP_ATTRIBUTE_CN, schemaName);
ldapSchemaEntry.setLdapDN(ldapDN);
ldapSchemaEntry.setSchemaFile(schemaName + ".schema");
ldapSchemaEntry.setOnlyConfigureOnForce(true);
return ldapSchemaEntry;
}
use of org.platformlayer.ops.ldap.LdapDN in project platformlayer by platformlayer.
the class LdapDomainController method addChildren.
@Override
protected void addChildren() throws OpsException {
LdapDomain ldapDomain = OpsContext.get().getInstance(LdapDomain.class);
String hostName = ldapDomain.organizationName;
LdapDN ldapBase = LdapServerUtilities.createBaseDN(hostName);
File dataRoot = new File("/var/ldap/data");
File dataDir = new File(dataRoot, hostName);
String ldapBaseOrganization = hostName;
ManagedFilesystemItem directory = ManagedDirectory.build(dataDir, "0700").setGroup("openldap").setOwner("openldap");
addChild(directory);
HdbDatabaseEntry db = buildDatabase(ldapBase, dataDir, hostName);
addChild(db);
OrganizationLdapEntry organization = buildOrganization(ldapBase, ldapBaseOrganization);
organization.setTop(true);
addChild(organization);
String ldapAdminPassword = LdapPasswords.getLdapPasswordEncoded(ldapDomain.adminPassword.plaintext());
OrganizationalRoleLdapEntry organizationalRole = buildOrganizationalRole(ldapBase, LdapAttributes.MANAGER_CN, "LDAP Administrator", ldapAdminPassword);
addChild(organizationalRole);
OrganizationalUnitLdapEntry users = buildOrganizationUnit(ldapBase, LdapAttributes.LDAP_USERS_CONTAINER_OU, "Users");
addChild(users);
OrganizationalUnitLdapEntry groups = buildOrganizationUnit(ldapBase, LdapAttributes.LDAP_GROUPS_CONTAINER_OU, "Groups");
addChild(groups);
}
Aggregations