Search in sources :

Example 21 with LdapNetworkConnection

use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.

the class AbstractLdapTest method assertNoLdapGroup.

protected void assertNoLdapGroup(String cn) throws LdapException, IOException, CursorException {
    LdapNetworkConnection connection = ldapConnect();
    List<Entry> entries = ldapSearch(connection, "(&(cn=" + cn + ")(objectClass=" + getLdapGroupObjectClass() + "))");
    ldapDisconnect(connection);
    assertEquals("Unexpected LDAP group " + cn + ": " + entries, 0, entries.size());
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection)

Example 22 with LdapNetworkConnection

use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.

the class AbstractLdapTest method addLdapAccount.

protected Entry addLdapAccount(String uid, String cn, String givenName, String sn) throws LdapException, IOException, CursorException {
    LdapNetworkConnection connection = ldapConnect();
    Entry entry = createAccountEntry(uid, cn, givenName, sn);
    try {
        connection.add(entry);
        display("Added LDAP account:\n" + entry);
    } catch (Exception e) {
        display("Error adding entry:\n" + entry + "\nError: " + e.getMessage());
        ldapDisconnect(connection);
        throw e;
    }
    ldapDisconnect(connection);
    return entry;
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) CursorLdapReferralException(org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) CertificateException(java.security.cert.CertificateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 23 with LdapNetworkConnection

use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.

the class TestOpenLdap method test702LockOutBarbossa.

@Test
public void test702LockOutBarbossa() throws Exception {
    final String TEST_NAME = "test702LockOutBarbossa";
    TestUtil.displayTestTile(this, TEST_NAME);
    Entry entry = getLdapAccountByUid(USER_BARBOSSA_USERNAME);
    display("LDAP Entry before", entry);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    for (int i = 0; i < 10; i++) {
        LdapNetworkConnection conn;
        try {
            conn = ldapConnect(null, entry.getDn().toString(), "this password is wrong");
        } catch (SecurityException e) {
            // Good bad attempt
            continue;
        }
        assertNotReached();
    }
    // THEN
    TestUtil.displayThen(TEST_NAME);
    entry = assertLdapAccount(USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME);
    display("LDAP Entry after", entry);
    PrismObject<ShadowType> shadow = getShadowModel(accountBarbossaOid);
    display("Shadow (model)", shadow);
    ActivationType activation = shadow.asObjectable().getActivation();
    assertNotNull("No activation", activation);
    LockoutStatusType lockoutStatus = shadow.asObjectable().getActivation().getLockoutStatus();
    assertEquals("Wrong lockout status", LockoutStatusType.LOCKED, lockoutStatus);
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) LockoutStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 24 with LdapNetworkConnection

use of org.apache.directory.ldap.client.api.LdapNetworkConnection in project midpoint by Evolveum.

the class AbstractLdapSynchronizationTest method test837RenameAccount.

@Test
public void test837RenameAccount() throws Exception {
    final String TEST_NAME = "test837RenameAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(this.getClass().getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    long tsStart = System.currentTimeMillis();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    LdapNetworkConnection connection = ldapConnect();
    ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
    modDnRequest.setName(new Dn(toAccountDn(ACCOUNT_HT_UID, ACCOUNT_HT_CN)));
    modDnRequest.setNewRdn(toAccountRdn(ACCOUNT_HTM_UID, ACCOUNT_HTM_CN));
    modDnRequest.setDeleteOldRdn(true);
    ModifyDnResponse modDnResponse = connection.modifyDn(modDnRequest);
    display("Modified " + toAccountDn(ACCOUNT_HT_UID, ACCOUNT_HT_CN) + " -> " + toAccountRdn(ACCOUNT_HTM_UID, ACCOUNT_HTM_CN) + ": " + modDnResponse);
    doAdditionalRenameModifications(connection);
    ldapDisconnect(connection);
    waitForTaskNextRunAssertSuccess(getSyncTaskOid(), true);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    long tsEnd = System.currentTimeMillis();
    PrismObject<UserType> user = findUserByUsername(ACCOUNT_HTM_UID);
    assertNotNull("No user " + ACCOUNT_HTM_UID + " created", user);
    assertUser(user, user.getOid(), ACCOUNT_HTM_UID, getAccountHtmCnAfterRename(), ACCOUNT_HT_GIVENNAME, ACCOUNT_HT_SN_MODIFIED);
    assertNull("User " + ACCOUNT_HT_UID + " still exist", findUserByUsername(ACCOUNT_HT_UID));
    assertStepSyncToken(getSyncTaskOid(), 9, tsStart, tsEnd);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapNetworkConnection(org.apache.directory.ldap.client.api.LdapNetworkConnection) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) ModifyDnResponse(org.apache.directory.api.ldap.model.message.ModifyDnResponse) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ModifyDnRequestImpl(org.apache.directory.api.ldap.model.message.ModifyDnRequestImpl) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)24 Entry (org.apache.directory.api.ldap.model.entry.Entry)11 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)10 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)8 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 Test (org.testng.annotations.Test)5 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)4 IOException (java.io.IOException)4 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)4 Dn (org.apache.directory.api.ldap.model.name.Dn)3 LdapConnectionConfig (org.apache.directory.ldap.client.api.LdapConnectionConfig)3 ApiOperation (io.swagger.annotations.ApiOperation)2 URI (java.net.URI)2 BadRequestException (javax.ws.rs.BadRequestException)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2