Search in sources :

Example 1 with SearchResultEntry

use of org.opends.server.types.SearchResultEntry 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 2 with SearchResultEntry

use of org.opends.server.types.SearchResultEntry 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 3 with SearchResultEntry

use of org.opends.server.types.SearchResultEntry 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 4 with SearchResultEntry

use of org.opends.server.types.SearchResultEntry in project OpenAM by OpenRock.

the class EmbeddedSearchResultIterator method hasNext.

public boolean hasNext() {
    if (!resultIter.hasNext()) {
        return false;
    }
    SearchResultEntry entry = (SearchResultEntry) resultIter.next();
    String dn = entry.getName().toString();
    if (hasExcludeDNs) {
        while (excludeDNs.contains(dn)) {
            if (resultIter.hasNext()) {
                entry = (SearchResultEntry) resultIter.next();
                dn = entry.getName().toString();
            } else {
                entry = null;
                break;
            }
        }
    }
    current = (entry == null) ? null : new SMSDataEntry(dn, convertLDAPAttributeSetToMap(entry.getAttributes()));
    return (current != null);
}
Also used : SMSDataEntry(com.sun.identity.sm.SMSDataEntry) ByteString(org.forgerock.opendj.ldap.ByteString) SearchResultEntry(org.opends.server.types.SearchResultEntry)

Example 5 with SearchResultEntry

use of org.opends.server.types.SearchResultEntry 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)

Aggregations

SearchResultEntry (org.opends.server.types.SearchResultEntry)5 SMSException (com.sun.identity.sm.SMSException)4 ResultCode (org.forgerock.opendj.ldap.ResultCode)4 InternalSearchOperation (org.opends.server.protocols.internal.InternalSearchOperation)4 LinkedHashSet (java.util.LinkedHashSet)3 LinkedList (java.util.LinkedList)2 SearchRequest (org.opends.server.protocols.internal.SearchRequest)2 DirectoryException (org.opends.server.types.DirectoryException)2 SMSDataEntry (com.sun.identity.sm.SMSDataEntry)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ByteString (org.forgerock.opendj.ldap.ByteString)1 SearchScope (org.forgerock.opendj.ldap.SearchScope)1