Search in sources :

Example 31 with LdapException

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

the class DataLayer method rename.

public void rename(java.security.Principal principal, Guid guid, String newName, boolean deleteOldName) throws UMSException {
    String id = guid.getDn();
    ResultCode errorCode;
    try {
        ModifyDNRequest request = LDAPRequests.newModifyDNRequest(id, newName);
        int retry = 0;
        while (retry <= connNumRetry) {
            if (debug.messageEnabled()) {
                debug.message("DataLayer.rename retry: " + retry);
            }
            try (Connection conn = getConnection(principal)) {
                conn.applyChange(request);
                return;
            } catch (LdapException e) {
                errorCode = e.getResult().getResultCode();
                if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
                    throw e;
                }
                retry++;
                try {
                    Thread.sleep(connRetryInterval);
                } catch (InterruptedException ex) {
                }
            }
        }
    } catch (LdapException e) {
        if (debug.warningEnabled()) {
            debug.warning("Exception in DataLayer.rename 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 : ModifyDNRequest(org.forgerock.opendj.ldap.requests.ModifyDNRequest) Connection(org.forgerock.opendj.ldap.Connection) ByteString(org.forgerock.opendj.ldap.ByteString) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 32 with LdapException

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

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

the class UpgradeUtils method getLDAPConnection.

/**
     * Helper method to return Ldap connection
     *
     * @return Ldap connection
     */
private static Connection getLDAPConnection() {
    String classMethod = "UpgradeUtils:getLDAPConnection : ";
    if (debug.messageEnabled()) {
        debug.message(classMethod + "Directory Server Host: " + dsHostName);
        debug.message(classMethod + "Directory Server Port: " + dsPort);
        debug.message(classMethod + "Direcotry Server DN: " + dsManager);
    }
    try {
        // All connections will use authentication.
        Options options = Options.defaultOptions().set(AUTHN_BIND_REQUEST, LDAPRequests.newSimpleBindRequest(dsManager, dsAdminPwd.toCharArray())).set(CONNECT_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS));
        return getLDAPConnectionFactory(dsHostName, dsPort, options).getConnection();
    } catch (LdapException e) {
        debug.error(classMethod + " Error getting LDAP Connection");
    }
    return null;
}
Also used : Options(org.forgerock.util.Options) Duration(org.forgerock.util.time.Duration) ByteString(org.forgerock.opendj.ldap.ByteString) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 34 with LdapException

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

the class SMSLdapObject method entryExists.

/**
     * Checks if the provided DN exists.
     */
private static boolean entryExists(String dn) throws SMSException {
    boolean entryExists = false;
    try (Connection conn = getConnection(adminPrincipal)) {
        // Use the Admin Principal to check if entry exists
        conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(dn, OU_ATTR));
        entryExists = true;
    } catch (EntryNotFoundException e) {
        debug.warning("SMSLdapObject:entryExists: {} does not exist", dn);
    } catch (LdapException e) {
        throw new SMSException("Unable to find entry with DN: " + dn, e, IUMSConstants.SMS_LDAP_OPERATION_FAILED);
    }
    return entryExists;
}
Also used : SMSException(com.sun.identity.sm.SMSException) Connection(org.forgerock.opendj.ldap.Connection) EntryNotFoundException(org.forgerock.opendj.ldap.EntryNotFoundException) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 35 with LdapException

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

Aggregations

LdapException (org.forgerock.opendj.ldap.LdapException)90 Connection (org.forgerock.opendj.ldap.Connection)64 ByteString (org.forgerock.opendj.ldap.ByteString)45 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)38 ResultCode (org.forgerock.opendj.ldap.ResultCode)37 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)37 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)24 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)24 HashSet (java.util.HashSet)22 Attribute (org.forgerock.opendj.ldap.Attribute)19 PolicyException (com.sun.identity.policy.PolicyException)13 SMSException (com.sun.identity.sm.SMSException)12 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)12 SSOException (com.iplanet.sso.SSOException)11 LinkedHashSet (java.util.LinkedHashSet)11 DN (org.forgerock.opendj.ldap.DN)11 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)10 IOException (java.io.IOException)10 InvalidNameException (com.sun.identity.policy.InvalidNameException)9 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)9