/// <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) { LdapResponseQueue q = (LdapResponseQueue)queue2; agent.merge(q.MessageAgent); return; }
/// <summary> Asynchronously renames an existing entry in the directory, using the /// specified constraints. /// /// </summary> /// <param name="dn"> The current distinguished name of the entry. /// /// </param> /// <param name="newRdn"> The new relative distinguished name for the entry. /// /// </param> /// <param name="deleteOldRdn"> If true, the old name is not retained as an /// attribute value. If false, the old name is /// retained as an attribute value. /// /// </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 operation. /// /// </param> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue Rename(System.String dn, System.String newRdn, bool deleteOldRdn, LdapResponseQueue queue, LdapConstraints cons) { return Rename(dn, newRdn, null, deleteOldRdn, queue, cons); }
/// <summary> Asynchronously makes a set of changes to an existing entry in the /// directory, using the specified constraints and queue. /// /// For example, this modify method can change attribute values, add new /// attribute values, or remove existing attribute values. /// /// Because the server applies all changes in an LdapModification array /// atomically, the application can expect that no changes /// have been performed if an error is returned. /// If the request fails with {@link LdapException.CONNECT_ERROR}, /// it is indeterminate whether or not the server made the modifications. /// /// </summary> /// <param name="dn"> The distinguished name of the entry to modify. /// /// </param> /// <param name="mods"> The changes to be made to the entry. /// /// </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"> Constraints specific to the operation. /// /// </param> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue Modify(System.String dn, LdapModification[] mods, LdapResponseQueue queue, LdapConstraints cons) { if ((System.Object) dn == null) { // Invalid DN parameter throw new System.ArgumentException(ExceptionMessages.DN_PARAM_ERROR); } if (cons == null) cons = defSearchCons; LdapMessage msg = new LdapModifyRequest(dn, mods, cons.getControls()); return SendRequestToServer(msg, cons.TimeLimit, queue, null); }
/// <summary> Asynchronously makes a set of changes to an existing entry in the /// directory. /// /// For example, this modify method can change attribute values, add new /// attribute values, or remove existing attribute values. /// /// Because the server applies all changes in an LdapModification array /// atomically, the application can expect that no changes /// have been performed if an error is returned. /// If the request fails with {@link LdapException.CONNECT_ERROR}, /// it is indeterminate whether or not the server made the modifications. /// /// </summary> /// <param name="dn"> The distinguished name of the entry to modify. /// /// </param> /// <param name="mods"> The changes to be made to the entry. /// /// </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> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue Modify(System.String dn, LdapModification[] mods, LdapResponseQueue queue) { return Modify(dn, mods, queue, defSearchCons); }
/// <summary> Asynchronously makes a single change to an existing entry in the /// directory, using the specified constraints and queue. /// /// For example, this modify method can change the value of an attribute, /// add a new attribute value, or remove an existing attribute value. /// /// The LdapModification object specifies both the change to be made /// and the LdapAttribute value to be changed. /// /// If the request fails with {@link LdapException.CONNECT_ERROR}, /// it is indeterminate whether or not the server made the modification. /// /// </summary> /// <param name="dn"> Distinguished name of the entry to modify. /// /// </param> /// <param name="mod"> A single change to be made to the entry. /// /// </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> /// <param name="cons"> Constraints specific to the operation. /// /// </param> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue Modify(System.String dn, LdapModification mod, LdapResponseQueue queue, LdapConstraints cons) { LdapModification[] mods = new LdapModification[1]; mods[0] = mod; return Modify(dn, mods, queue, cons); }
/* * Asynchronous Ldap extended request with SearchConstraints */ /// <summary> Provides an asynchronous means to access extended, non-mandatory /// operations offered by a particular Ldapv3 compliant server. /// /// </summary> /// <param name="op"> The object which contains (1) an identifier of an extended /// operation which should be recognized by the particular Ldap /// server this client is connected to and (2) an operation- /// specific sequence of octet strings or BER-encoded values. /// /// </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 this operation. /// /// </param> /// <returns> An operation-specific object, containing an ID and either an /// octet string or BER-encoded values. /// /// </returns> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue ExtendedOperation(LdapExtendedOperation op, LdapConstraints cons, LdapResponseQueue queue) { // Use default constraints if none-specified if (cons == null) cons = defSearchCons; LdapMessage msg = MakeExtendedOperation(op, cons); return SendRequestToServer(msg, cons.TimeLimit, queue, null); }
public virtual LdapResponseQueue Bind(int version, System.String dn, sbyte[] passwd, LdapResponseQueue queue, LdapConstraints cons) { int msgId; BindProperties bindProps; if (cons == null) cons = defSearchCons; if ((System.Object) dn == null) { dn = ""; } else { dn = dn.Trim(); } if (passwd == null) passwd = new sbyte[]{}; bool anonymous = false; if (passwd.Length == 0) { anonymous = true; // anonymous, passwd length zero with simple bind dn = ""; // set to null if anonymous } LdapMessage msg = new LdapBindRequest(version, dn, passwd, cons.getControls()); msgId = msg.MessageID; bindProps = new BindProperties(version, dn, "simple", anonymous, null, null); // For bind requests, if not connected, attempt to reconnect if (!conn.Connected) { if ((System.Object) conn.Host != null) { conn.connect(conn.Host, conn.Port); } else { throw new LdapException(ExceptionMessages.CONNECTION_IMPOSSIBLE, LdapException.CONNECT_ERROR, null); } } // The semaphore is released when the bind response is queued. conn.acquireWriteSemaphore(msgId); return SendRequestToServer(msg, cons.TimeLimit, queue, bindProps); }
/// <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; }
/// <summary> Asynchronously compares an attribute value with one in the directory, /// using the specified queue and contraints. /// /// Please note that a successful completion of this command results in /// one of two status codes: LdapException.COMPARE_TRUE if the entry /// has the value, and LdapException.COMPARE_FALSE if the entry /// does not have the value or the attribute. /// /// </summary> /// <param name="dn"> The distinguished name of the entry containing an /// attribute to compare. /// /// </param> /// <param name="attr"> An attribute to compare. /// /// </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> /// <param name="cons"> Constraints specific to the operation. /// /// </param> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// /// </exception> /// <seealso cref="LdapException.COMPARE_TRUE"> /// </seealso> /// <seealso cref="LdapException.COMPARE_FALSE"> /// </seealso> public virtual LdapResponseQueue Compare(System.String dn, LdapAttribute attr, LdapResponseQueue queue, LdapConstraints cons) { if (attr.size() != 1) { throw new System.ArgumentException("compare: Exactly one value " + "must be present in the LdapAttribute"); } if ((System.Object) dn == null) { // Invalid parameter throw new System.ArgumentException("compare: DN cannot be null"); } if (cons == null) cons = defSearchCons; LdapMessage msg = new LdapCompareRequest(dn, attr.Name, attr.ByteValue, cons.getControls()); return SendRequestToServer(msg, cons.TimeLimit, queue, null); }
/// <summary> Asynchronously compares an attribute value with one in the directory, /// using the specified queue. /// /// Please note that a successful completion of this command results in /// one of two status codes: LdapException.COMPARE_TRUE if the entry /// has the value, and LdapException.COMPARE_FALSE if the entry /// does not have the value or the attribute. /// /// </summary> /// <param name="dn"> The distinguished name of the entry containing an /// attribute to compare. /// /// </param> /// <param name="attr"> An attribute to compare. /// /// </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> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// /// </exception> /// <seealso cref="LdapException.COMPARE_TRUE"> /// </seealso> /// <seealso cref="LdapException.COMPARE_FALSE"> /// </seealso> public virtual LdapResponseQueue Compare(System.String dn, LdapAttribute attr, LdapResponseQueue queue) { return Compare(dn, attr, queue, defSearchCons); }
public virtual LdapResponseQueue Bind(int version, System.String dn, sbyte[] passwd, LdapResponseQueue queue, LdapConstraints cons, string mech) { int msgId; BindProperties bindProps; if (cons == null) cons = defSearchCons; if ((System.Object) dn == null) { dn = ""; } else { dn = dn.Trim(); } if (passwd == null) passwd = new sbyte[]{}; bool anonymous = false; if (passwd.Length == 0) { anonymous = true; // anonymous, passwd length zero with simple bind dn = ""; // set to null if anonymous } LdapMessage msg; #if TARGET_JVM if (mech != null) msg = new LdapBindRequest(version, "", mech, passwd, cons.getControls()); else #endif msg = new LdapBindRequest(version, dn, passwd, cons.getControls()); msgId = msg.MessageID; bindProps = new BindProperties(version, dn, "simple", anonymous, null, null); // For bind requests, if not connected, attempt to reconnect if (!conn.Connected) { if ((System.Object) conn.Host != null) { conn.connect(conn.Host, conn.Port); } else { throw new LdapException(ExceptionMessages.CONNECTION_IMPOSSIBLE, LdapException.CONNECT_ERROR, null); } } #if TARGET_JVM // stopping reader to enable stream replace after secure binding is complete, see Connection.ReplaceStreams() if (mech != null) { if (conn.BindSemIdClear) { // need to acquire a semaphore only if bindSemId is clear // because if we receive SASL_BIND_IN_PROGRESS the semaphore is not // released when the response is queued conn.acquireWriteSemaphore(msgId); conn.BindSemId = msgId; } conn.stopReaderOnReply(msgId); } else #endif // The semaphore is released when the bind response is queued. conn.acquireWriteSemaphore(msgId); return SendRequestToServer(msg, cons.TimeLimit, queue, bindProps); }
public virtual LdapResponseQueue Bind(int version, System.String dn, sbyte[] passwd, LdapResponseQueue queue) { return Bind(version, dn, passwd, queue, defSearchCons, null); }
/// <summary> Asynchronously adds an entry to the directory, using the specified /// constraints. /// /// </summary> /// <param name="entry"> LdapEntry object specifying the distinguished /// name and attributes of the new entry. /// /// </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> /// <param name="cons"> Constraints specific to the operation. /// /// </param> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue Add(LdapEntry entry, LdapResponseQueue queue, LdapConstraints cons) { if (cons == null) cons = defSearchCons; // error check the parameters if (entry == null) { throw new System.ArgumentException("The LdapEntry parameter" + " cannot be null"); } if ((System.Object) entry.DN == null) { throw new System.ArgumentException("The DN value must be present" + " in the LdapEntry object"); } LdapMessage msg = new LdapAddRequest(entry, cons.getControls()); return SendRequestToServer(msg, cons.TimeLimit, queue, null); }
/// <summary> Asynchronously adds an entry to the directory. /// /// </summary> /// <param name="entry"> LdapEntry object specifying the distinguished /// name and attributes of the new entry. /// /// </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 LdapResponseQueue Add(LdapEntry entry, LdapResponseQueue queue) { return Add(entry, queue, defSearchCons); }
/** * Check the queue for a response. If a response has been received, * print the response information. */ private static bool checkForAChange(LdapResponseQueue 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 MonitorEventResponse) { MonitorEventResponse eventerrorresponse = (MonitorEventResponse) message; Console.WriteLine("\nError in Registration ResultCode = " + eventerrorresponse.ResultCode); EdirEventSpecifier[] specifiers = eventerrorresponse.SpecifierList; for (int i = 0; i < specifiers.Length; i++) { Console.WriteLine("Specifier:" + "EventType = " + specifiers[i].EventType); } Environment.Exit(-1); } // is the response a event response ? else if ( message is EdirEventIntermediateResponse) { Console.WriteLine("Edir Event Occured"); EdirEventIntermediateResponse eventresponse = (EdirEventIntermediateResponse) message; //process the eventresponse Data, depending on the // type of response processEventData(eventresponse.EventResponseDataObject, eventresponse.EventType); } // the message is a Unknown response else { Console.WriteLine("UnKnown Message =" + message); } } } } catch (LdapException e) { Console.WriteLine("Error: " + e.ToString()); result = false; } return result; }
/// <summary> Asynchronously renames an existing entry in the directory, possibly /// repositioning the entry in the directory. /// /// </summary> /// <param name="dn"> The current distinguished name of the entry. /// /// </param> /// <param name="newRdn"> The new relative distinguished name for the entry. /// /// </param> /// <param name="newParentdn"> The distinguished name of an existing entry which /// is to be the new parent of the entry. /// /// </param> /// <param name="deleteOldRdn"> If true, the old name is not retained as an /// attribute value. If false, the old name is /// retained as an attribute value. /// /// </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> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue Rename(System.String dn, System.String newRdn, System.String newParentdn, bool deleteOldRdn, LdapResponseQueue queue) { return Rename(dn, newRdn, newParentdn, deleteOldRdn, queue, defSearchCons); }
/// <summary> Asynchronously renames an existing entry in the directory, using the /// specified constraints and possibily repositioning the entry in the /// directory. /// /// </summary> /// <param name="dn"> The current distinguished name of the entry. /// /// </param> /// <param name="newRdn"> The new relative distinguished name for the entry. /// /// </param> /// <param name="newParentdn"> The distinguished name of an existing entry which /// is to be the new parent of the entry. /// /// </param> /// <param name="deleteOldRdn"> If true, the old name is not retained as an /// attribute value. If false, the old name is /// retained as an attribute value. /// /// </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 operation. /// /// </param> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue Rename(System.String dn, System.String newRdn, System.String newParentdn, bool deleteOldRdn, LdapResponseQueue queue, LdapConstraints cons) { if ((System.Object) dn == null || (System.Object) newRdn == null) { // Invalid DN or RDN parameter throw new System.ArgumentException(ExceptionMessages.RDN_PARAM_ERROR); } if (cons == null) cons = defSearchCons; LdapMessage msg = new LdapModifyDNRequest(dn, newRdn, newParentdn, deleteOldRdn, cons.getControls()); return SendRequestToServer(msg, cons.TimeLimit, queue, null); }
/// <summary> Asynchronously deletes the entry with the specified distinguished name /// from the directory and returns the results to the specified queue. /// /// Note: A Delete operation will not remove an entry that contains /// subordinate entries, nor will it dereference alias entries. /// /// </summary> /// <param name="dn"> The distinguished name of the entry to modify. /// /// </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> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// /// </exception> public virtual LdapResponseQueue Delete(System.String dn, LdapResponseQueue queue) { return Delete(dn, queue, defSearchCons); }
//************************************************************************* // helper methods //************************************************************************* /// <summary> Locates the appropriate message agent and sends /// the Ldap request to a directory server. /// /// </summary> /// <param name="msg">the message to send /// /// </param> /// <param name="timeout">the timeout value /// /// </param> /// <param name="queue">the response queue or null /// /// </param> /// <returns> the LdapResponseQueue for this request /// /// </returns> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> private LdapResponseQueue SendRequestToServer(LdapMessage msg, int timeout, LdapResponseQueue queue, BindProperties bindProps) { MessageAgent agent; if (queue == null) { agent = new MessageAgent(); queue = new LdapResponseQueue(agent); } else { agent = queue.MessageAgent; } agent.sendMessage(conn, msg, timeout, queue, bindProps); return queue; }
/* * Asynchronous Ldap extended request */ /// <summary> Provides an asynchronous means to access extended, non-mandatory /// operations offered by a particular Ldapv3 compliant server. /// /// </summary> /// <param name="op"> The object which contains (1) an identifier of an extended /// operation which should be recognized by the particular Ldap /// server this client is connected to and (2) an /// operation-specific sequence of octet strings /// or BER-encoded values. /// /// </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> /// <returns> An operation-specific object, containing an ID and either an octet /// string or BER-encoded values. /// /// </returns> /// <exception> LdapException A general exception which includes an error /// message and an Ldap error code. /// </exception> public virtual LdapResponseQueue ExtendedOperation(LdapExtendedOperation op, LdapResponseQueue queue) { return ExtendedOperation(op, defSearchCons, queue); }