Search in sources :

Example 26 with ResultCode

use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.

the class SMSLdapObject method read.

/**
     * Reads in the object from persistent store, assuming that the guid and the
     * SSOToken are valid
     */
public Map<String, Set<String>> read(SSOToken token, String dn) throws SMSException, SSOException {
    if (dn == null || dn.length() == 0) {
        // This must not be possible return an exception.
        debug.error("SMSLdapObject: read():Null or Empty DN=" + dn);
        throw new SMSException(LdapException.newLdapException(ResultCode.NO_SUCH_OBJECT, getBundleString(IUMSConstants.SMS_INVALID_DN, dn)), "sms-NO_SUCH_OBJECT");
    }
    if (!LDAPUtils.isDN(dn)) {
        debug.warning("SMSLdapObject: 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)) {
        debug.message("SMSLdapObject:read Entry not present: {} (checked in cache)", dn);
        return null;
    }
    Entry ldapEntry = null;
    int retry = 0;
    while (retry <= connNumRetry) {
        debug.message("SMSLdapObject.read() retry: {}", retry);
        ResultCode errorCode = null;
        try (Connection conn = getConnection(token.getPrincipal())) {
            ldapEntry = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(DN.valueOf(dn), getAttributeNames()));
            break;
        } catch (LdapException e) {
            errorCode = e.getResult().getResultCode();
            if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
                if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
                    // Add to not present Set
                    objectChanged(dn, DELETE);
                    debug.message("SMSLdapObject.read: entry not present: {}", dn);
                    break;
                } else {
                    debug.warning("SMSLdapObject.read: Error in accessing entry DN: {}", dn, e);
                    throw new SMSException(e, "sms-entry-cannot-access");
                }
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            // ignored
            }
        }
    }
    if (ldapEntry != null) {
        if (debug.messageEnabled()) {
            debug.message("SMSLdapObject.read(): reading entry: " + dn);
        }
        return SMSUtils.convertEntryToAttributesMap(ldapEntry);
    } else {
        return null;
    }
}
Also used : SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry) SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SMSEntry(com.sun.identity.sm.SMSEntry) LinkedHashMapEntry(org.forgerock.opendj.ldap.LinkedHashMapEntry) Entry(org.forgerock.opendj.ldap.Entry) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 27 with ResultCode

use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.

the class SMSLdapObject method getOrgNames.

private Set<String> getOrgNames(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
    ConnectionEntryReader results = null;
    int retry = 0;
    SearchRequest request = getSearchRequest(dn, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, 0, sortResults, ascendingOrder, getOrgNamingAttribute(), O_ATTR);
    while (retry <= connNumRetry) {
        if (debug.messageEnabled()) {
            debug.message("SMSLdapObject.getOrgNames() retry: " + retry);
        }
        try (Connection conn = getConnection(token.getPrincipal())) {
            // Get the organization names
            results = conn.search(request);
            results.hasNext();
            return toDNStrings(results, dn, ORG_CANNOT_OBTAIN);
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
                if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
                    debug.message("SMSLdapObject.getOrgNames(): org not present: {}", dn);
                    break;
                } else {
                    debug.warning("SMSLdapObject.getOrgNames: Unable to search for organization names: {}", dn, e);
                    throw new SMSException(e, "sms-org-cannot-search");
                }
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            // ignored
            }
        }
    }
    return Collections.emptySet();
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 28 with ResultCode

use of org.forgerock.opendj.ldap.ResultCode 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 29 with ResultCode

use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.

the class SMSLdapObject method searchSubOrganizationNames.

private Set<String> searchSubOrganizationNames(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder, boolean recursive) throws SMSException, SSOException {
    SearchRequest request = getSearchRequest(dn, filter, recursive ? SearchScope.WHOLE_SUBTREE : SearchScope.SINGLE_LEVEL, numOfEntries, 0, sortResults, ascendingOrder, getOrgNamingAttribute(), O_ATTR);
    int retry = 0;
    while (retry <= connNumRetry) {
        if (debug.messageEnabled()) {
            debug.message("SMSLdapObject.searchSubOrganizationNames() retry: " + retry);
        }
        try (Connection conn = getConnection(token.getPrincipal())) {
            // Get the suborganization names
            ConnectionEntryReader iterResults = conn.search(request);
            iterResults.hasNext();
            return toDNStrings(iterResults, dn, SUBORG_CANNOT_OBTAIN);
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
                if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
                    debug.message("SMSLdapObject.searchSubOrganizationNames(): suborg not present: {}", dn);
                    break;
                } else {
                    debug.warning("SMSLdapObject.searchSubOrganizationName(): Unable to search: {}", dn, e);
                    throw new SMSException(e, "sms-suborg-cannot-search");
                }
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            // ignored
            }
        }
    }
    return Collections.emptySet();
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 30 with ResultCode

use of org.forgerock.opendj.ldap.ResultCode 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)

Aggregations

ResultCode (org.forgerock.opendj.ldap.ResultCode)49 LdapException (org.forgerock.opendj.ldap.LdapException)37 Connection (org.forgerock.opendj.ldap.Connection)29 ByteString (org.forgerock.opendj.ldap.ByteString)18 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)18 SMSException (com.sun.identity.sm.SMSException)17 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)17 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)15 HashSet (java.util.HashSet)14 PolicyException (com.sun.identity.policy.PolicyException)13 SSOException (com.iplanet.sso.SSOException)9 InvalidNameException (com.sun.identity.policy.InvalidNameException)9 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)9 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)7 ValidValues (com.sun.identity.policy.ValidValues)6 LinkedHashSet (java.util.LinkedHashSet)6 InternalSearchOperation (org.opends.server.protocols.internal.InternalSearchOperation)6 AMException (com.iplanet.am.sdk.AMException)4 AMSearchResults (com.iplanet.am.sdk.AMSearchResults)4 IOException (java.io.IOException)4