A mechanism for queuing asynchronous search results received from a server.
Inheritance: LdapMessageQueue
コード例 #1
0
        /// <summary> Merges two message queues.  It appends the current and
        /// future contents from another queue to this one.
        ///
        /// After the operation, queue2.getMessageIDs()
        /// returns an empty array, and its outstanding responses
        /// have been removed and appended to this queue.
        ///
        /// </summary>
        /// <param name="queue2">   The queue that is merged from.  Following
        /// the merge, this queue object will no
        /// longer receive any data, and calls made
        /// to its methods will fail with a RuntimeException.
        /// The queue can be reactivated by using it in an
        /// Ldap request, after which it will receive responses
        /// for that request..
        /// </param>
        public virtual void  merge(LdapMessageQueue queue2)
        {
            LdapSearchQueue q = (LdapSearchQueue)queue2;

            agent.merge(q.MessageAgent);

            return;
        }
コード例 #2
0
        private int _referenceIndex; // Current position in vector

        // private ArrayList referralConn = null; // Referral Connections

        /// <summary>
        ///     Constructs a queue object for search results.
        /// </summary>
        /// <param name="queue">
        ///     The queue for the search results.
        /// </param>
        /// <param name="cons">
        ///     The LdapSearchConstraints associated with this search.
        /// </param>
        internal LdapSearchResults(LdapSearchQueue queue, LdapSearchConstraints cons)
        {
            // setup entry Vector
            _cons = cons;
            var requestedBatchSize = cons.BatchSize;
            _entries = new ArrayList(requestedBatchSize == 0 ? 64 : requestedBatchSize);
            _entryCount = 0;
            _entryIndex = 0;

            // setup search reference Vector
            _references = new List<string[]>(5);
            _referenceCount = 0;
            _referenceIndex = 0;

            _queue = queue;
            _batchSize = requestedBatchSize == 0 ? int.MaxValue : requestedBatchSize;
        }
コード例 #3
0
        private readonly LdapSearchConstraints cons; // LdapSearchConstraints for search
        //private ArrayList referralConn = null; // Referral Connections

        /// <summary>
        ///     Constructs a queue object for search results.
        /// </summary>
        /// <param name="conn">
        ///     The LdapConnection which initiated the search
        /// </param>
        /// <param name="queue">
        ///     The queue for the search results.
        /// </param>
        /// <param name="cons">
        ///     The LdapSearchConstraints associated with this search
        /// </param>
        internal LdapSearchResults(LdapConnection conn, LdapSearchQueue queue, LdapSearchConstraints cons)
        {
            // setup entry Vector
            this.cons = cons;
            var requestedBatchSize = cons.BatchSize;

            entries    = new ArrayList(requestedBatchSize == 0 ? 64 : requestedBatchSize);
            entryCount = 0;
            entryIndex = 0;

            // setup search reference Vector
            references     = new ArrayList(5);
            referenceCount = 0;
            referenceIndex = 0;

            this.queue     = queue;
            this.batchSize = requestedBatchSize == 0 ? int.MaxValue : requestedBatchSize;
        }
コード例 #4
0
ファイル: LdapSearchResults.cs プロジェクト: cmsd2/oidc
        private System.Collections.ArrayList referralConn = null; // Referral Connections

        /// <summary> Constructs a queue object for search results.
        ///
        /// </summary>
        /// <param name="conn">The LdapConnection which initiated the search
        ///
        /// </param>
        /// <param name="queue">The queue for the search results.
        ///
        /// </param>
        /// <param name="cons">The LdapSearchConstraints associated with this search
        /// </param>
        /* package */
        internal LdapSearchResults(LdapConnection conn, LdapSearchQueue queue, LdapSearchConstraints cons)
        {
            // setup entry Vector
            this.conn = conn;
            this.cons = cons;
            int batchSize  = cons.BatchSize;
            int vectorIncr = (batchSize == 0) ? 64 : 0;

            entries    = new System.Collections.ArrayList((batchSize == 0) ? 64 : batchSize);
            entryCount = 0;
            entryIndex = 0;

            // setup search reference Vector
            references     = new System.Collections.ArrayList(5);
            referenceCount = 0;
            referenceIndex = 0;

            this.queue     = queue;
            this.batchSize = (batchSize == 0) ? Int32.MaxValue : batchSize;
        }
コード例 #5
0
ファイル: LdapSearchResults.cs プロジェクト: nickchal/pash
		private System.Collections.ArrayList referralConn = null; // Referral Connections
		
		/// <summary> Constructs a queue object for search results.
		/// 
		/// </summary>
		/// <param name="conn">The LdapConnection which initiated the search
		/// 
		/// </param>
		/// <param name="queue">The queue for the search results.
		/// 
		/// </param>
		/// <param name="cons">The LdapSearchConstraints associated with this search
		/// </param>
		/* package */
		internal LdapSearchResults(LdapConnection conn, LdapSearchQueue queue, LdapSearchConstraints cons)
		{
			// setup entry Vector
			this.conn = conn;
			this.cons = cons;
			int batchSize = cons.BatchSize;
			int vectorIncr = (batchSize == 0)?64:0;
			entries = new System.Collections.ArrayList((batchSize == 0)?64:batchSize);
			entryCount = 0;
			entryIndex = 0;
			
			// setup search reference Vector
			references = new System.Collections.ArrayList(5);
			referenceCount = 0;
			referenceIndex = 0;
			
			this.queue = queue;
			this.batchSize = (batchSize == 0)?System.Int32.MaxValue:batchSize;
			
			return ;
		}
コード例 #6
0
		/// <summary> Sends an Ldap request to a directory server.
		/// 
		/// The specified the Ldap request is sent to the directory server
		/// associated with this connection. An Ldap request object is an
		/// {@link LdapMessage} with the operation type set to one of the request
		/// types. You can build a request by using the request classes found in this
		/// package
		/// 
		/// You should note that, since Ldap requests sent to the server
		/// using sendRequest are asynchronous, automatic referral following
		/// does not apply to these requests.
		/// 
		/// </summary>
		/// <param name="request">The Ldap request to send to the directory server.
		/// </param>
		/// <param name="queue">   The queue for messages returned from a server in
		/// response to this request. If it is null, a
		/// queue object is created internally.
		/// </param>
		/// <param name="cons">   The constraints that apply to this request
		/// </param>
		/// <exception>     LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// 
		/// </exception>
		/// <seealso cref="LdapMessage.Type">
		/// </seealso>
		/// <seealso cref="RfcLdapMessage.isRequest">
		/// </seealso>
		public virtual LdapMessageQueue SendRequest(LdapMessage request, LdapMessageQueue queue, LdapConstraints cons)
		{
			
			
			if (!request.Request)
			{
				throw new System.SystemException("Object is not a request message");
			}
			
			if (cons == null)
			{
				cons = defSearchCons;
			}
			
			// Get the correct queue for a search request
			MessageAgent agent;
			LdapMessageQueue myqueue = queue;
			if (myqueue == null)
			{
				agent = new MessageAgent();
				if (request.Type == LdapMessage.SEARCH_REQUEST)
				{
					myqueue = new LdapSearchQueue(agent);
				}
				else
				{
					myqueue = new LdapResponseQueue(agent);
				}
			}
			else
			{
				if (request.Type == LdapMessage.SEARCH_REQUEST)
				{
					agent = queue.MessageAgent;
				}
				else
				{
					agent = queue.MessageAgent;
				}
			}
			
			try
			{
				agent.sendMessage(conn, request, cons.TimeLimit, myqueue, null);
			}
			catch (LdapException lex)
			{
				throw lex;
			}
			return myqueue;
		}
コード例 #7
0
		/// <summary> Asynchronously performs the search specified by the parameters,
		/// also allowing specification of constraints for the search (such
		/// as the maximum number of entries to find or the maximum time to
		/// wait for search results).
		/// 
		/// </summary>
		/// <param name="base">          The base distinguished name to search from.
		/// 
		/// </param>
		/// <param name="scope">         The scope of the entries to search. The following
		/// are the valid options:
		/// <ul>
		/// <li>SCOPE_BASE - searches only the base DN</li>
		/// 
		/// <li>SCOPE_ONE - searches only entries under the base DN</li>
		/// 
		/// <li>SCOPE_SUB - searches the base DN and all entries
		/// within its subtree</li>
		/// </ul>
		/// </param>
		/// <param name="filter">        The search filter specifying the search criteria.
		/// 
		/// </param>
		/// <param name="attrs">         The names of attributes to retrieve.
		/// 
		/// </param>
		/// <param name="typesOnly">     If true, returns the names but not the values of
		/// the attributes found.  If false, returns the
		/// names and values for attributes found.
		/// 
		/// </param>
		/// <param name="queue">         The queue for messages returned from a server in
		/// response to this request. If it is null, a
		/// queue object is created internally.
		/// 
		/// </param>
		/// <param name="cons">          The constraints specific to the search.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual LdapSearchQueue Search(System.String base_Renamed, int scope, System.String filter, System.String[] attrs, bool typesOnly, LdapSearchQueue queue, LdapSearchConstraints cons)
		{
			if ((System.Object) filter == null)
			{
				filter = "objectclass=*";
			}
			if (cons == null)
				cons = defSearchCons;
			
			LdapMessage msg = new LdapSearchRequest(base_Renamed, scope, filter, attrs, cons.Dereference, cons.MaxResults, cons.ServerTimeLimit, typesOnly, cons.getControls());
			MessageAgent agent;
			LdapSearchQueue myqueue = queue;
			if (myqueue == null)
			{
				agent = new MessageAgent();
				myqueue = new LdapSearchQueue(agent);
			}
			else
			{
				agent = queue.MessageAgent;
			}
			
			try
			{
				agent.sendMessage(conn, msg, cons.TimeLimit, myqueue, null);
			}
			catch (LdapException lex)
			{
				throw lex;
			}
			return myqueue;
		}
コード例 #8
0
		/// <summary> Asynchronously performs the search specified by the parameters.
		/// 
		/// </summary>
		/// <param name="base">          The base distinguished name to search from.
		/// 
		/// </param>
		/// <param name="scope">         The scope of the entries to search. The following
		/// are the valid options:
		/// <ul>
		/// <li>SCOPE_BASE - searches only the base DN</li>
		/// 
		/// <li>SCOPE_ONE - searches only entries under the base DN</li>
		/// 
		/// <li>SCOPE_SUB - searches the base DN and all entries
		/// within its subtree</li>
		/// </ul>
		/// </param>
		/// <param name="filter">        Search filter specifying the search criteria.
		/// 
		/// </param>
		/// <param name="attrs">         Names of attributes to retrieve.
		/// 
		/// </param>
		/// <param name="typesOnly">     If true, returns the names but not the values of
		/// the attributes found.  If false, returns the
		/// names and values for attributes found.
		/// 
		/// </param>
		/// <param name="queue">         Handler for messages returned from a server in
		/// response to this request. If it is null, a
		/// queue object is created internally.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual LdapSearchQueue Search(System.String base_Renamed, int scope, System.String filter, System.String[] attrs, bool typesOnly, LdapSearchQueue queue)
		{
			return Search(base_Renamed, scope, filter, attrs, typesOnly, queue, defSearchCons);
		}
コード例 #9
0
        /// <summary> Check the queue for a response. If a response has been received,
        /// print the response information.
        /// </summary>
        private static bool checkForAChange(LdapSearchQueue queue)
        {
            LdapMessage message;
            bool result = true;
            try
            {
                //check if a response has been received so we don't block
                //when calling getResponse()
                if (queue.isResponseReceived())
                {
                    message = queue.getResponse();
                    if (message != null)
                    {
                        // is the response a search result reference?
                        if (message is LdapSearchResultReference)
                        {
                            String[] urls = ((LdapSearchResultReference) message).Referrals;
                            Console.Out.WriteLine("\nSearch result references:");
                            for (int i = 0; i < urls.Length; i++)
                                Console.Out.WriteLine(urls[i]);
                        }
                            // is the response a search result?
                        else if (message is LdapSearchResult)
                        {
                            LdapControl[] controls = message.Controls;
                            for (int i = 0; i < controls.Length; i++)
                            {
                                if (controls[i] is LdapEntryChangeControl)
                                {
                                    LdapEntryChangeControl ecCtrl = (LdapEntryChangeControl) controls[i];

                                    int changeType = ecCtrl.ChangeType;
                                        Console.Out.WriteLine("\n\nchange type: " + getChangeTypeString(changeType));
                                    if (changeType == LdapPersistSearchControl.MODDN)
                                        Console.Out.WriteLine("Prev. DN: " + ecCtrl.PreviousDN);
                                    if (ecCtrl.HasChangeNumber)
                                        Console.Out.WriteLine("Change Number: " + ecCtrl.ChangeNumber);

                                    LdapEntry entry = ((LdapSearchResult) message).Entry;

                                    Console.Out.WriteLine("entry: " + entry.DN);
                                }
                            }
                        }
                            // the message is a search response
                        else
                        {
                            LdapResponse response = (LdapResponse) message;
                            int resultCode = response.ResultCode;
                            if (resultCode == LdapException.SUCCESS)
                            {
                                Console.Out.WriteLine("\nUnexpected success response.");
                                result = false;
                            }
                            else if (resultCode == LdapException.REFERRAL)
                            {
                                String[] urls = ((LdapResponse) message).Referrals;
                                Console.Out.WriteLine("\n\nReferrals:");
                                for (int i = 0; i < urls.Length; i++)
                                    Console.Out.WriteLine(urls[i]);
                            }
                            else
                            {
                                Console.Out.WriteLine("Persistent search failed.");
                                throw new LdapException(response.ErrorMessage, resultCode, response.MatchedDN);
                            }
                        }
                    }
                }
            }
            catch (LdapException e)
            {
                Console.Out.WriteLine("Error: " + e.ToString());
                result = false;
            }

            return result;
        }