Search in sources :

Example 6 with InternalSearchOperation

use of org.opends.server.protocols.internal.InternalSearchOperation in project OpenAM by OpenRock.

the class SMSEmbeddedLdapObject method getSubEntries.

private Set<String> getSubEntries(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
    // Get the sub entries
    try {
        SearchRequest request = Requests.newSearchRequest(dn, SearchScope.SINGLE_LEVEL, filter, orgUnitAttr.toArray(new String[orgUnitAttr.size()]));
        InternalSearchOperation iso = icConn.processSearch(request);
        ResultCode resultCode = iso.getResultCode();
        if (resultCode == ResultCode.NO_SUCH_OBJECT) {
            if (debug.messageEnabled()) {
                debug.message("SMSEmbeddedLdapObject.getSubEntries(): " + "entry not present:" + dn);
            }
        } else if (resultCode == ResultCode.SIZE_LIMIT_EXCEEDED) {
            if (debug.messageEnabled()) {
                debug.message("SMSEmbeddedLdapObject.getSubEntries: " + "size limit " + numOfEntries + " exceeded for " + "sub-entries: " + dn);
            }
        } else if (resultCode != ResultCode.SUCCESS) {
            if (debug.warningEnabled()) {
                debug.warning("SMSEmbeddedLdapObject.getSubEntries: " + "Unable to search for " + "sub-entries: " + dn);
            }
            throw new SMSException("", "sms-entry-cannot-search");
        }
        // Construct the results and return
        Set<String> answer = new LinkedHashSet<>();
        LinkedList searchResult = iso.getSearchEntries();
        for (Iterator iter = searchResult.iterator(); iter.hasNext(); ) {
            SearchResultEntry entry = (SearchResultEntry) iter.next();
            String edn = entry.getName().toString();
            if (!edn.toLowerCase().startsWith("ou=")) {
                continue;
            }
            String rdn = entry.getName().getRDN(0).getAttributeValue(0).toString();
            answer.add(rdn);
        }
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject.getSubEntries: " + "Successfully obtained sub-entries for : " + dn);
        }
        return answer;
    } catch (DirectoryException dex) {
        if (debug.warningEnabled()) {
            debug.warning("SMSEmbeddedLdapObject.getSubEntries: " + "Unable to search for " + "sub-entries: " + dn, dex);
        }
        throw new SMSException(dex, "sms-entry-cannot-search");
    }
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) LinkedHashSet(java.util.LinkedHashSet) SearchRequest(org.opends.server.protocols.internal.SearchRequest) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) ResultCode(org.forgerock.opendj.ldap.ResultCode) LinkedList(java.util.LinkedList) DirectoryException(org.opends.server.types.DirectoryException) SearchResultEntry(org.opends.server.types.SearchResultEntry)

Example 7 with InternalSearchOperation

use of org.opends.server.protocols.internal.InternalSearchOperation in project OpenAM by OpenRock.

the class SMSEmbeddedLdapObject method searchSubOrganizationNames.

private Set<String> searchSubOrganizationNames(String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder, boolean recursive) throws SMSException, SSOException {
    SearchScope scope = (recursive) ? SearchScope.WHOLE_SUBTREE : SearchScope.SINGLE_LEVEL;
    InternalSearchOperation iso = searchObjects(dn, filter, scope, numOfEntries, sortResults, ascendingOrder);
    ResultCode resultCode = iso.getResultCode();
    if (resultCode == ResultCode.NO_SUCH_OBJECT) {
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject." + "searchSubOrganizationNames: suborg not present:" + dn);
        }
    } else if (resultCode == ResultCode.SIZE_LIMIT_EXCEEDED) {
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject." + "searchSubOrganizationNames: size limit exceeded. " + "numOfEntries = " + numOfEntries + ", dn = " + dn);
        }
    } else if (resultCode != ResultCode.SUCCESS) {
        if (debug.warningEnabled()) {
            debug.warning("SMSEmbeddedLdapObject." + "searchSubOrganizationNames: Unable to search. dn = " + dn + ", filter = " + filter + ", resultCode = " + resultCode);
        }
        throw new SMSException("", "sms-suborg-cannot-search");
    }
    Set<String> answer = new LinkedHashSet<>();
    for (SearchResultEntry entry : iso.getSearchEntries()) {
        String edn = entry.getName().toString();
        answer.add(edn);
    }
    if (debug.messageEnabled()) {
        debug.message("SMSEmbeddedLdapObject.searchSubOrganizationName: " + "Successfully obtained suborganization names for : " + dn);
        debug.message("SMSEmbeddedLdapObject.searchSubOrganizationName: " + "Successfully obtained suborganization names  : " + answer.toString());
    }
    return answer;
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) LinkedHashSet(java.util.LinkedHashSet) SMSException(com.sun.identity.sm.SMSException) SearchScope(org.forgerock.opendj.ldap.SearchScope) ResultCode(org.forgerock.opendj.ldap.ResultCode) SearchResultEntry(org.opends.server.types.SearchResultEntry)

Example 8 with InternalSearchOperation

use of org.opends.server.protocols.internal.InternalSearchOperation in project OpenAM by OpenRock.

the class SMSEmbeddedLdapObject method searchObjects.

private InternalSearchOperation searchObjects(String startDN, String filter, SearchScope scope, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SSOException, SMSException {
    // sorting is not implemented
    try {
        // Get the sub entries
        SearchRequest request = Requests.newSearchRequest(startDN, scope, filter);
        request.setSizeLimit(numOfEntries);
        InternalSearchOperation iso = icConn.processSearch(request);
        return iso;
    } catch (DirectoryException dex) {
        if (debug.warningEnabled()) {
            debug.warning("SMSEmbeddedLdapObject.searchObjects: " + "Unable to " + "search. startDN = " + startDN + ", filter = " + filter, dex);
        }
        throw new SMSException(dex, "sms-error-in-searching");
    }
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) SearchRequest(org.opends.server.protocols.internal.SearchRequest) SMSException(com.sun.identity.sm.SMSException) DirectoryException(org.opends.server.types.DirectoryException)

Example 9 with InternalSearchOperation

use of org.opends.server.protocols.internal.InternalSearchOperation in project midpoint by Evolveum.

the class TestSanity method test049DeleteUser.

/**
     * The user should have an account now. Let's try to delete the user. The
     * account should be gone as well.
     *
     * @throws JAXBException
     */
@Test
public void test049DeleteUser() throws SchemaException, FaultMessage, DirectoryException, JAXBException {
    TestUtil.displayTestTile("test049DeleteUser");
    // GIVEN
    assertNoRepoCache();
    // WHEN
    OperationResultType result = deleteObjectViaModelWS(ObjectTypes.USER.getTypeQName(), USER_JACK_OID);
    // THEN
    assertNoRepoCache();
    displayJaxb("deleteObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("deleteObject has failed", result);
    // User should be gone from the repository
    OperationResult repoResult = new OperationResult("getObject");
    try {
        repositoryService.getObject(UserType.class, USER_JACK_OID, null, repoResult);
        AssertJUnit.fail("User still exists in repo after delete");
    } catch (ObjectNotFoundException e) {
    // This is expected
    }
    // Account shadow should be gone from the repository
    repoResult = new OperationResult("getObject");
    try {
        repositoryService.getObject(ShadowType.class, accountShadowOidOpendj, null, repoResult);
        AssertJUnit.fail("Shadow still exists in repo after delete");
    } catch (ObjectNotFoundException e) {
        // This is expected, but check also the result
        AssertJUnit.assertFalse("getObject failed as expected, but the result indicates success", repoResult.isSuccess());
    }
    // Account should be deleted from LDAP
    InternalSearchOperation op = openDJController.getInternalConnection().processSearch("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, DereferencePolicy.NEVER_DEREF_ALIASES, 100, 100, false, "(uid=" + USER_JACK_LDAP_UID + ")", null);
    AssertJUnit.assertEquals(0, op.getEntriesSent());
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 10 with InternalSearchOperation

use of org.opends.server.protocols.internal.InternalSearchOperation in project midpoint by Evolveum.

the class TestSanityLegacy method test049DeleteUser.

/**
     * The user should have an account now. Let's try to delete the user. The
     * account should be gone as well.
     *
     * @throws JAXBException
     */
@Test
public void test049DeleteUser() throws SchemaException, FaultMessage, DirectoryException, JAXBException {
    TestUtil.displayTestTile("test049DeleteUser");
    // GIVEN
    assertNoRepoCache();
    // WHEN
    OperationResultType result = deleteObjectViaModelWS(ObjectTypes.USER.getTypeQName(), USER_JACK_OID);
    // THEN
    assertNoRepoCache();
    displayJaxb("deleteObject result", result, SchemaConstants.C_RESULT);
    TestUtil.assertSuccess("deleteObject has failed", result);
    // User should be gone from the repository
    OperationResult repoResult = new OperationResult("getObject");
    try {
        repositoryService.getObject(UserType.class, USER_JACK_OID, null, repoResult);
        AssertJUnit.fail("User still exists in repo after delete");
    } catch (ObjectNotFoundException e) {
    // This is expected
    }
    // Account shadow should be gone from the repository
    repoResult = new OperationResult("getObject");
    try {
        repositoryService.getObject(ShadowType.class, accountShadowOidOpendj, null, repoResult);
        AssertJUnit.fail("Shadow still exists in repo after delete");
    } catch (ObjectNotFoundException e) {
        // This is expected, but check also the result
        AssertJUnit.assertFalse("getObject failed as expected, but the result indicates success", repoResult.isSuccess());
    }
    // Account should be deleted from LDAP
    InternalSearchOperation op = openDJController.getInternalConnection().processSearch("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, DereferencePolicy.NEVER_DEREF_ALIASES, 100, 100, false, "(uid=" + USER_JACK_LDAP_UID + ")", null);
    AssertJUnit.assertEquals(0, op.getEntriesSent());
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Aggregations

InternalSearchOperation (org.opends.server.protocols.internal.InternalSearchOperation)13 SMSException (com.sun.identity.sm.SMSException)7 ResultCode (org.forgerock.opendj.ldap.ResultCode)6 SearchRequest (org.opends.server.protocols.internal.SearchRequest)4 DirectoryException (org.opends.server.types.DirectoryException)4 SearchResultEntry (org.opends.server.types.SearchResultEntry)4 LinkedHashSet (java.util.LinkedHashSet)3 LinkedList (java.util.LinkedList)3 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 SearchScope (org.forgerock.opendj.ldap.SearchScope)1