Search in sources :

Example 1 with SearchRequest

use of org.opends.server.protocols.internal.SearchRequest 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 2 with SearchRequest

use of org.opends.server.protocols.internal.SearchRequest 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)

Example 3 with SearchRequest

use of org.opends.server.protocols.internal.SearchRequest 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 SearchRequest

use of org.opends.server.protocols.internal.SearchRequest 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)

Aggregations

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