Search in sources :

Example 56 with Connection

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

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

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

the class SMSLdapObject method search.

/**
     * Returns LDAP entries that match the filter, using the start DN provided
     * in method
     */
public Iterator<SMSDataEntry> search(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Set<String> excludes) throws SSOException, SMSException {
    Connection conn = getConnection(adminPrincipal);
    ConnectionEntryReader results = searchObjectsEx(token, startDN, filter, numOfEntries, timeLimit, sortResults, ascendingOrder, conn);
    return new SearchResultIterator(results, excludes, conn);
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) Connection(org.forgerock.opendj.ldap.Connection)

Example 59 with Connection

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

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

the class SMDataLayer method getConnection.

/**
     * Get connection from pool, not through LDAPProxy. Reauthenticate if
     * necessary
     * 
     * @return connection that is available to use
     */
protected Connection getConnection() {
    if (_ldapPool == null)
        return null;
    debug.message("SMDataLayer:getConnection() - Invoking _ldapPool.getConnection()");
    Connection conn = null;
    try {
        conn = _ldapPool.getConnection();
        debug.message("SMDataLayer:getConnection() - Got Connection : {}", conn);
    } catch (LdapException e) {
        debug.error("SMDataLayer:getConnection() - Failed to get Connection", e);
    }
    return conn;
}
Also used : Connection(org.forgerock.opendj.ldap.Connection) LdapException(org.forgerock.opendj.ldap.LdapException)

Aggregations

Connection (org.forgerock.opendj.ldap.Connection)88 LdapException (org.forgerock.opendj.ldap.LdapException)70 ByteString (org.forgerock.opendj.ldap.ByteString)45 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)42 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)35 ResultCode (org.forgerock.opendj.ldap.ResultCode)29 Attribute (org.forgerock.opendj.ldap.Attribute)25 HashSet (java.util.HashSet)23 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)20 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)17 IOException (java.io.IOException)16 SSOException (com.iplanet.sso.SSOException)15 PolicyException (com.sun.identity.policy.PolicyException)14 SMSException (com.sun.identity.sm.SMSException)13 ModifyRequest (org.forgerock.opendj.ldap.requests.ModifyRequest)12 LinkedAttribute (org.forgerock.opendj.ldap.LinkedAttribute)11 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)10 InvalidNameException (com.sun.identity.policy.InvalidNameException)10 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)10 LinkedHashSet (java.util.LinkedHashSet)10