Search in sources :

Example 1 with LdapDomain

use of org.platformlayer.service.openldap.model.LdapDomain in project platformlayer by platformlayer.

the class OpenLdapTestHelpers method createLdapDomain.

public LdapDomain createLdapDomain(LdapService ldapService, String organizationName) throws OpsException, IOException {
    String domainId = "domain-" + ldapService.getId();
    Secret adminPassword = randomSecret();
    LdapDomain domain = new LdapDomain();
    domain.organizationName = organizationName;
    domain.adminPassword = adminPassword;
    domain = context.putItem(domainId, domain);
    domain = context.waitForHealthy(domain);
    return domain;
}
Also used : Secret(org.platformlayer.core.model.Secret) LdapDomain(org.platformlayer.service.openldap.model.LdapDomain)

Example 2 with LdapDomain

use of org.platformlayer.service.openldap.model.LdapDomain 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);
}
Also used : HdbDatabaseEntry(org.platformlayer.service.openldap.ops.ldap.HdbDatabaseEntry) OrganizationLdapEntry(org.platformlayer.service.openldap.ops.ldap.OrganizationLdapEntry) LdapDomain(org.platformlayer.service.openldap.model.LdapDomain) OrganizationalUnitLdapEntry(org.platformlayer.service.openldap.ops.ldap.OrganizationalUnitLdapEntry) ManagedFilesystemItem(org.platformlayer.ops.filesystem.ManagedFilesystemItem) File(java.io.File) OrganizationalRoleLdapEntry(org.platformlayer.service.openldap.ops.ldap.OrganizationalRoleLdapEntry) LdapDN(org.platformlayer.ops.ldap.LdapDN)

Example 3 with LdapDomain

use of org.platformlayer.service.openldap.model.LdapDomain 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;
}
Also used : LdapDomain(org.platformlayer.service.openldap.model.LdapDomain) GitService(org.platformlayer.service.git.model.GitService) LdapDN(org.platformlayer.ops.ldap.LdapDN)

Example 4 with LdapDomain

use of org.platformlayer.service.openldap.model.LdapDomain in project platformlayer by platformlayer.

the class OpenLdapProvider method beforeCreateItem.

@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
    super.beforeCreateItem(item);
    // TODO: This doesn't feel like the right place for this
    if (item instanceof LdapService) {
        LdapService ldapService = (LdapService) item;
        Passwords passwords = new Passwords();
        if (Secret.isNullOrEmpty(ldapService.ldapServerPassword)) {
            ldapService.ldapServerPassword = passwords.generateRandomPassword(12);
        }
    }
    if (item instanceof LdapDomain) {
        LdapDomain ldapService = (LdapDomain) item;
        Passwords passwords = new Passwords();
        if (Secret.isNullOrEmpty(ldapService.adminPassword)) {
            ldapService.adminPassword = passwords.generateRandomPassword(12);
        }
    }
}
Also used : LdapDomain(org.platformlayer.service.openldap.model.LdapDomain) Passwords(org.platformlayer.ops.crypto.Passwords) LdapService(org.platformlayer.service.openldap.model.LdapService)

Example 5 with LdapDomain

use of org.platformlayer.service.openldap.model.LdapDomain in project platformlayer by platformlayer.

the class ITOpenLdapService method testCreateAndDeleteItem.

@Test
public void testCreateAndDeleteItem() throws Exception {
    OpenLdapTestHelpers openLdap = new OpenLdapTestHelpers(getContext());
    LdapService ldapService = openLdap.createLdapServer();
    InetSocketAddress socketAddress = getUniqueEndpoint(ldapService);
    Assert.assertFalse(isPortOpen(socketAddress));
    openFirewall(ldapService, LdapServiceController.PORT);
    Assert.assertTrue(isPortOpen(socketAddress));
    String organizationName = "test.platformlayer.org";
    LdapDomain ldapDomain = openLdap.createLdapDomain(ldapService, organizationName);
    // TODO: Make endpoint ldap://<ip>:<port>/ ???
    String ldapUrl = "ldap://" + socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort() + "/";
    testLdap(ldapUrl, ldapDomain.adminPassword);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) LdapDomain(org.platformlayer.service.openldap.model.LdapDomain) OpenLdapTestHelpers(org.platformlayer.service.openldap.tests.OpenLdapTestHelpers) LdapService(org.platformlayer.service.openldap.model.LdapService) Test(org.testng.annotations.Test) PlatformLayerApiTest(org.platformlayer.tests.PlatformLayerApiTest)

Aggregations

LdapDomain (org.platformlayer.service.openldap.model.LdapDomain)7 LdapService (org.platformlayer.service.openldap.model.LdapService)4 LdapDN (org.platformlayer.ops.ldap.LdapDN)3 InetSocketAddress (java.net.InetSocketAddress)2 GitService (org.platformlayer.service.git.model.GitService)2 OpenLdapTestHelpers (org.platformlayer.service.openldap.tests.OpenLdapTestHelpers)2 PlatformLayerApiTest (org.platformlayer.tests.PlatformLayerApiTest)2 Test (org.testng.annotations.Test)2 File (java.io.File)1 EndpointInfo (org.platformlayer.core.model.EndpointInfo)1 Secret (org.platformlayer.core.model.Secret)1 OpsException (org.platformlayer.ops.OpsException)1 Passwords (org.platformlayer.ops.crypto.Passwords)1 ManagedFilesystemItem (org.platformlayer.ops.filesystem.ManagedFilesystemItem)1 PublicEndpoint (org.platformlayer.ops.networks.PublicEndpoint)1 GitRepository (org.platformlayer.service.git.model.GitRepository)1 HdbDatabaseEntry (org.platformlayer.service.openldap.ops.ldap.HdbDatabaseEntry)1 OrganizationLdapEntry (org.platformlayer.service.openldap.ops.ldap.OrganizationLdapEntry)1 OrganizationalRoleLdapEntry (org.platformlayer.service.openldap.ops.ldap.OrganizationalRoleLdapEntry)1 OrganizationalUnitLdapEntry (org.platformlayer.service.openldap.ops.ldap.OrganizationalUnitLdapEntry)1