Search in sources :

Example 1 with InternalSearchOperation

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

the class OpenDJController method dumpEntries.

public String dumpEntries() throws DirectoryException {
    InternalSearchOperation op = getInternalConnection().processSearch(ldapSuffix, SearchScope.WHOLE_SUBTREE, DereferencePolicy.NEVER_DEREF_ALIASES, 100, 100, false, "(objectclass=*)", getSearchAttributes());
    StringBuilder sb = new StringBuilder();
    for (SearchResultEntry searchEntry : op.getSearchEntries()) {
        sb.append(toHumanReadableLdifoid(searchEntry));
        sb.append("\n");
    }
    return sb.toString();
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation)

Example 2 with InternalSearchOperation

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

the class SMSEmbeddedLdapObject method search.

/**
     * Returns LDAP entries that match the filter, using the start DN provided
     * in method
     */
public Set<String> search(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder) throws SSOException, SMSException {
    if (debug.messageEnabled()) {
        debug.message("SMSEmbeddedLdapObject.search: startDN = " + startDN + ", filter: " + filter);
    }
    InternalSearchOperation iso = searchObjects(startDN, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, sortResults, ascendingOrder);
    ResultCode resultCode = iso.getResultCode();
    if (resultCode == ResultCode.SIZE_LIMIT_EXCEEDED) {
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject.search:" + " size limit exceeded. numOfEntries = " + numOfEntries);
        }
    } else if (resultCode != ResultCode.SUCCESS) {
        if (debug.warningEnabled()) {
            debug.warning("SMSEmbeddedLdapObject.search: Unable to " + "search. startDN = " + startDN + ", filter = " + filter + ", resultCode = " + resultCode);
        }
        throw new SMSException("", "sms-error-in-searching");
    }
    Set<String> answer = new LinkedHashSet<>();
    for (SearchResultEntry entry : iso.getSearchEntries()) {
        String dn = entry.getName().toString();
        answer.add(dn);
    }
    if (debug.messageEnabled()) {
        debug.message("SMSEmbeddedLdapObject.search: returned " + "successfully: " + filter + "\n\tObjects: " + answer);
    }
    return answer;
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) LinkedHashSet(java.util.LinkedHashSet) SMSException(com.sun.identity.sm.SMSException) ResultCode(org.forgerock.opendj.ldap.ResultCode) SearchResultEntry(org.opends.server.types.SearchResultEntry)

Example 3 with InternalSearchOperation

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

the class SMSEmbeddedLdapObject method read.

/**
     * Reads in the object from persistent store, assuming that the guid and the
     * SSOToken are valid
     */
public Map read(SSOToken token, String dn) throws SMSException, SSOException {
    if (dn == null || dn.length() == 0) {
        // This must not be possible return an exception.
        debug.error("SMSEmbeddedLdapObject.read: Null or Empty DN=" + dn);
        throw new SMSException("", "sms-NO_SUCH_OBJECT");
    }
    if (!LDAPUtils.isDN(dn)) {
        debug.warning("SMSEmbeddedLdapObject: Invalid DN=" + dn);
        String[] args = { dn };
        throw new SMSException(IUMSConstants.UMS_BUNDLE_NAME, "sms-INVALID_DN", args);
    }
    // Check if entry does not exist
    if (SMSNotificationManager.isCacheEnabled() && entriesNotPresent.contains(dn)) {
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject:read Entry not present: " + dn + " (checked in cached)");
        }
        return (null);
    }
    try {
        SearchRequest request = Requests.newSearchRequest(dn, SearchScope.BASE_OBJECT, "(objectclass=*)", smsAttributes.toArray(new String[smsAttributes.size()]));
        InternalSearchOperation iso = icConn.processSearch(request);
        ResultCode resultCode = iso.getResultCode();
        if (resultCode == ResultCode.SUCCESS) {
            LinkedList searchResult = iso.getSearchEntries();
            if (!searchResult.isEmpty()) {
                SearchResultEntry entry = (SearchResultEntry) searchResult.get(0);
                List attributes = entry.getAttributes();
                return EmbeddedSearchResultIterator.convertLDAPAttributeSetToMap(attributes);
            } else {
                return null;
            }
        } else if (resultCode == ResultCode.NO_SUCH_OBJECT) {
            // Add to not present Set
            objectChanged(dn, DELETE);
            if (debug.messageEnabled()) {
                debug.message("SMSEmbeddedLdapObject.read: " + "entry not present:" + dn);
            }
            return null;
        } else {
            if (debug.warningEnabled()) {
                debug.warning("SMSEmbeddedLdapObject.read: " + "Error in accessing entry DN: " + dn + ", error code = " + resultCode);
            }
            throw new SMSException("", "sms-entry-cannot-access");
        }
    } catch (DirectoryException dex) {
        if (debug.warningEnabled()) {
            debug.warning("SMSEmbeddedLdapObject.read: " + "Error in accessing entry DN: " + dn, dex);
        }
        throw new SMSException(dex, "sms-entry-cannot-access");
    }
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) SearchRequest(org.opends.server.protocols.internal.SearchRequest) SMSException(com.sun.identity.sm.SMSException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ResultCode(org.forgerock.opendj.ldap.ResultCode) LinkedList(java.util.LinkedList) DirectoryException(org.opends.server.types.DirectoryException) SearchResultEntry(org.opends.server.types.SearchResultEntry)

Example 4 with InternalSearchOperation

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

the class SMSEmbeddedLdapObject method search.

public Iterator<SMSDataEntry> search(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Set excludes) throws SSOException, SMSException {
    InternalSearchOperation iso = searchObjects(startDN, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, sortResults, ascendingOrder);
    ResultCode resultCode = iso.getResultCode();
    if (resultCode == ResultCode.SIZE_LIMIT_EXCEEDED) {
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject.search:" + " size limit exceeded. numOfEntries = " + numOfEntries);
        }
    } else if (resultCode != ResultCode.SUCCESS) {
        if (debug.warningEnabled()) {
            debug.warning("SMSEmbeddedLdapObject.searchEx: Unable to " + "search. startDN = " + startDN + ", filter = " + filter + ", resultCode = " + resultCode);
        }
        throw new SMSException("", "sms-error-in-searching");
    }
    LinkedList searchResult = iso.getSearchEntries();
    return new EmbeddedSearchResultIterator(searchResult, excludes);
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) SMSException(com.sun.identity.sm.SMSException) ResultCode(org.forgerock.opendj.ldap.ResultCode) LinkedList(java.util.LinkedList)

Example 5 with InternalSearchOperation

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

the class SMSEmbeddedLdapObject method entryExists.

/**
     * Checks if the provided DN exists.
     */
private static boolean entryExists(String dn) throws SMSException {
    try {
        SearchRequest request = Requests.newSearchRequest(dn, SearchScope.BASE_OBJECT, "(objectclass=*)");
        InternalSearchOperation iso = icConn.processSearch(request);
        ResultCode resultCode = iso.getResultCode();
        if (resultCode == ResultCode.SUCCESS) {
            return true;
        } else if (resultCode == ResultCode.NO_SUCH_OBJECT || resultCode == ResultCode.CLIENT_SIDE_NO_RESULTS_RETURNED) {
            if (debug.warningEnabled()) {
                debug.warning("SMSEmbeddedLdapObject:entryExists: " + dn + " does not exist. resultCode = " + resultCode);
            }
            return false;
        } else {
            throw new SMSException("Failed to find entry with DN: " + dn + " LDAP error result: " + resultCode, IUMSConstants.SMS_LDAP_OPERATION_FAILED);
        }
    } catch (DirectoryException dex) {
        throw new SMSException("Failed to find entry with DN: " + dn, dex, IUMSConstants.SMS_LDAP_OPERATION_FAILED);
    }
}
Also used : InternalSearchOperation(org.opends.server.protocols.internal.InternalSearchOperation) SearchRequest(org.opends.server.protocols.internal.SearchRequest) SMSException(com.sun.identity.sm.SMSException) ResultCode(org.forgerock.opendj.ldap.ResultCode) DirectoryException(org.opends.server.types.DirectoryException)

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