Search in sources :

Example 31 with ResultCode

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

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

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

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

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

the class SMSEmbeddedLdapObject method modify.

/**
     * Save the entry using the token provided. The principal provided will be
     * used to get the proxy connection.
     */
public void modify(SSOToken token, String dn, ModificationItem[] mods) throws SMSException, SSOException {
    SMSAuditor auditor = newAuditor(token, dn, readCurrentState(dn));
    List modList = copyModItemsToLDAPModList(mods);
    ModifyOperation mo = icConn.processModify(dn, modList);
    ResultCode resultCode = mo.getResultCode();
    if (resultCode == ResultCode.SUCCESS) {
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject.modify: Successfully " + "modified entry: " + dn);
        }
        if (auditor != null) {
            auditor.auditModify(mods);
        }
    } else {
        debug.error("SMSEmbeddedLdapObject.modify: Error modifying entry " + dn + " by Principal: " + token.getPrincipal().getName() + ", error code = " + resultCode);
        throw new SMSException("", "sms-entry-cannot-modify");
    }
}
Also used : SMSAuditor(org.forgerock.openam.auditors.SMSAuditor) SMSException(com.sun.identity.sm.SMSException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ModifyOperation(org.opends.server.core.ModifyOperation) ResultCode(org.forgerock.opendj.ldap.ResultCode)

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