Search in sources :

Example 6 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class OpenLDAPEntries method readPasswordPolicy.

static OpenLDAPPasswordPolicy readPasswordPolicy(final OpenLDAPUser person) throws ChaiUnavailableException, ChaiOperationException {
    ChaiEntry searchEntry = new OpenLDAPEntry(person.getEntryDN(), person.getChaiProvider());
    OpenLDAPEntry discoveredPolicy = null;
    int safetyCounter = 0;
    while (safetyCounter < 50 && searchEntry != null && discoveredPolicy == null) {
        safetyCounter++;
        if (searchEntry.exists()) {
            final String pwdPolicySubentryValue = searchEntry.readStringAttribute(ChaiConstant.ATTR_OPENLDAP_PASSWORD_SUB_ENTRY);
            LOGGER.trace("pwdPolicySubentryValue = " + pwdPolicySubentryValue);
            if (pwdPolicySubentryValue != null && !pwdPolicySubentryValue.isEmpty()) {
                final OpenLDAPEntry policyEntry = new OpenLDAPEntry(pwdPolicySubentryValue, person.getChaiProvider());
                if (policyEntry.exists()) {
                    discoveredPolicy = policyEntry;
                }
            }
        }
        searchEntry = searchEntry.getParentEntry();
    }
    if (discoveredPolicy != null) {
        return new OpenLDAPPasswordPolicy(discoveredPolicy.getEntryDN(), person.getChaiProvider());
    }
    final String passwordPolicyDn = person.getChaiProvider().getChaiConfiguration().getSetting(ChaiSetting.OPENLDAP_PASSWORD_POLICY_DN);
    LOGGER.debug("passwordPolicyDn = " + passwordPolicyDn);
    if (passwordPolicyDn != null && passwordPolicyDn.trim().length() > 0) {
        final OpenLDAPPasswordPolicy defaultPolicy = new OpenLDAPPasswordPolicy(passwordPolicyDn, person.getChaiProvider());
        if (defaultPolicy.exists()) {
            return defaultPolicy;
        }
    }
    return null;
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry)

Example 7 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class ChaiUtility method createGroup.

/**
 * Creates a new group entry in the ldap directory.  A new "groupOfNames" object is created.
 * The "cn" and "description" ldap attributes are set to the supplied name.
 *
 * @param parentDN the entryDN of the new group.
 * @param name     name of the group
 * @param provider a ldap provider be used to create the group.
 * @return an instance of the ChaiGroup entry
 * @throws ChaiOperationException   If there is an error during the operation
 * @throws ChaiUnavailableException If the directory server(s) are unavailable
 */
public static ChaiGroup createGroup(final String parentDN, final String name, final ChaiProvider provider) throws ChaiOperationException, ChaiUnavailableException {
    // Get a good CN for it
    final String objectCN = findUniqueName(name, parentDN, provider);
    // Concantonate the entryDN
    final StringBuilder entryDN = new StringBuilder();
    entryDN.append("cn=");
    entryDN.append(objectCN);
    entryDN.append(',');
    entryDN.append(parentDN);
    // First create the base group.
    provider.createEntry(entryDN.toString(), ChaiConstant.OBJECTCLASS_BASE_LDAP_GROUP, Collections.emptyMap());
    // Now build an ldapentry object to add attributes to it
    final ChaiEntry theObject = provider.getEntryFactory().newChaiEntry(entryDN.toString());
    // Add the description
    theObject.writeStringAttribute(ChaiConstant.ATTR_LDAP_DESCRIPTION, name);
    // Return the newly created group.
    return provider.getEntryFactory().newChaiGroup(entryDN.toString());
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry)

Example 8 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class ChaiProviderTester method testDeleteAttribute.

public void testDeleteAttribute() throws Exception {
    final ChaiProvider[] providers = this.getProviders();
    for (final ChaiProvider provider : providers) {
        final ChaiEntry testContainer = TestHelper.createTestContainer();
        final String testUserDN = TestHelper.createNewTestUser(testContainer).getEntryDN();
        System.out.println("Testing provider " + provider.toString());
        {
            // test single value writes.
            provider.writeStringAttribute(testUserDN, testAttribute, new HashSet<String>(Arrays.asList("value1", "value2")), false);
            final Set<String> results = provider.readMultiStringAttribute(testUserDN, testAttribute);
            Assert.assertTrue("setup values failed", results.size() == 2 && results.contains("value1") && results.contains("value2"));
        }
        {
            // delete existing value
            provider.deleteStringAttributeValue(testUserDN, testAttribute, "value2");
            final Set<String> results = provider.readMultiStringAttribute(testUserDN, testAttribute);
            Assert.assertTrue("delete existing value failed", results.size() == 1 && results.contains("value1"));
        }
        {
            // delete non existing value
            try {
                provider.deleteStringAttributeValue(testUserDN, testAttribute, "value2");
                Assert.fail("missing exception during delete of non-existant value");
            } catch (ChaiOperationException e) {
                Assert.assertEquals("missing NO_SUCH_VALUE error", e.getErrorCode(), ChaiError.NO_SUCH_VALUE);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ChaiEntry(com.novell.ldapchai.ChaiEntry) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) HashSet(java.util.HashSet)

Example 9 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class ChaiProviderTester method testWriteStringAttribute.

public void testWriteStringAttribute() throws Exception {
    final ChaiProvider[] providers = this.getProviders();
    for (final ChaiProvider provider : providers) {
        final ChaiEntry testContainer = TestHelper.createTestContainer();
        final String testUserDN = TestHelper.createNewTestUser(testContainer).getEntryDN();
        System.out.println("Testing provider " + provider.toString());
        {
            // test single value writes.
            provider.writeStringAttribute(testUserDN, testAttribute, Collections.singleton("value1"), false);
            final Set<String> results = provider.readMultiStringAttribute(testUserDN, testAttribute);
            Assert.assertTrue("single write failed", results.size() == 1 && results.contains("value1"));
        }
        {
            // append single value writes.
            provider.writeStringAttribute(testUserDN, testAttribute, Collections.singleton("value2"), false);
            final Set<String> results = provider.readMultiStringAttribute(testUserDN, testAttribute);
            Assert.assertTrue("single append failed", results.size() == 2 && results.contains("value1") && results.contains("value2"));
        }
        {
            // overwrite single value writes.
            provider.writeStringAttribute(testUserDN, testAttribute, Collections.singleton("value3"), true);
            final Set<String> results = provider.readMultiStringAttribute(testUserDN, testAttribute);
            Assert.assertTrue("single overwrite failed", results.size() == 1 && results.contains("value3"));
        }
        {
            // append multi value writes.
            provider.writeStringAttribute(testUserDN, testAttribute, new HashSet<String>(Arrays.asList("value4", "value5")), false);
            final Set<String> results = provider.readMultiStringAttribute(testUserDN, testAttribute);
            Assert.assertTrue("multi append failed", results.size() == 3 && results.contains("value3") && results.contains("value4") && results.contains("value5"));
        }
        {
            // overwrite multi value writes.
            provider.writeStringAttribute(testUserDN, testAttribute, new HashSet<String>(Arrays.asList("value6", "value7")), true);
            final Set<String> results = provider.readMultiStringAttribute(testUserDN, testAttribute);
            Assert.assertTrue("multi overwrite failed", results.size() == 2 && results.contains("value6") && results.contains("value7"));
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ChaiEntry(com.novell.ldapchai.ChaiEntry) HashSet(java.util.HashSet)

Example 10 with ChaiEntry

use of com.novell.ldapchai.ChaiEntry in project ldapchai by ldapchai.

the class ChaiTester method testCreateBulk.

public void testCreateBulk() throws Exception {
    final ChaiEntry testContainer = TestHelper.createTestContainer();
    final String userClass = "inetOrgPerson";
    for (int i = 0; i < TestHelper.testBulkIterations; i++) {
        final String dn = "cn=user" + i + "," + testContainer.getEntryDN();
        final Map<String, String> props = new HashMap<String, String>();
        props.put("givenName", "first" + i);
        props.put("sn", "last" + i);
        TestHelper.getProvider().createEntry(dn, userClass, props);
        System.out.println("Created " + dn);
    }
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry)

Aggregations

ChaiEntry (com.novell.ldapchai.ChaiEntry)31 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)12 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)8 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)7 ChaiUser (com.novell.ldapchai.ChaiUser)6 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)3 ChaiException (com.novell.ldapchai.exception.ChaiException)2 ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)2 NmasResponseSet (com.novell.ldapchai.impl.edir.NmasResponseSet)2 TcpProxy (com.novell.ldapchai.tests.util.TcpProxy)2 InetSocketAddress (java.net.InetSocketAddress)2 MalformedURLException (java.net.MalformedURLException)2 UnknownHostException (java.net.UnknownHostException)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2