Search in sources :

Example 66 with LdapException

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

the class ServiceBase method connectDSwithDN.

/**
     * Check if Directory Server has the suffix.
     *
     * @return <code>true</code> if specified suffix exists.
     */
protected static boolean connectDSwithDN(Connection ld, String suffix) {
    String filter = "cn=" + suffix;
    String[] attrs = { "" };
    try (ConnectionEntryReader reader = ld.search(LDAPRequests.newSearchRequest(suffix, SearchScope.BASE_OBJECT, filter, attrs))) {
        return reader.hasNext();
    } catch (LdapException e) {
        return false;
    }
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) LdapException(org.forgerock.opendj.ldap.LdapException)

Example 67 with LdapException

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

the class UpgradeUtils method delete.

/**
     * Delete an entry, recursing if the entry has children
     *
     * @param dn DN of the entry to delete
     * @param ld active connection to server
     * @param doDelete true if the entries really
     * are to be deleted
     */
public static void delete(String dn, Connection ld, boolean doDelete) {
    String theDN = "";
    try {
        // Find all immediate child nodes; return no
        // attributes
        ConnectionEntryReader res = ld.search(LDAPRequests.newSearchRequest(dn, SearchScope.SINGLE_LEVEL, "objectclass=*"));
        while (res.hasNext()) {
            if (res.isReference()) {
                //ignore
                res.readReference();
            } else {
                // Next directory entry
                SearchResultEntry entry = res.readEntry();
                theDN = entry.getName().toString();
                // Recurse down
                delete(theDN, ld, doDelete);
            }
        }
        // so stop recursing and delete the node
        try {
            if (doDelete) {
                ld.delete(LDAPRequests.newDeleteRequest(dn));
                if (debug.messageEnabled()) {
                    debug.message(dn + " deleted");
                }
            }
        } catch (LdapException e) {
            if (debug.messageEnabled()) {
                debug.message(e.toString());
            }
        } catch (Exception e) {
            if (debug.messageEnabled()) {
                debug.message(e.toString());
            }
        }
    } catch (Exception me) {
    // do nothing
    }
}
Also used : ConnectionEntryReader(org.forgerock.opendj.ldif.ConnectionEntryReader) ByteString(org.forgerock.opendj.ldap.ByteString) LdapException(org.forgerock.opendj.ldap.LdapException) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) SearchResultEntry(org.forgerock.opendj.ldap.responses.SearchResultEntry)

Example 68 with LdapException

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

the class DirectoryServicesImpl method verifyAndGetOrgDN.

/**
     * Gets the Organization DN for the specified entryDN. If the entry itself
     * is an org, then same DN is returned.
     * 
     * @param token
     *            a valid SSOToken
     * @param entryDN
     *            the entry whose parent Organization is to be obtained
     * @param childDN
     *            the immediate entry whose parent Organization is to be
     *            obtained
     * @return the DN String of the parent Organization
     * @throws AMException
     *             if an error occured while obtaining the parent Organization
     */
public String verifyAndGetOrgDN(SSOToken token, String entryDN, String childDN) throws AMException {
    if (entryDN.isEmpty() || DN.valueOf(entryDN).size() <= 0) {
        debug.error("DirectoryServicesImpl.verifyAndGetOrgDN() Invalid " + "DN: " + entryDN);
        throw new AMException(token, "157");
    }
    String organizationDN = null;
    boolean errorCondition = false;
    try {
        PersistentObject po = UMSObject.getObjectHandle(internalToken, new Guid(childDN));
        String searchFilter = getOrgSearchFilter(entryDN);
        SearchResults result = po.search(searchFilter, aName, scontrol);
        if (result.hasMoreElements()) {
            // ABANDON logged in directory server access logs.
            while (result.hasMoreElements()) {
                result.next();
            }
            organizationDN = po.getGuid().toString().toLowerCase();
        }
    } catch (InvalidSearchFilterException e) {
        errorCondition = true;
        debug.error("DirectoryServicesImpl.verifyAndGetOrgDN(): Invalid " + "search filter, unable to get Parent Organization: ", e);
    } catch (UMSException ue) {
        errorCondition = true;
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.verifyAndGetOrgDN(): " + "Unable to Obtain Parent Organization", ue);
        }
        LdapException lex = (LdapException) ue.getRootCause();
        ResultCode errorCode = lex.getResult().getResultCode();
        if (retryErrorCodes.contains("" + errorCode)) {
            throw new AMException(token, Integer.toString(errorCode.intValue()), ue);
        }
    }
    if (errorCondition) {
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("124", locale), "124");
    }
    return organizationDN;
}
Also used : UMSException(com.iplanet.ums.UMSException) InvalidSearchFilterException(com.iplanet.ums.InvalidSearchFilterException) AMException(com.iplanet.am.sdk.AMException) PersistentObject(com.iplanet.ums.PersistentObject) Guid(com.iplanet.ums.Guid) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) SearchResults(com.iplanet.ums.SearchResults) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 69 with LdapException

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

the class DirectoryServicesImpl method search.

/**
     * Searches the Directory
     * 
     * @param token
     *            SSOToken
     * @param entryDN
     *            DN of the entry to start the search with
     * @param searchFilter
     *            search filter
     * @param searchScope
     *            search scope, BASE, ONELEVEL or SUBTREE
     * @return Set set of matching DNs
     */
public Set search(SSOToken token, String entryDN, String searchFilter, int searchScope) throws AMException {
    Set resultSet = Collections.EMPTY_SET;
    try {
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        SearchControl control = new SearchControl();
        control.setSearchScope(searchScope);
        SearchResults results = po.search(searchFilter, control);
        resultSet = searchResultsToSet(results);
    } catch (UMSException ue) {
        LdapException lex = (LdapException) ue.getRootCause();
        ResultCode errorCode = lex.getResult().getResultCode();
        if (retryErrorCodes.contains("" + errorCode)) {
            throw new AMException(token, Integer.toString(errorCode.intValue()), ue);
        }
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.search(token:, entryDN: " + entryDN + ", searchFilter: " + searchFilter + "searchScope: " + searchScope + " error occurred: ", ue);
        }
        processInternalException(token, ue, "341");
    }
    return resultSet;
}
Also used : Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) AttrSet(com.iplanet.services.ldap.AttrSet) UMSException(com.iplanet.ums.UMSException) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) SearchControl(com.iplanet.ums.SearchControl) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) SearchResults(com.iplanet.ums.SearchResults) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 70 with LdapException

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

the class Step4 method validateUMDomainName.

public boolean validateUMDomainName() {
    setPath(null);
    Context ctx = getContext();
    String strSSL = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_SSL);
    boolean ssl = (strSSL != null) && (strSSL.equals("SSL"));
    String domainName = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_DOMAINNAME);
    String rootSuffixAD = dnsDomainToDN(domainName);
    getContext().setSessionAttribute(SessionAttributeNames.USER_STORE_ROOT_SUFFIX, rootSuffixAD);
    String[] hostAndPort = { "" };
    try {
        hostAndPort = getLdapHostAndPort(domainName);
    } catch (NamingException nex) {
        writeToResponse(getLocalizedString("cannot.connect.to.UM.datastore"));
        return false;
    } catch (IOException ioex) {
        writeToResponse(getLocalizedString("cannot.connect.to.UM.datastore"));
        return false;
    }
    String host = hostAndPort[0];
    int port = Integer.parseInt(hostAndPort[1]);
    String bindDN = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_LOGIN_ID);
    String rootSuffix = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_ROOT_SUFFIX);
    String bindPwd = (String) ctx.getSessionAttribute(SessionAttributeNames.USER_STORE_LOGIN_PWD);
    try (Connection conn = getConnection(host, port, bindDN, bindPwd.toCharArray(), 3, ssl)) {
        //String filter = "cn=" + "\"" + rootSuffix + "\"";
        String[] attrs = { "" };
        conn.search(LDAPRequests.newSearchRequest(rootSuffix, SearchScope.BASE_OBJECT, ObjectClassFilter, attrs));
        writeToResponse("ok");
    } catch (LdapException lex) {
        ResultCode resultCode = lex.getResult().getResultCode();
        if (!writeErrorToResponse(resultCode)) {
            writeToResponse(getLocalizedString("cannot.connect.to.UM.datastore"));
        }
    } catch (Exception e) {
        writeToResponse(getLocalizedString("cannot.connect.to.UM.datastore"));
    }
    return false;
}
Also used : DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext) Context(org.apache.click.Context) Connection(org.forgerock.opendj.ldap.Connection) NamingException(javax.naming.NamingException) IOException(java.io.IOException) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode) LdapException(org.forgerock.opendj.ldap.LdapException) IOException(java.io.IOException) NamingException(javax.naming.NamingException)

Aggregations

LdapException (org.forgerock.opendj.ldap.LdapException)88 Connection (org.forgerock.opendj.ldap.Connection)62 ByteString (org.forgerock.opendj.ldap.ByteString)41 ResultCode (org.forgerock.opendj.ldap.ResultCode)37 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)35 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)34 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)23 HashSet (java.util.HashSet)22 SearchResultReferenceIOException (org.forgerock.opendj.ldap.SearchResultReferenceIOException)22 Attribute (org.forgerock.opendj.ldap.Attribute)17 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 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)10 IOException (java.io.IOException)10 DN (org.forgerock.opendj.ldap.DN)10 InvalidNameException (com.sun.identity.policy.InvalidNameException)9 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)9