Search in sources :

Example 16 with ResultCode

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

the class DataLayer method modify.

/**
     * Modifies an ldap entry.
     * 
     * @param principal Authentication Principal.
     * @param guid globally unique identifier for the entry.
     * @param modifications Set of modifications for the entry.
     * @exception AccessRightsException if insufficient access
     * @exception EntryNotFoundException if the entry is not found.
     * @exception UMSException if failure
     *
     * @supported.api
     */
public void modify(Principal principal, Guid guid, Collection<Modification> modifications) throws UMSException {
    String id = guid.getDn();
    ResultCode errorCode;
    try {
        ModifyRequest request = LDAPRequests.newModifyRequest(id);
        for (Modification modification : modifications) {
            request.addModification(modification);
        }
        int retry = 0;
        while (retry <= connNumRetry) {
            if (debug.messageEnabled()) {
                debug.message("DataLayer.modify retry: " + retry);
            }
            try (Connection conn = getConnection(principal)) {
                conn.modify(request);
                return;
            } catch (LdapException e) {
                if (!retryErrorCodes.contains("" + e.getResult().getResultCode().toString()) || retry == connNumRetry) {
                    throw e;
                }
                retry++;
                try {
                    Thread.sleep(connRetryInterval);
                } catch (InterruptedException ex) {
                }
            }
        }
    } catch (LdapException e) {
        if (debug.warningEnabled()) {
            debug.warning("Exception in DataLayer.modify for DN: " + id, e);
        }
        errorCode = e.getResult().getResultCode();
        if (ResultCode.NO_SUCH_OBJECT.equals(errorCode)) {
            throw new EntryNotFoundException(id, e);
        } else if (ResultCode.INSUFFICIENT_ACCESS_RIGHTS.equals(errorCode)) {
            throw new AccessRightsException(id, e);
        } else {
            throw new UMSException(id, e);
        }
    }
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Connection(org.forgerock.opendj.ldap.Connection) ByteString(org.forgerock.opendj.ldap.ByteString) ModifyRequest(org.forgerock.opendj.ldap.requests.ModifyRequest) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 17 with ResultCode

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

the class SMSLdapObject method create.

/**
     * Create an entry in the directory using the principal name
     */
private static void create(Principal p, String dn, Map attrs) throws SMSException, SSOException {
    int retry = 0;
    Entry entry = copyMapToEntry(attrs).setName(dn);
    while (retry <= connNumRetry) {
        debug.message("SMSLdapObject.create() retry: {}", retry);
        try (Connection conn = getConnection(p)) {
            conn.add(LDAPRequests.newAddRequest(entry));
            debug.message("SMSLdapObject.create Successfully created entry: {}", dn);
            break;
        } catch (LdapException e) {
            ResultCode errorCode = e.getResult().getResultCode();
            if (errorCode.equals(ResultCode.ENTRY_ALREADY_EXISTS) && retry > 0) {
                // During install time and other times,
                // this error gets throws due to unknown issue. Issue:
                // Hence mask it.
                debug.warning("SMSLdapObject.create() Entry Already Exists Error for DN {}", dn);
                break;
            }
            if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
                debug.error("SMSLdapObject.create() Error in creating: {} By Principal: {}", dn, p.getName(), e);
                throw new SMSException(e, "sms-entry-cannot-create");
            }
            retry++;
            try {
                Thread.sleep(connRetryInterval);
            } catch (InterruptedException ex) {
            //ignored
            }
        }
    }
}
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 18 with ResultCode

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

the class SMSEmbeddedLdapObject method delete.

/**
     * Delete the entry in the directory. This will delete sub-entries also!
     */
public void delete(SSOToken token, String dn) throws SMSException, SSOException {
    SMSAuditor auditor = newAuditor(token, dn, readCurrentState(dn));
    // Check if there are sub-entries, delete if present
    Iterator se = subEntries(token, dn, "*", 0, false, false).iterator();
    while (se.hasNext()) {
        String entry = (String) se.next();
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject: deleting sub-entry: " + entry);
        }
        delete(token, getNamingAttribute() + "=" + entry + "," + dn);
    }
    // Check if there are suborganizations, delete if present
    // The recursive 'false' here has the scope SCOPE_ONE
    // while searching for the suborgs.
    // Loop through the suborg at the first level and if there
    // is no next suborg, delete that.
    Set subOrgNames = searchSubOrgNames(token, dn, "*", 0, false, false, false);
    for (Iterator so = subOrgNames.iterator(); so.hasNext(); ) {
        String subOrg = (String) so.next();
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject: deleting " + "suborganization: " + subOrg);
        }
        delete(token, subOrg);
    }
    DeleteOperation dop = icConn.processDelete(dn);
    ResultCode resultCode = dop.getResultCode();
    if (resultCode != ResultCode.SUCCESS) {
        if (debug.warningEnabled()) {
            debug.warning("SMSEmbeddedLdapObject.delete: " + "Unable to delete entry:" + dn);
        }
        throw (new SMSException("", "sms-entry-cannot-delete"));
    }
    objectChanged(dn, DELETE);
    if (auditor != null) {
        auditor.auditDelete();
    }
}
Also used : SMSAuditor(org.forgerock.openam.auditors.SMSAuditor) DeleteOperation(org.opends.server.core.DeleteOperation) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) SMSException(com.sun.identity.sm.SMSException) Iterator(java.util.Iterator) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 19 with ResultCode

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

the class SMSEmbeddedLdapObject method internalCreate.

/**
     * Create an entry in the directory using the principal name
     */
private void internalCreate(SSOToken token, String dn, Map attrs) throws SMSException, SSOException {
    SMSAuditor auditor = newAuditor(token, dn, null);
    List attrList = copyMapToAttrList(attrs);
    AddOperation ao = icConn.processAdd(dn, attrList);
    ResultCode resultCode = ao.getResultCode();
    if (resultCode == ResultCode.SUCCESS) {
        if (debug.messageEnabled()) {
            debug.message("SMSEmbeddedLdapObject.create: Successfully created" + " entry: " + dn);
        }
        if (auditor != null) {
            auditor.auditCreate(attrs);
        }
    } else if (resultCode == ResultCode.ENTRY_ALREADY_EXISTS) {
        // During install time and other times,
        // this error gets throws due to unknown issue. Issue:
        // Hence mask it.
        debug.warning("SMSEmbeddedLdapObject.create: Entry " + "Already Exists Error for DN" + dn);
    } else {
        debug.error("SMSEmbeddedLdapObject.create: Error creating entry: " + dn + ", error code = " + resultCode);
        throw new SMSException("", "sms-entry-cannot-create");
    }
}
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) AddOperation(org.opends.server.core.AddOperation) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 20 with ResultCode

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

the class SearchResultIterator method hasNext.

public boolean hasNext() {
    try {
        if (results.hasNext()) {
            if (current == null) {
                if (results.isReference()) {
                    debug.warning("SearchResultIterator: ignoring reference: {}", results.readReference());
                    return hasNext();
                }
                SearchResultEntry entry = results.readEntry();
                String dn = entry.getName().toString();
                if (hasExcludeDNs && excludeDNs.contains(dn)) {
                    return hasNext();
                }
                current = new SMSDataEntry(dn, SMSUtils.convertEntryToAttributesMap(entry));
            }
            return true;
        }
    } catch (LdapException e) {
        ResultCode errorCode = e.getResult().getResultCode();
        if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
            debug.message("SearchResultIterator: size limit exceeded");
        } else {
            debug.error("SearchResultIterator.hasNext", e);
        }
    } catch (SearchResultReferenceIOException e) {
        debug.error("SearchResultIterator.hasNext: reference should be already handled", e);
        return hasNext();
    }
    conn.close();
    return false;
}
Also used : SMSDataEntry(com.sun.identity.sm.SMSDataEntry) SearchResultReferenceIOException(org.forgerock.opendj.ldap.SearchResultReferenceIOException) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode) SearchResultEntry(org.forgerock.opendj.ldap.responses.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