/// <summary>
        ///     Constructs a sort control with multiple sort keys.
        /// </summary>
        /// <param name="keys		An">
        ///     array of sort key objects, to be processed in
        ///     order.
        /// </param>
        /// <param name="critical	True">
        ///     if the search operation is to fail if the
        ///     server does not support this control.
        /// </param>
        public LdapSortControl(LdapSortKey[] keys, bool critical) : base(requestOID, critical, null)
        {
            var sortKeyList = new Asn1SequenceOf();

            for (var i = 0; i < keys.Length; i++)
            {
                var key = new Asn1Sequence();

                key.add(new Asn1OctetString(keys[i].Key));

                if ((object)keys[i].MatchRule != null)
                {
                    key.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, ORDERING_RULE),
                                           new Asn1OctetString(keys[i].MatchRule), false));
                }

                if (keys[i].Reverse)
                {
                    // only add if true
                    key.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, REVERSE_ORDER),
                                           new Asn1Boolean(true), false));
                }

                sortKeyList.add(key);
            }

            setValue(sortKeyList.getEncoding(new LBEREncoder()));
        }
예제 #2
0
        /// <summary> Encode an array of LdapModifications to ASN.1.
        ///
        /// </summary>
        /// <param name="mods">an array of LdapModification objects
        ///
        /// </param>
        /// <returns> an Asn1SequenceOf object containing the modifications.
        /// </returns>
        static private Asn1SequenceOf encodeModifications(LdapModification[] mods)
        {
            // Convert Java-API LdapModification[] to RFC2251 SEQUENCE OF SEQUENCE
            Asn1SequenceOf rfcMods = new Asn1SequenceOf(mods.Length);

            for (int i = 0; i < mods.Length; i++)
            {
                LdapAttribute attr = mods[i].Attribute;

                // place modification attribute values in Asn1SetOf
                Asn1SetOf vals = new Asn1SetOf(attr.size());
                if (attr.size() > 0)
                {
                    System.Collections.IEnumerator attrEnum = attr.ByteValues;
                    while (attrEnum.MoveNext())
                    {
                        vals.add(new RfcAttributeValue((sbyte[])attrEnum.Current));
                    }
                }

                // create SEQUENCE containing mod operation and attr type and vals
                Asn1Sequence rfcMod = new Asn1Sequence(2);
                rfcMod.add(new Asn1Enumerated(mods[i].Op));
                rfcMod.add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr.Name), vals));

                // place SEQUENCE into SEQUENCE OF
                rfcMods.add(rfcMod);
            }
            return(rfcMods);
        }
예제 #3
0
        /// <summary>
        /// Constructs an extended operations object which contains the ber encoded
        /// replication filter.
        ///
        /// </summary>
        /// <param name="serverDN">The server on which the replication filter needs to be set
        ///
        /// </param>
        /// <param name="replicationFilter">An array of String Arrays. Each array starting with
        /// a class name followed by the attribute names for that class that should comprise
        /// the replication filter.
        ///
        /// </param>
        /// <exception> LdapException A general exception which includes an error
        /// message and an Ldap error code.
        /// </exception>
        public SetReplicationFilterRequest(System.String serverDN, System.String[][] replicationFilter) : base(ReplicationConstants.SET_REPLICATION_FILTER_REQ, null)
        {
            try
            {
                if ((System.Object)serverDN == null)
                {
                    throw new System.ArgumentException(ExceptionMessages.PARAM_ERROR);
                }

                System.IO.MemoryStream encodedData = new System.IO.MemoryStream();
                LBEREncoder            encoder     = new LBEREncoder();

                Asn1OctetString asn1_serverDN = new Asn1OctetString(serverDN);

                // Add the serverDN to encoded data
                asn1_serverDN.encode(encoder, encodedData);

                // The toplevel sequenceOF
                Asn1SequenceOf asn1_replicationFilter = new Asn1SequenceOf();

                if (replicationFilter == null)
                {
                    asn1_replicationFilter.encode(encoder, encodedData);
                    setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
                    return;
                }

                int i = 0;
                // for every element in the array
                while ((i < replicationFilter.Length) && (replicationFilter[i] != null))
                {
                    // The following additional Sequence is not needed
                    // as defined by the Asn1. But the server and the
                    // C client are encoding it. Remove this when server
                    // and C client are fixed to conform to the published Asn1.
                    Asn1Sequence buginAsn1Representation = new Asn1Sequence();

                    // Add the classname to the sequence -
                    buginAsn1Representation.add(new Asn1OctetString(replicationFilter[i][0]));

                    // Start a sequenceOF for attributes
                    Asn1SequenceOf asn1_attributeList = new Asn1SequenceOf();

                    // For every attribute in the array - remember attributes start after
                    // the first element
                    int j = 1;
                    while ((j < replicationFilter[i].Length) && ((System.Object)replicationFilter[i][j] != null))
                    {
                        // Add the attribute name to the inner SequenceOf
                        asn1_attributeList.add(new Asn1OctetString(replicationFilter[i][j]));
                        j++;
                    }


                    // Add the attributeList to the sequence - extra add due to bug
                    buginAsn1Representation.add(asn1_attributeList);
                    asn1_replicationFilter.add(buginAsn1Representation);
                    i++;
                }

                asn1_replicationFilter.encode(encoder, encodedData);
                setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
            }
            catch (System.IO.IOException ioe)
            {
                throw new LdapException(ExceptionMessages.ENCODING_ERROR, LdapException.ENCODING_ERROR, (System.String)null);
            }
        }