Esempio n. 1
0
 public void AddRange(DirectoryAttribute[] attributes)
 {
     if (attributes != null)
     {
         DirectoryAttribute[] directoryAttributeArray = attributes;
         int num = 0;
         while (num < (int)directoryAttributeArray.Length)
         {
             DirectoryAttribute directoryAttribute = directoryAttributeArray[num];
             if (directoryAttribute != null)
             {
                 num++;
             }
             else
             {
                 throw new ArgumentException(Res.GetString("NullDirectoryAttributeCollection"));
             }
         }
         base.InnerList.AddRange(attributes);
         return;
     }
     else
     {
         throw new ArgumentNullException("attributes");
     }
 }
		public void AddRange(DirectoryAttribute[] attributes)
		{
			if (attributes != null)
			{
				DirectoryAttribute[] directoryAttributeArray = attributes;
				int num = 0;
				while (num < (int)directoryAttributeArray.Length)
				{
					DirectoryAttribute directoryAttribute = directoryAttributeArray[num];
					if (directoryAttribute != null)
					{
						num++;
					}
					else
					{
						throw new ArgumentException(Res.GetString("NullDirectoryAttributeCollection"));
					}
				}
				base.InnerList.AddRange(attributes);
				return;
			}
			else
			{
				throw new ArgumentNullException("attributes");
			}
		}
        /// <summary>
        /// Get LDAP attribute string representation.
        /// </summary>
        /// <param name="attribute">LDAP attribute</param>
        /// <param name="replaceInvalidCharacters">Replace invalid characters in result.</param>
        public static string GetAttributeString(DirectoryAttribute attribute, bool replaceInvalidCharacters = false)
        {
            if (attribute != null)
            {
                var builder = new StringBuilder();

                for (int i = 0; i < attribute.Count; i++)
                {
                    if (attribute[i] is string)
                    {
                        builder.Append((string)attribute[i]);
                    }
                    else if (attribute[i] is byte[])
                    {
                        builder.Append(ToHexString((byte[])attribute[i]));
                    }
                    else
                    {
                        throw new InvalidOperationException("Unexpected type for attribute value: " + attribute[i].GetType().Name);
                    }
                }

                // Replace invalid characters
                return replaceInvalidCharacters ? Regex.Replace(builder.ToString(), "[^\\p{L}0-9_.-]+", "_") : builder.ToString();
            }

            return null;
        }
Esempio n. 4
0
 public int Add(DirectoryAttribute attribute)
 {
     if (attribute == null)
     {
         throw new ArgumentException(Res.GetString("NullDirectoryAttributeCollection"));
     }
     return(base.List.Add(attribute));
 }
 public void Insert(int index, DirectoryAttribute value)
 {
     if (value == null)
     {
         throw new ArgumentException(Res.GetString("NullDirectoryAttributeCollection"));
     }
     base.List.Insert(index, value);
 }
Esempio n. 6
0
        public bool LadpAdd(string strOU, DirectoryAttribute[] dirAttrList1)
        {

            string strOU1 = strOU + "," + m_TargetOU;
            AddRequest addRequest = new AddRequest(strOU1, dirAttrList1);
            m_LdapConnection.SendRequest(addRequest);
            return true;
        }
Esempio n. 7
0
 public void Insert(int index, DirectoryAttribute value)
 {
     if (value == null)
     {
         throw new ArgumentException(Res.GetString("NullDirectoryAttributeCollection"));
     }
     base.List.Insert(index, value);
 }
 public int Add(DirectoryAttribute attribute)
 {
     if (attribute == null)
     {
         throw new ArgumentException(Res.GetString("NullDirectoryAttributeCollection"));
     }
     return base.List.Add(attribute);
 }
Esempio n. 9
0
        public int Add(DirectoryAttribute attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.NullDirectoryAttributeCollection));
            }

            return(List.Add(attribute));
        }
Esempio n. 10
0
        public void Insert(int index, DirectoryAttribute value)
        {
            if (value == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.NullDirectoryAttributeCollection));
            }

            List.Insert(index, value);
        }
Esempio n. 11
0
		public AddRequest(string distinguishedName, DirectoryAttribute[] attributes) : this()
		{
			this.dn = distinguishedName;
			if (attributes != null)
			{
				for (int i = 0; i < (int)attributes.Length; i++)
				{
					this.attributeList.Add(attributes[i]);
				}
			}
		}
 public CompareRequest(string distinguishedName, DirectoryAttribute assertion)
 {
     this.attribute = new DirectoryAttribute();
     if (assertion == null)
     {
         throw new ArgumentNullException("assertion");
     }
     if (assertion.Count != 1)
     {
         throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("WrongNumValuesCompare"));
     }
     this.CompareRequestHelper(distinguishedName, assertion.Name, assertion[0]);
 }
 public AddRequest(string distinguishedName, string objectClass) : this()
 {
     if (objectClass == null)
     {
         throw new ArgumentNullException("objectClass");
     }
     this.dn = distinguishedName;
     DirectoryAttribute attribute = new DirectoryAttribute {
         Name = "objectClass"
     };
     attribute.Add(objectClass);
     this.attributeList.Add(attribute);
 }
 public CompareRequest(string distinguishedName, DirectoryAttribute assertion)
 {
     this.attribute = new DirectoryAttribute();
     if (assertion == null)
     {
         throw new ArgumentNullException("assertion");
     }
     if (assertion.Count != 1)
     {
         throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("WrongNumValuesCompare"));
     }
     this.CompareRequestHelper(distinguishedName, assertion.Name, assertion[0]);
 }
Esempio n. 15
0
        public CompareRequest(string distinguishedName, DirectoryAttribute assertion)
        {
            if (assertion == null)
            {
                throw new ArgumentNullException("assertion");
            }

            if (assertion.Count != 1)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.WrongNumValuesCompare));
            }

            CompareRequestHelper(distinguishedName, assertion.Name, assertion[0]);
        }
 private SearchResultAttributeCollection AttributesHelper()
 {
     SearchResultAttributeCollection attributes = new SearchResultAttributeCollection();
     XmlNodeList list = this.dsmlNode.SelectNodes("dsml:attr", this.dsmlNS);
     if (list.Count != 0)
     {
         foreach (XmlNode node in list)
         {
             DirectoryAttribute attribute = new DirectoryAttribute((XmlElement) node);
             attributes.Add(attribute.Name, attribute);
         }
     }
     return attributes;
 }
Esempio n. 17
0
        public AddRequest(string distinguishedName, string objectClass) : this()
        {
            if (objectClass == null)
            {
                throw new ArgumentNullException("objectClass");
            }
            this.dn = distinguishedName;
            DirectoryAttribute attribute = new DirectoryAttribute {
                Name = "objectClass"
            };

            attribute.Add(objectClass);
            this.attributeList.Add(attribute);
        }
Esempio n. 18
0
        public CompareRequest(string distinguishedName, DirectoryAttribute assertion)
        {
            if (assertion == null)
            {
                throw new ArgumentNullException("assertion");
            }

            if (assertion.Count != 1)
            {
                throw new ArgumentException(Res.GetString(Res.WrongNumValuesCompare));
            }

            CompareRequestHelper(distinguishedName, assertion.Name, assertion[0]);
        }
Esempio n. 19
0
        private SearchResultAttributeCollection AttributesHelper()
        {
            SearchResultAttributeCollection attributes = new SearchResultAttributeCollection();
            XmlNodeList list = this.dsmlNode.SelectNodes("dsml:attr", this.dsmlNS);

            if (list.Count != 0)
            {
                foreach (XmlNode node in list)
                {
                    DirectoryAttribute attribute = new DirectoryAttribute((XmlElement)node);
                    attributes.Add(attribute.Name, attribute);
                }
            }
            return(attributes);
        }
Esempio n. 20
0
        private SearchResultAttributeCollection AttributesHelper()
        {
            SearchResultAttributeCollection searchResultAttributeCollection = new SearchResultAttributeCollection();
            XmlNodeList xmlNodeLists = this.dsmlNode.SelectNodes("dsml:attr", this.dsmlNS);

            if (xmlNodeLists.Count != 0)
            {
                foreach (XmlNode xmlNodes in xmlNodeLists)
                {
                    DirectoryAttribute directoryAttribute = new DirectoryAttribute((XmlElement)xmlNodes);
                    searchResultAttributeCollection.Add(directoryAttribute.Name, directoryAttribute);
                }
            }
            return(searchResultAttributeCollection);
        }
Esempio n. 21
0
		public AddRequest(string distinguishedName, string objectClass) : this()
		{
			if (objectClass != null)
			{
				this.dn = distinguishedName;
				DirectoryAttribute directoryAttribute = new DirectoryAttribute();
				directoryAttribute.Name = "objectClass";
				directoryAttribute.Add(objectClass);
				this.attributeList.Add(directoryAttribute);
				return;
			}
			else
			{
				throw new ArgumentNullException("objectClass");
			}
		}
Esempio n. 22
0
 public AddRequest(string distinguishedName, string objectClass) : this()
 {
     if (objectClass != null)
     {
         this.dn = distinguishedName;
         DirectoryAttribute directoryAttribute = new DirectoryAttribute();
         directoryAttribute.Name = "objectClass";
         directoryAttribute.Add(objectClass);
         this.attributeList.Add(directoryAttribute);
         return;
     }
     else
     {
         throw new ArgumentNullException("objectClass");
     }
 }
 public void AddRange(DirectoryAttribute[] attributes)
 {
     if (attributes == null)
     {
         throw new ArgumentNullException("attributes");
     }
     DirectoryAttribute[] attributeArray = attributes;
     for (int i = 0; i < attributeArray.Length; i++)
     {
         if (attributeArray[i] == null)
         {
             throw new ArgumentException(Res.GetString("NullDirectoryAttributeCollection"));
         }
     }
     base.InnerList.AddRange(attributes);
 }
Esempio n. 24
0
        public AddRequest(string distinguishedName, string objectClass) : this()
        {
            // parameter validation
            if (objectClass == null)
            {
                throw new ArgumentNullException("objectClass");
            }

            // Store off the distinguished name
            _dn = distinguishedName;

            // Store off the objectClass in an object class attribute
            DirectoryAttribute objClassAttr = new DirectoryAttribute();

            objClassAttr.Name = "objectClass";
            objClassAttr.Add(objectClass);
            _attributeList.Add(objClassAttr);
        }
Esempio n. 25
0
        private SearchResultAttributeCollection AttributesHelper()
        {
            SearchResultAttributeCollection attributes = new SearchResultAttributeCollection();

            XmlNodeList nodeList = _dsmlNode.SelectNodes("dsml:attr", _dsmlNS);

            if (nodeList.Count != 0)
            {
                foreach (XmlNode node in nodeList)
                {
                    Debug.Assert(node is XmlElement);

                    DirectoryAttribute attribute = new DirectoryAttribute((XmlElement)node);
                    attributes.Add(attribute.Name, attribute);
                }
            }

            return(attributes);
        }
Esempio n. 26
0
		public CompareRequest(string distinguishedName, DirectoryAttribute assertion)
		{
			this.attribute = new DirectoryAttribute();
			if (assertion != null)
			{
				if (assertion.Count == 1)
				{
					this.CompareRequestHelper(distinguishedName, assertion.Name, assertion[0]);
					return;
				}
				else
				{
					throw new ArgumentException(Res.GetString("WrongNumValuesCompare"));
				}
			}
			else
			{
				throw new ArgumentNullException("assertion");
			}
		}
Esempio n. 27
0
 public CompareRequest(string distinguishedName, DirectoryAttribute assertion)
 {
     this.attribute = new DirectoryAttribute();
     if (assertion != null)
     {
         if (assertion.Count == 1)
         {
             this.CompareRequestHelper(distinguishedName, assertion.Name, assertion[0]);
             return;
         }
         else
         {
             throw new ArgumentException(Res.GetString("WrongNumValuesCompare"));
         }
     }
     else
     {
         throw new ArgumentNullException("assertion");
     }
 }
Esempio n. 28
0
        protected override XmlElement ToXmlNode(XmlDocument doc)
        {
            XmlElement elem = CreateRequestElement(doc, "searchRequest", true, _dn);

            // attach the "scope" attribute (required)
            XmlAttribute attrScope = doc.CreateAttribute("scope", null);

            switch (_directoryScope)
            {
            case SearchScope.Subtree:
                attrScope.InnerText = "wholeSubtree";
                break;

            case SearchScope.OneLevel:
                attrScope.InnerText = "singleLevel";
                break;

            case SearchScope.Base:
                attrScope.InnerText = "baseObject";
                break;

            default:
                Debug.Assert(false, "Unknown DsmlSearchScope type");
                break;
            }

            elem.Attributes.Append(attrScope);

            // attach the "derefAliases" attribute (required)
            XmlAttribute attrDerefAliases = doc.CreateAttribute("derefAliases", null);

            switch (_directoryRefAlias)
            {
            case DereferenceAlias.Never:
                attrDerefAliases.InnerText = "neverDerefAliases";
                break;

            case DereferenceAlias.InSearching:
                attrDerefAliases.InnerText = "derefInSearching";
                break;

            case DereferenceAlias.FindingBaseObject:
                attrDerefAliases.InnerText = "derefFindingBaseObj";
                break;

            case DereferenceAlias.Always:
                attrDerefAliases.InnerText = "derefAlways";
                break;

            default:
                Debug.Assert(false, "Unknown DsmlDereferenceAlias type");
                break;
            }

            elem.Attributes.Append(attrDerefAliases);

            // attach the "sizeLimit" attribute (optional)
            XmlAttribute attrSizeLimit = doc.CreateAttribute("sizeLimit", null);

            attrSizeLimit.InnerText = _directorySizeLimit.ToString(CultureInfo.InvariantCulture);
            elem.Attributes.Append(attrSizeLimit);

            // attach the "timeLimit" attribute (optional)
            XmlAttribute attrTimeLimit = doc.CreateAttribute("timeLimit", null);

            attrTimeLimit.InnerText = (_directoryTimeLimit.Ticks / TimeSpan.TicksPerSecond).ToString(CultureInfo.InvariantCulture);
            elem.Attributes.Append(attrTimeLimit);

            // attach the "typesOnly" attribute (optional, defaults to false)
            XmlAttribute attrTypesOnly = doc.CreateAttribute("typesOnly", null);

            attrTypesOnly.InnerText = _directoryTypesOnly ? "true" : "false";
            elem.Attributes.Append(attrTypesOnly);

            // add in the <filter> element (required)
            XmlElement elemFilter = doc.CreateElement("filter", DsmlConstants.DsmlUri);

            if (Filter != null)
            {
                StringWriter  stringWriter = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);

                try
                {
                    if (Filter is XmlDocument)
                    {
                        if (((XmlDocument)Filter).NamespaceURI.Length == 0)
                        {
                            // namespaceURI is not explicitly specified
                            CopyFilter((XmlDocument)Filter, xmlWriter);
                            elemFilter.InnerXml = stringWriter.ToString();
                        }
                        else
                        {
                            elemFilter.InnerXml = ((XmlDocument)Filter).OuterXml;
                        }
                    }
                    else if (Filter is string)
                    {
                        //
                        // Search Filter
                        // We make use of the code from DSDE, which requires an intermediary
                        // trip through the ADFilter representation.  Although ADFilter is unnecessary
                        // for our purposes, this enables us to use the same exact code as
                        // DSDE, without having to maintain a second copy of it.
                        //

                        // AD filter currently does not support filter without paranthesis, so adding it explicitly
                        string tempFilter = (string)Filter;
                        if (!tempFilter.StartsWith("(", StringComparison.Ordinal) && !tempFilter.EndsWith(")", StringComparison.Ordinal))
                        {
                            tempFilter = tempFilter.Insert(0, "(");
                            tempFilter = String.Concat(tempFilter, ")");
                        }

                        // Convert LDAP filter string to ADFilter representation
                        ADFilter adfilter = FilterParser.ParseFilterString(tempFilter);

                        if (adfilter == null)
                        {
                            // The LDAP filter string didn't parse correctly
                            throw new ArgumentException(Res.GetString(Res.BadSearchLDAPFilter));
                        }

                        // Convert ADFilter representation to a DSML filter string
                        //   Ideally, we'd skip the intemediary string, but the DSDE conversion
                        //   routines expect a XmlWriter, and the only XmlWriter available
                        //   is the XmlTextWriter, which produces text.
                        DSMLFilterWriter filterwriter = new DSMLFilterWriter();

                        filterwriter.WriteFilter(adfilter, false, xmlWriter, DsmlConstants.DsmlUri);

                        elemFilter.InnerXml = stringWriter.ToString();
                    }
                    else
                    {
                        Debug.Assert(false, "Unknown filter type");
                    }
                }
                finally
                {
                    // close this stream and the underlying stream.
                    xmlWriter.Close();
                }
            }
            else
            {
                // default filter: (objectclass=*)
                elemFilter.InnerXml = DsmlConstants.DefaultSearchFilter;
            }

            elem.AppendChild(elemFilter);

            // add in the <attributes> element (optional)
            if (_directoryAttributes != null && _directoryAttributes.Count != 0)
            {
                // create and attach the <attributes> element
                XmlElement elemAttributes = doc.CreateElement("attributes", DsmlConstants.DsmlUri);
                elem.AppendChild(elemAttributes);

                // create and attach the <attribute> elements under the <attributes> element
                foreach (string attrName in _directoryAttributes)
                {
                    // DsmlAttribute objects know how to persist themself in the right
                    // XML format, so we'll make use of that here rather than
                    // duplicating the code
                    DirectoryAttribute attr = new DirectoryAttribute();
                    attr.Name = attrName;
                    XmlElement elemAttr = attr.ToXmlNode(doc, "attribute");
                    elemAttributes.AppendChild(elemAttr);
                }
            }

            return(elem);
        }
Esempio n. 29
0
 public CompareRequest(string distinguishedName, DirectoryAttribute assertion)
 {
     DistinguishedName = distinguishedName;
     Assertion         = assertion;
 }
Esempio n. 30
0
 public void Insert(int index, DirectoryAttribute value)
 {
     list.Insert(index, value);
 }
Esempio n. 31
0
 public bool Contains(DirectoryAttribute value)
 {
     return(list.Contains(value));
 }
Esempio n. 32
0
        private string getSearchResponseDSML(System.DirectoryServices.Protocols.SearchResponse response)
        {
            string returnValue = String.Empty;

            if (response != null)
            {
                DataIntegrator.Descriptions.LDAP.DSML.SearchResponse dsmlResponse = new DataIntegrator.Descriptions.LDAP.DSML.SearchResponse();

                dsmlResponse.requestID = response.RequestId;

                if ((response.Entries != null) && (response.Entries.Count > 0))
                {
                    dsmlResponse.searchResultEntry = new DataIntegrator.Descriptions.LDAP.DSML.SearchResultEntry[response.Entries.Count];

                    List <DataIntegrator.Descriptions.LDAP.DSML.DsmlAttr> dsmlAttrs = new List <DataIntegrator.Descriptions.LDAP.DSML.DsmlAttr>();

                    DataIntegrator.Descriptions.LDAP.DSML.DsmlAttr attr = null;

                    System.DirectoryServices.Protocols.DirectoryAttribute directoryAttrb = null;

                    for (int i = 0; i < response.Entries.Count; i++)
                    {
                        dsmlResponse.searchResultEntry[i]           = new DataIntegrator.Descriptions.LDAP.DSML.SearchResultEntry();
                        dsmlResponse.searchResultEntry[i].requestID = response.RequestId;
                        dsmlResponse.searchResultEntry[i].dn        = response.Entries[i].DistinguishedName;

                        if ((response.Entries[i].Attributes != null) && (response.Entries[i].Attributes.Count > 0))
                        {
                            dsmlResponse.searchResultEntry[i].attr = new DataIntegrator.Descriptions.LDAP.DSML.DsmlAttr[response.Entries[i].Attributes.Count];

                            dsmlAttrs = new List <DataIntegrator.Descriptions.LDAP.DSML.DsmlAttr>();

                            foreach (string attrName in response.Entries[i].Attributes.AttributeNames)
                            {
                                directoryAttrb = response.Entries[i].Attributes[attrName];

                                if ((directoryAttrb != null) && (directoryAttrb.Count > 0))
                                {
                                    attr       = new DataIntegrator.Descriptions.LDAP.DSML.DsmlAttr();
                                    attr.name  = attrName;
                                    attr.value = new string[directoryAttrb.Count];

                                    for (int j = 0; j < directoryAttrb.Count; j++)
                                    {
                                        if (directoryAttrb[j] is byte[])
                                        {
                                            attr.value[j] = Convert.ToBase64String((directoryAttrb[j] as byte[]), Base64FormattingOptions.None);
                                        }
                                        else
                                        {
                                            attr.value[j] = directoryAttrb[j].ToString();
                                        }
                                    }

                                    dsmlAttrs.Add(attr);
                                }

                                directoryAttrb = null;
                            }

                            if ((dsmlAttrs != null) && (dsmlAttrs.Count > 0))
                            {
                                dsmlAttrs.CopyTo(dsmlResponse.searchResultEntry[i].attr);
                            }

                            dsmlAttrs = null;
                            attr      = null;
                        }
                    }

                    Type   type  = typeof(DataIntegrator.Descriptions.LDAP.DSML.SearchResponse);
                    Type[] types = new Type[5];
                    types[0] = typeof(DataIntegrator.Descriptions.LDAP.DSML.DsmlAttr);
                    types[1] = typeof(DataIntegrator.Descriptions.LDAP.DSML.SearchResultEntry);
                    types[2] = typeof(DataIntegrator.Descriptions.LDAP.DSML.SearchResultReference);
                    types[3] = typeof(DataIntegrator.Descriptions.LDAP.DSML.LDAPResult);
                    types[4] = typeof(DataIntegrator.Descriptions.LDAP.DSML.ResultCode);

                    XmlSerializer           serializer = new XmlSerializer(type, types);
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                    namespaces.Add("", "urn:oasis:names:tc:DSML:2:0:core");

                    StringWriter writer = new StringWriter();

                    serializer.Serialize(writer, dsmlResponse, namespaces);

                    writer.Flush();
                    returnValue = writer.ToString();
                    writer.Close();

                    returnValue = returnValue.Replace("&#x", "HEX:");
                }
            }

            return(returnValue);
        }
		public void Insert (int index, DirectoryAttribute value)
		{
			list.Insert (index, value);
		}
Esempio n. 34
0
 internal void Add(string name, DirectoryAttribute value)
 {
     Dictionary.Add(name.ToLower(CultureInfo.InvariantCulture), value);
 }
		public void AddRange (DirectoryAttribute [] attributes)
		{
			list.AddRange (attributes);
		}
		internal DirectoryAttributeCollection (DirectoryAttribute [] attributes)
		{
			list = new ArrayList (attributes);
		}
Esempio n. 37
0
        public bool Execute()
        {
            try
            {
                conn_MDM = new Dbconn("MDM");
                DataTable dt_user = conn_MDM.GetDataTable(@"
            SELECT DISTINCT AM_login FROM dbo.AM_User t1 WITH(NOLOCK)
            JOIN dbo.AM_User_Dept t2 WITH(NOLOCK) ON t1.AM_User_id = t2.AM_USER_ID
            JOIN dbo.AM_Dept t3 WITH(NOLOCK) ON t2.AM_S_Dept_ID = t3.AM_S_Dept_ID
            WHERE  AM_Company='235'
    ", new string[0]);

                //目前只更新雅莹的数据
                ldap = new Common.LdapConnect("192.168.0.171:389", "cn=root", "elegant.admin");
                ldap = new Common.LdapConnect("172.16.205.73:389", "cn=root", "elegant");
                ldap.TargetOU = "dc=hwayifashiongroup,dc=com";
                ldap.TargetOU = "dc=elegant-prosper,dc=com,dc=cn";


                if (!ldap.ConnectLDAP())
                {
                    return false;
                }
                for (int i = 0; i < dt_user.Rows.Count; i++)
                {
                    string strUser = dt_user.Rows[i]["AM_login"].ToString();

                    DirectoryAttribute[] dir = new DirectoryAttribute[4];
                    dir[0] = new DirectoryAttribute("cn", strUser);
                    dir[1] = new DirectoryAttribute("sn", strUser);
                    dir[2] = new DirectoryAttribute("objectClass", "inetOrgPerson");
                    dir[3] = new DirectoryAttribute("userPassword", "111111");
                    ldap.LadpAdd("uid=" + strUser + ",ou=peoples", dir).ToString();
                }

                //取二级部门是室和部结尾的所有雅莹的数据
                DataTable dt_Groups = conn_MDM.GetDataTable(@"
                    SELECT  t3.AM_S_dept_ID,
		                    t3.AM_Dept_Name_All,
                            t3.AM_Dept_Name
                    FROM    dbo.AM_Dept t3
                            LEFT JOIN dbo.AM_Dept t4 WITH ( NOLOCK ) ON t3.AM_Dept1_ID = t4.AM_S_Dept_ID
                    WHERE   t3.AM_Company = '235'
                            AND ( t4.AM_Dept1_ID IS NULL
                                  OR t4.AM_Dept_NAME LIKE '%室'
                                  OR t4.AM_Dept_NAME LIKE '%部'
                                )
                      ORDER BY t3.OrderIndex 
                    ", new string[0]);


                for (int i = 0; i < dt_Groups.Rows.Count; i++)
                {
                    //添加组织架构
                    string strDEPT_Name = dt_Groups.Rows[i]["AM_Dept_Name"].ToString();
                    string strDEPT_Name_All = dt_Groups.Rows[i]["AM_Dept_Name_All"].ToString();

                    string[] strDEPTList = strDEPT_Name_All.Split('\\');

                    string strOU = "";
                    for (int j = strDEPTList.Length-1; j >=0 ; j--)
                    {
                        strOU += "cn="+strDEPTList[j]+",";
                    }

                    strOU += "ou=groups";

                    DirectoryAttribute[] dir = new DirectoryAttribute[2];
                    dir[0] = new DirectoryAttribute("cn", strDEPT_Name);
                    dir[1] = new DirectoryAttribute("objectClass", "container");
                    ldap.LadpAdd(strOU, dir).ToString();
                }


                //组织架构下面的成员
                DataTable dt_Dept_User = conn_MDM.GetDataTable(@"
                    SELECT DISTINCT
                            AM_login ,
                            t3.AM_S_Dept_ID ,
                            t3.AM_p_Dept_ID ,
                            t3.AM_Dept_NAME ,
                            t3.AM_Dept_NAME_All
                    FROM    dbo.AM_User t1 WITH ( NOLOCK )
                            JOIN dbo.AM_User_Dept t2 WITH ( NOLOCK ) ON t1.AM_User_id = t2.AM_USER_ID
                            JOIN dbo.AM_Dept t3 WITH ( NOLOCK ) ON t2.AM_S_Dept_ID = t3.AM_S_Dept_ID
                            LEFT JOIN dbo.AM_Dept t4 WITH ( NOLOCK ) ON t3.AM_Dept1_ID = t4.AM_S_Dept_ID
                    WHERE   t3.AM_Company = '235'
                            AND ( t4.AM_Dept1_ID IS NULL
                                  OR t4.AM_Dept_NAME LIKE '%室'
                                  OR t4.AM_Dept_NAME LIKE '%部'
                                )
                                

            ", new string[0]);


                for (int i = 0; i < dt_Dept_User.Rows.Count; i++)
                {
                    //添加组织架构下的成员
                    string strUser = dt_Dept_User.Rows[i]["AM_login"].ToString();
                    string strDEPT_Name = dt_Dept_User.Rows[i]["AM_Dept_Name"].ToString();
                    string strDEPT_Name_All = dt_Dept_User.Rows[i]["AM_Dept_Name_All"].ToString();

                    //string strOU = "uid=" + strUser + ",cn=" + strDEPT_Name_All.Replace("\\", ",cn=") + ",ou=groups," + ldap.TargetOU;
                    
                    string[] strDEPTList = strDEPT_Name_All.Split('\\');
                    string strOU = "uid=" + strUser + ",";
                    for (int j = strDEPTList.Length - 1; j >= 0; j--)
                    {
                        strOU += "cn=" + strDEPTList[j] + ",";
                    }

                    strOU += "ou=groups";

                    DirectoryAttribute[] dir = new DirectoryAttribute[3];
                    dir[0] = new DirectoryAttribute("cn", strUser);
                    dir[1] = new DirectoryAttribute("sn", strUser);
                    dir[2] = new DirectoryAttribute("objectClass", "inetOrgPerson");
                    ldap.LadpAdd(strOU, dir).ToString();
                }

                return true;

            }
            catch
            {
                throw;
            }
        }
Esempio n. 38
0
 public CompareRequest()
 {
     this.attribute = new DirectoryAttribute();
 }
Esempio n. 39
0
        /// <summary>
        /// Adds an entry to the LDAP directory with the specified distinguished name and attributes.
        /// </summary>
        /// <param name="dn">The distinguished name of the entry to add.</param>
        /// <param name="attributes">The attributes for the entry to add.</param>
        /// <returns>True if added, false otherwise.</returns>
        public bool Add(string dn, DirectoryAttribute[] attributes)
        {
            if (!string.IsNullOrWhiteSpace(dn))
            {
                AddRequest request = new AddRequest(dn, attributes);
                try
                {
                    AddResponse response = (AddResponse)connection.SendRequest(request);

                    // Check that a response was received.
                    if (response != null)
                    {
                        // A response was received.
                        if (response.ResultCode == ResultCode.Success)
                        {
                            return true;
                        }
                    }
                    else
                    {
                        // A response was not received.
                        return false;
                    }
                }
                catch
                {
                }
            }
            return false;
        }
Esempio n. 40
0
 public CompareRequest(string distinguishedName, string attributeName, Uri value)
 {
     this.attribute = new DirectoryAttribute();
     this.CompareRequestHelper(distinguishedName, attributeName, value);
 }
Esempio n. 41
0
        internal DirectoryAttribute ConstructAttribute(IntPtr entryMessage, IntPtr attributeName)
        {
            DirectoryAttribute attribute = new DirectoryAttribute();
            attribute.isSearchResult = true;

            // get name
            string name = Marshal.PtrToStringUni(attributeName);
            attribute.Name = name;

            // get values
            IntPtr valuesArray = Wldap32.ldap_get_values_len(ldapHandle, entryMessage, name);
            try
            {
                IntPtr tempPtr = (IntPtr)0;
                int count = 0;
                if (valuesArray != (IntPtr)0)
                {
                    tempPtr = Marshal.ReadIntPtr(valuesArray, Marshal.SizeOf(typeof(IntPtr)) * count);
                    while (tempPtr != (IntPtr)0)
                    {
                        berval bervalue = new berval();
                        Marshal.PtrToStructure(tempPtr, bervalue);
                        byte[] byteArray = null;
                        if (bervalue.bv_len > 0 && bervalue.bv_val != (IntPtr)0)
                        {
                            byteArray = new byte[bervalue.bv_len];
                            Marshal.Copy(bervalue.bv_val, byteArray, 0, bervalue.bv_len);
                            attribute.Add(byteArray);
                        }

                        count++;
                        tempPtr = Marshal.ReadIntPtr(valuesArray, Marshal.SizeOf(typeof(IntPtr)) * count);
                    }
                }
            }
            finally
            {
                if (valuesArray != (IntPtr)0)
                    Wldap32.ldap_value_free_len(valuesArray);
            }

            return attribute;
        }
		public void CopyTo (DirectoryAttribute [] array, int index)
		{
			list.CopyTo (array, index);
		}
        //
        // This function goes through each of the object class values for the container to determine
        // whether the object class is one of the possible superiors of the user object
        //
        private bool ContainerIsSuperiorOfUser(DirectoryAttribute objectClass)
        {
            ArrayList possibleSuperiorsList = new ArrayList();

            //
            // first get a list of all the classes from which the user class is derived
            //
            DirectoryEntry de = new DirectoryEntry(GetADsPath("schema") + "/user", GetUsername(), GetPassword(), AuthenticationTypes);
            ArrayList classesList = new ArrayList();
            bool derivedFromlistEmpty = false;
            object value = null;

            try
            {
                value = de.InvokeGet("DerivedFrom");
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int) 0x8000500D))
                {
                    derivedFromlistEmpty = true;
                }
                else
                    throw;
            }

            if (!derivedFromlistEmpty)
            {
                if (value is ICollection)
                {
                    classesList.AddRange((ICollection) value);
                }
                else
                {
                    // single value
                    classesList.Add((string) value);
                }
            }

            //
            // we will use this list to create a filter of all the classSchema objects that we need to determine the recursive list
            // of "possibleSecuperiors". We need to add the user class also.
            //
            classesList.Add("user");

            //
            // Now search under the schema naming context for all these classes and get the "possSuperiors" and "systemPossSuperiors" attributes
            //
            DirectoryEntry schemaNC = new DirectoryEntry(GetADsPath((string) rootdse.Properties["schemaNamingContext"].Value), GetUsername(), GetPassword(), AuthenticationTypes);
            DirectorySearcher searcher = new DirectorySearcher(schemaNC);

            searcher.Filter = "(&(objectClass=classSchema)(|";
            foreach(string supClass in classesList)
                searcher.Filter += "(ldapDisplayName=" + supClass + ")";
            searcher.Filter += "))";

            searcher.SearchScope = System.DirectoryServices.SearchScope.OneLevel;
            searcher.PropertiesToLoad.Add("possSuperiors");
            searcher.PropertiesToLoad.Add("systemPossSuperiors");

            SearchResultCollection resCol = searcher.FindAll();

            try
            {
                foreach (SearchResult res in resCol)
                {
                    possibleSuperiorsList.AddRange(res.Properties["possSuperiors"]);
                    possibleSuperiorsList.AddRange(res.Properties["systemPossSuperiors"]);
                }
            }
            finally
            {
                resCol.Dispose();
            }

            //
            // Now we have the list of all the possible superiors, check if the objectClass that was specified as a parameter
            // to this function is one of these values, if so, return true else false
            //
            foreach (string objectClassValue in objectClass.GetValues(typeof(string)))
            {
                if (possibleSuperiorsList.Contains(objectClassValue))
                    return true;
            }

            return false;
        }
        protected override XmlElement ToXmlNode(XmlDocument doc)
        {
            XmlElement element = base.CreateRequestElement(doc, "searchRequest", true, this.dn);
            XmlAttribute node = doc.CreateAttribute("scope", null);
            switch (this.directoryScope)
            {
                case SearchScope.Base:
                    node.InnerText = "baseObject";
                    break;

                case SearchScope.OneLevel:
                    node.InnerText = "singleLevel";
                    break;

                case SearchScope.Subtree:
                    node.InnerText = "wholeSubtree";
                    break;
            }
            element.Attributes.Append(node);
            XmlAttribute attribute2 = doc.CreateAttribute("derefAliases", null);
            switch (this.directoryRefAlias)
            {
                case DereferenceAlias.Never:
                    attribute2.InnerText = "neverDerefAliases";
                    break;

                case DereferenceAlias.InSearching:
                    attribute2.InnerText = "derefInSearching";
                    break;

                case DereferenceAlias.FindingBaseObject:
                    attribute2.InnerText = "derefFindingBaseObj";
                    break;

                case DereferenceAlias.Always:
                    attribute2.InnerText = "derefAlways";
                    break;
            }
            element.Attributes.Append(attribute2);
            XmlAttribute attribute3 = doc.CreateAttribute("sizeLimit", null);
            attribute3.InnerText = this.directorySizeLimit.ToString(CultureInfo.InvariantCulture);
            element.Attributes.Append(attribute3);
            XmlAttribute attribute4 = doc.CreateAttribute("timeLimit", null);
            attribute4.InnerText = (this.directoryTimeLimit.Ticks / 0x989680L).ToString(CultureInfo.InvariantCulture);
            element.Attributes.Append(attribute4);
            XmlAttribute attribute5 = doc.CreateAttribute("typesOnly", null);
            attribute5.InnerText = this.directoryTypesOnly ? "true" : "false";
            element.Attributes.Append(attribute5);
            XmlElement newChild = doc.CreateElement("filter", "urn:oasis:names:tc:DSML:2:0:core");
            if (this.Filter != null)
            {
                StringWriter w = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter writer = new XmlTextWriter(w);
                try
                {
                    if (this.Filter is XmlDocument)
                    {
                        if (((XmlDocument) this.Filter).NamespaceURI.Length == 0)
                        {
                            this.CopyFilter((XmlDocument) this.Filter, writer);
                            newChild.InnerXml = w.ToString();
                        }
                        else
                        {
                            newChild.InnerXml = ((XmlDocument) this.Filter).OuterXml;
                        }
                    }
                    else if (this.Filter is string)
                    {
                        string str = (string) this.Filter;
                        if (!str.StartsWith("(", StringComparison.Ordinal) && !str.EndsWith(")", StringComparison.Ordinal))
                        {
                            str = str.Insert(0, "(") + ")";
                        }
                        ADFilter filter = FilterParser.ParseFilterString(str);
                        if (filter == null)
                        {
                            throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("BadSearchLDAPFilter"));
                        }
                        new DSMLFilterWriter().WriteFilter(filter, false, writer, "urn:oasis:names:tc:DSML:2:0:core");
                        newChild.InnerXml = w.ToString();
                    }
                }
                finally
                {
                    writer.Close();
                }
            }
            else
            {
                newChild.InnerXml = "<present name='objectClass' xmlns=\"urn:oasis:names:tc:DSML:2:0:core\"/>";
            }
            element.AppendChild(newChild);
            if ((this.directoryAttributes != null) && (this.directoryAttributes.Count != 0))
            {
                XmlElement element3 = doc.CreateElement("attributes", "urn:oasis:names:tc:DSML:2:0:core");
                element.AppendChild(element3);
                foreach (string str2 in this.directoryAttributes)
                {
                    XmlElement element4 = new DirectoryAttribute { Name = str2 }.ToXmlNode(doc, "attribute");
                    element3.AppendChild(element4);
                }
            }
            return element;
        }
		public int Add (DirectoryAttribute attribute)
		{
			return list.Add (attribute);
		}
Esempio n. 46
0
 private string CreateUserAccountName(string value, DirectoryAttribute attr)
 {
     int position = value.IndexOf('\\');
     if(position > 0)
         value = value.Substring(position+1);
     string AccountName = string.Format("{0}{1}@{2}", this.SPOClaimsString, value, this.SPOAccountUPN);
     return AccountName;
 }
		public bool Contains (DirectoryAttribute value)
		{
			return list.Contains (value);
		}
Esempio n. 48
0
        protected override XmlElement ToXmlNode(XmlDocument doc)
        {
            string       str;
            XmlElement   xmlElement   = base.CreateRequestElement(doc, "searchRequest", true, this.dn);
            XmlAttribute xmlAttribute = doc.CreateAttribute("scope", null);
            SearchScope  searchScope  = this.directoryScope;

            switch (searchScope)
            {
            case SearchScope.Base:
            {
                xmlAttribute.InnerText = "baseObject";
                break;
            }

            case SearchScope.OneLevel:
            {
                xmlAttribute.InnerText = "singleLevel";
                break;
            }

            case SearchScope.Subtree:
            {
                xmlAttribute.InnerText = "wholeSubtree";
                break;
            }
            }
            xmlElement.Attributes.Append(xmlAttribute);
            XmlAttribute     xmlAttribute1   = doc.CreateAttribute("derefAliases", null);
            DereferenceAlias dereferenceAlia = this.directoryRefAlias;

            switch (dereferenceAlia)
            {
            case DereferenceAlias.Never:
            {
                xmlAttribute1.InnerText = "neverDerefAliases";
                break;
            }

            case DereferenceAlias.InSearching:
            {
                xmlAttribute1.InnerText = "derefInSearching";
                break;
            }

            case DereferenceAlias.FindingBaseObject:
            {
                xmlAttribute1.InnerText = "derefFindingBaseObj";
                break;
            }

            case DereferenceAlias.Always:
            {
                xmlAttribute1.InnerText = "derefAlways";
                break;
            }
            }
            xmlElement.Attributes.Append(xmlAttribute1);
            XmlAttribute str1 = doc.CreateAttribute("sizeLimit", null);

            str1.InnerText = this.directorySizeLimit.ToString(CultureInfo.InvariantCulture);
            xmlElement.Attributes.Append(str1);
            XmlAttribute str2  = doc.CreateAttribute("timeLimit", null);
            long         ticks = this.directoryTimeLimit.Ticks / (long)0x989680;

            str2.InnerText = ticks.ToString(CultureInfo.InvariantCulture);
            xmlElement.Attributes.Append(str2);
            XmlAttribute xmlAttribute2 = doc.CreateAttribute("typesOnly", null);
            XmlAttribute xmlAttribute3 = xmlAttribute2;

            if (this.directoryTypesOnly)
            {
                str = "true";
            }
            else
            {
                str = "false";
            }
            xmlAttribute3.InnerText = str;
            xmlElement.Attributes.Append(xmlAttribute2);
            XmlElement outerXml = doc.CreateElement("filter", "urn:oasis:names:tc:DSML:2:0:core");

            if (this.Filter == null)
            {
                outerXml.InnerXml = "<present name='objectClass' xmlns=\"urn:oasis:names:tc:DSML:2:0:core\"/>";
            }
            else
            {
                StringWriter  stringWriter  = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
                try
                {
                    if (this.Filter as XmlDocument == null)
                    {
                        if (this.Filter as string != null)
                        {
                            string filter = (string)this.Filter;
                            if (!filter.StartsWith("(", StringComparison.Ordinal) && !filter.EndsWith(")", StringComparison.Ordinal))
                            {
                                filter = filter.Insert(0, "(");
                                filter = string.Concat(filter, ")");
                            }
                            ADFilter aDFilter = FilterParser.ParseFilterString(filter);
                            if (aDFilter != null)
                            {
                                DSMLFilterWriter dSMLFilterWriter = new DSMLFilterWriter();
                                dSMLFilterWriter.WriteFilter(aDFilter, false, xmlTextWriter, "urn:oasis:names:tc:DSML:2:0:core");
                                outerXml.InnerXml = stringWriter.ToString();
                            }
                            else
                            {
                                throw new ArgumentException(Res.GetString("BadSearchLDAPFilter"));
                            }
                        }
                    }
                    else
                    {
                        if (((XmlDocument)this.Filter).NamespaceURI.Length != 0)
                        {
                            outerXml.InnerXml = ((XmlDocument)this.Filter).OuterXml;
                        }
                        else
                        {
                            this.CopyFilter((XmlDocument)this.Filter, xmlTextWriter);
                            outerXml.InnerXml = stringWriter.ToString();
                        }
                    }
                }
                finally
                {
                    xmlTextWriter.Close();
                }
            }
            xmlElement.AppendChild(outerXml);
            if (this.directoryAttributes != null && this.directoryAttributes.Count != 0)
            {
                XmlElement xmlElement1 = doc.CreateElement("attributes", "urn:oasis:names:tc:DSML:2:0:core");
                xmlElement.AppendChild(xmlElement1);
                foreach (string directoryAttribute in this.directoryAttributes)
                {
                    DirectoryAttribute directoryAttribute1 = new DirectoryAttribute();
                    directoryAttribute1.Name = directoryAttribute;
                    XmlElement xmlNode = directoryAttribute1.ToXmlNode(doc, "attribute");
                    xmlElement1.AppendChild(xmlNode);
                }
            }
            return(xmlElement);
        }
		public int IndexOf (DirectoryAttribute value)
		{
			return list.IndexOf (value);
		}
Esempio n. 50
0
		public CompareRequest (string distinguishedName, DirectoryAttribute assertion)
		{
			DistinguishedName = distinguishedName;
			Assertion = assertion;
		}
		public void Remove (DirectoryAttribute value)
		{
			list.Remove (value);
		}
Esempio n. 52
0
		public CompareRequest()
		{
			this.attribute = new DirectoryAttribute();
		}
Esempio n. 53
0
 public int Add(DirectoryAttribute attribute)
 {
     return(list.Add(attribute));
 }
Esempio n. 54
0
		public CompareRequest(string distinguishedName, string attributeName, Uri value)
		{
			this.attribute = new DirectoryAttribute();
			this.CompareRequestHelper(distinguishedName, attributeName, value);
		}
Esempio n. 55
0
 public int IndexOf(DirectoryAttribute value)
 {
     return(list.IndexOf(value));
 }
Esempio n. 56
0
		public ADAddRequest(string distinguishedName, DirectoryAttribute[] attributes) : base(distinguishedName, attributes)
		{
		}
Esempio n. 57
0
 public void Remove(DirectoryAttribute value)
 {
     list.Remove(value);
 }
        protected override XmlElement ToXmlNode(XmlDocument doc)
        {
            XmlElement   element = base.CreateRequestElement(doc, "searchRequest", true, this.dn);
            XmlAttribute node    = doc.CreateAttribute("scope", null);

            switch (this.directoryScope)
            {
            case SearchScope.Base:
                node.InnerText = "baseObject";
                break;

            case SearchScope.OneLevel:
                node.InnerText = "singleLevel";
                break;

            case SearchScope.Subtree:
                node.InnerText = "wholeSubtree";
                break;
            }
            element.Attributes.Append(node);
            XmlAttribute attribute2 = doc.CreateAttribute("derefAliases", null);

            switch (this.directoryRefAlias)
            {
            case DereferenceAlias.Never:
                attribute2.InnerText = "neverDerefAliases";
                break;

            case DereferenceAlias.InSearching:
                attribute2.InnerText = "derefInSearching";
                break;

            case DereferenceAlias.FindingBaseObject:
                attribute2.InnerText = "derefFindingBaseObj";
                break;

            case DereferenceAlias.Always:
                attribute2.InnerText = "derefAlways";
                break;
            }
            element.Attributes.Append(attribute2);
            XmlAttribute attribute3 = doc.CreateAttribute("sizeLimit", null);

            attribute3.InnerText = this.directorySizeLimit.ToString(CultureInfo.InvariantCulture);
            element.Attributes.Append(attribute3);
            XmlAttribute attribute4 = doc.CreateAttribute("timeLimit", null);

            attribute4.InnerText = (this.directoryTimeLimit.Ticks / 0x989680L).ToString(CultureInfo.InvariantCulture);
            element.Attributes.Append(attribute4);
            XmlAttribute attribute5 = doc.CreateAttribute("typesOnly", null);

            attribute5.InnerText = this.directoryTypesOnly ? "true" : "false";
            element.Attributes.Append(attribute5);
            XmlElement newChild = doc.CreateElement("filter", "urn:oasis:names:tc:DSML:2:0:core");

            if (this.Filter != null)
            {
                StringWriter  w      = new StringWriter(CultureInfo.InvariantCulture);
                XmlTextWriter writer = new XmlTextWriter(w);
                try
                {
                    if (this.Filter is XmlDocument)
                    {
                        if (((XmlDocument)this.Filter).NamespaceURI.Length == 0)
                        {
                            this.CopyFilter((XmlDocument)this.Filter, writer);
                            newChild.InnerXml = w.ToString();
                        }
                        else
                        {
                            newChild.InnerXml = ((XmlDocument)this.Filter).OuterXml;
                        }
                    }
                    else if (this.Filter is string)
                    {
                        string str = (string)this.Filter;
                        if (!str.StartsWith("(", StringComparison.Ordinal) && !str.EndsWith(")", StringComparison.Ordinal))
                        {
                            str = str.Insert(0, "(") + ")";
                        }
                        ADFilter filter = FilterParser.ParseFilterString(str);
                        if (filter == null)
                        {
                            throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("BadSearchLDAPFilter"));
                        }
                        new DSMLFilterWriter().WriteFilter(filter, false, writer, "urn:oasis:names:tc:DSML:2:0:core");
                        newChild.InnerXml = w.ToString();
                    }
                }
                finally
                {
                    writer.Close();
                }
            }
            else
            {
                newChild.InnerXml = "<present name='objectClass' xmlns=\"urn:oasis:names:tc:DSML:2:0:core\"/>";
            }
            element.AppendChild(newChild);
            if ((this.directoryAttributes != null) && (this.directoryAttributes.Count != 0))
            {
                XmlElement element3 = doc.CreateElement("attributes", "urn:oasis:names:tc:DSML:2:0:core");
                element.AppendChild(element3);
                foreach (string str2 in this.directoryAttributes)
                {
                    XmlElement element4 = new DirectoryAttribute {
                        Name = str2
                    }.ToXmlNode(doc, "attribute");
                    element3.AppendChild(element4);
                }
            }
            return(element);
        }