Thrown to indicate that an Ldap exception has occurred. This is a general exception which includes a message and an Ldap result code. An LdapException can result from physical problems (such as network errors) as well as problems with Ldap operations detected by the server. For example, if an Ldap add operation fails because of a duplicate entry, the server returns a result code. Five possible sources of information are available from LdapException:
Result Code:
The getResultCode method returns a result code, which can be compared against standard Ldap result codes.
Message:
The getMessage method returns a localized message from the message resource that corresponds to the result code.
Ldap server Message:
The getLdapErrorMessage method returns any error message received from the Ldap server.
Matched DN:
The getMatchedDN method retrieves the part of a submitted distinguished name which could be matched by the server
Root Cause:
The getCause method returns the a nested exception that was the original cause for the error.
The toString method returns a string containing all the above sources of information, if they have a value. Exceptions generated by the API, i.e. that are not a result of a server response, can be identified as instanceof {@link LdapLocalException} The following table lists the standard Ldap result codes. See RFC2251 for a discussion of the meanings of the result codes. The corresponding ASN.1 definition from RFC2251 is provided in parentheses.
Value Result Code
0{@link #SUCCESS} (success)
1{@link #OPERATIONS_ERROR} (operationsError)
2{@link #PROTOCOL_ERROR} (protocolError)
3{@link #TIME_LIMIT_EXCEEDED} (timeLimitExceeded)
4{@link #SIZE_LIMIT_EXCEEDED} (sizeLimitExceeded)
5{@link #COMPARE_FALSE} (compareFalse)
6{@link #COMPARE_TRUE} (compareTrue)
7{@link #AUTH_METHOD_NOT_SUPPORTED} (authMethodNotSupported)
8{@link #STRONG_AUTH_REQUIRED} (strongAuthRequired)
10{@link #REFERRAL} (referral)
11{@link #ADMIN_LIMIT_EXCEEDED} (adminLimitExceeded)
12{@link #UNAVAILABLE_CRITICAL_EXTENSION} (unavailableCriticalExtension)
13{@link #CONFIDENTIALITY_REQUIRED} (confidentialityRequired)
14{@link #SASL_BIND_IN_PROGRESS} (saslBindInProgress)
16{@link #NO_SUCH_ATTRIBUTE} (noSuchAttribute)
17{@link #UNDEFINED_ATTRIBUTE_TYPE} (undefinedAttributeType)
18{@link #INAPPROPRIATE_MATCHING} (inappropriateMatching)
19{@link #CONSTRAINT_VIOLATION} (constraintViolation)
20{@link #ATTRIBUTE_OR_VALUE_EXISTS} (AttributeOrValueExists)
21{@link #INVALID_ATTRIBUTE_SYNTAX} (invalidAttributeSyntax)
32{@link #NO_SUCH_OBJECT} (noSuchObject)
33{@link #ALIAS_PROBLEM} (aliasProblem)
34{@link #INVALID_DN_SYNTAX} (invalidDNSyntax)
35{@link #IS_LEAF} (isLeaf)
36{@link #ALIAS_DEREFERENCING_PROBLEM} (aliasDereferencingProblem)
48{@link #INAPPROPRIATE_AUTHENTICATION} (inappropriateAuthentication)
49{@link #INVALID_CREDENTIALS} (invalidCredentials)
50{@link #INSUFFICIENT_ACCESS_RIGHTS} (insufficientAccessRights)
51{@link #BUSY} (busy)
52{@link #UNAVAILABLE} (unavailable)
53{@link #UNWILLING_TO_PERFORM} (unwillingToPerform)
54{@link #LOOP_DETECT} (loopDetect)
64{@link #NAMING_VIOLATION} (namingViolation)
65{@link #OBJECT_CLASS_VIOLATION} (objectClassViolation)
66{@link #NOT_ALLOWED_ON_NONLEAF} (notAllowedOnNonLeaf)
67{@link #NOT_ALLOWED_ON_RDN} (notAllowedOnRDN)
68{@link #ENTRY_ALREADY_EXISTS} (entryAlreadyExists)
69{@link #OBJECT_CLASS_MODS_PROHIBITED} (objectClassModsProhibited)
71{@link #AFFECTS_MULTIPLE_DSAS} (affectsMultipleDSAs
80{@link #OTHER} (other)
Local errors, resulting from actions other than an operation on a server.
Value Result Code
81{@link #SERVER_DOWN}
82{@link #LOCAL_ERROR}
83{@link #ENCODING_ERROR}
84{@link #DECODING_ERROR}
85{@link #Ldap_TIMEOUT}
86{@link #AUTH_UNKNOWN}
87{@link #FILTER_ERROR}
88{@link #USER_CANCELLED}
90{@link #NO_MEMORY}
91{@link #CONNECT_ERROR}
92{@link #Ldap_NOT_SUPPORTED}
93{@link #CONTROL_NOT_FOUND}
94{@link #NO_RESULTS_RETURNED}
95{@link #MORE_RESULTS_TO_RETURN}
96{@link #CLIENT_LOOP}
97{@link #REFERRAL_LIMIT_EXCEEDED}
100{@link #INVALID_RESPONSE}
101{@link #AMBIGUOUS_RESPONSE}
112{@link #TLS_NOT_SUPPORTED}
Inheritance: System.Exception
Beispiel #1
0
        /// <summary> Checks the resultCode and throws the appropriate exception.
        ///
        /// </summary>
        /// <exception> LdapException A general exception which includes an error
        /// message and an Ldap error code.
        /// </exception>
        /* package */
        internal virtual void chkResultCode()
        {
            if (exception != null)
            {
                throw exception;
            }
            LdapException ex = ResultException;

            if (ex != null)
            {
                throw ex;
            }
        }
        /// <summary>
        ///     Collects batchSize elements from an LdapSearchQueue message
        ///     queue and places them in a Vector.
        ///     If the last message from the server,
        ///     the result message, contains an error, it will be stored in the Vector
        ///     for nextElement to process. (although it does not increment the search
        ///     result count) All search result entries will be placed in the Vector.
        ///     If a null is returned from getResponse(), it is likely that the search
        ///     was abandoned.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns>
        ///     true if all search results have been placed in the vector.
        /// </returns>
        private async Task <bool> GetBatchOfResultsAsync(CancellationToken cancellationToken)
        {
            LdapMessage msg;

            // <=batchSize so that we can pick up the result-done message
            for (var i = 0; i < _batchSize;)
            {
                try
                {
                    if ((msg = await _queue.GetResponse(cancellationToken).ConfigureAwait(false)) != null)
                    {
                        // Only save controls if there are some
                        var ctls = msg.Controls;
                        if (ctls != null)
                        {
                            ResponseControls = ctls;
                        }

                        if (msg is LdapSearchResult)
                        {
                            // Search Entry
                            object entry = ((LdapSearchResult)msg).Entry;
                            _entries.Add(entry);
                            i++;
                            _entryCount++;
                        }
                        else if (msg is LdapSearchResultReference)
                        {
                            // Search Ref
                            var refs = ((LdapSearchResultReference)msg).Referrals;

                            if (_cons.ReferralFollowing)
                            {
                                _referralConn = await _conn.ChaseReferralAsync(_queue, _cons, msg, refs, 0, true, _referralConn, cancellationToken).ConfigureAwait(false);
                            }
                            else
                            {
                                _references.Add(refs);
                                _referenceCount++;
                            }
                        }
                        else
                        {
                            // LdapResponse
                            var resp       = (LdapResponse)msg;
                            var resultCode = resp.ResultCode;

                            // Check for an embedded exception
                            if (resp.HasException())
                            {
                                // Fake it, results in an exception when msg read
                                resultCode = LdapException.ConnectError;
                            }

                            if (resultCode == LdapException.Referral && _cons.ReferralFollowing)
                            {
                                // Following referrals
                                _referralConn = await _conn.ChaseReferralAsync(_queue, _cons, resp, resp.Referrals, 0, false, _referralConn, cancellationToken : cancellationToken).ConfigureAwait(false);
                            }
                            else if (resultCode != LdapException.Success)
                            {
                                // Results in an exception when message read
                                _entries.Add(resp);
                                _entryCount++;
                            }

                            // We are done only when we have read all messages
                            // including those received from following referrals
                            var msgIDs   = _queue.MessageIDs;
                            var controls = _cons.GetControls();
                            if (msgIDs.Length == 0 && (controls == null || controls.Length == 0))
                            {
                                // Release referral exceptions
                                await _conn.ReleaseReferralConnections(_referralConn, cancellationToken).ConfigureAwait(false);

                                return(true); // search completed
                            }
                        }
                    }
                    else
                    {
                        // We get here if the connection timed out
                        // we have no responses, no message IDs and no exceptions
                        var e = new LdapException(null, LdapException.LdapTimeout, null);
                        _entries.Add(e);
                        break;
                    }
                }
                catch (LdapException e)
                {
                    // Hand exception off to user
                    _entries.Add(e);
                }
            }

            return(false); // search not completed
        }
Beispiel #3
0
        private void HandleLdapException(LdapException x) {
            switch (x.ResultCode) {
            case LdapException.Ldap_TIMEOUT:
                throw new TimeoutException("Ldap lookup timed out", x);
            case LdapException.OPERATIONS_ERROR:
            case LdapException.INVALID_DN_SYNTAX:
                if (x.ResultCode == 1 && x.LdapErrorMessage.Contains("DSID-0C090627"))
                    throw new DreamAbortException(DreamMessage.Forbidden(string.Format("Account '{0}' is disabled", this._username)));

                throw new ArgumentException(string.Format("The search base '{0}' may have invalid format (Example: 'DC=sales,DC=acme,DC=com') or the account used for binding may be disabled. Error returned from LDAP: {1}", _config.LdapSearchBase, x.LdapErrorMessage), x);
            default:
                throw x;
            }
        }
    protected void NotifyExceptionListeners(LdapMessage sourceMessage, LdapException ldapException)
    {
      if (null != directory_exception_event)
      {
	directory_exception_event(this, new DirectoryExceptionEventArgs(sourceMessage, ldapException));
      }
    }