예제 #1
0
파일: ADLib.cs 프로젝트: ddmunhoz/Seeker
        /// <summary>
        /// Populates the list from the container which was clicked on the treeview
        /// </summary>
        /// <param name="aDContainer"></param>
        public void FillListViewFromADContainer(ref ListView ctr_list, DirectoryEntry aDContainer)
        {
            //Fill the ListView Element
            try
            {
                if (aDContainer == null)
                {
                    return;
                }
                ctr_list.Items.Clear();

                foreach (object ADProperties in aDContainer.Properties.PropertyNames)
                {
                    if (!(ADProperties.ToString().Contains("ms-Mcs-AdmPwdExpirationTime") | (ADProperties.ToString().Contains("ms-Mcs-AdmPwd"))))
                    {
                        IADsPropertyList  oPropList  = (aDContainer.NativeObject as IADsPropertyList);
                        IADsPropertyEntry oPropEntry = (oPropList.GetPropertyItem(ADProperties.ToString(), (int)ADSTYPEENUM.ADSTYPE_UNKNOWN) as IADsPropertyEntry);
                        int iADsType = oPropEntry.ADsType;

                        ListViewItem ListItem = new ListViewItem(ADProperties.ToString(), 0);
                        ListItem.SubItems.Add(PropertyToString(aDContainer, oPropEntry, iADsType));
                        ctr_list.Items.AddRange(new ListViewItem[] { ListItem });
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error while populating the list", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
파일: ADLib.cs 프로젝트: ddmunhoz/Seeker
        /// <summary>
        /// return Datatable from container
        /// </summary>
        /// <param name="aDContainer"></param>
        public DataTable FillDataTableFromADContainer(DirectoryEntry aDContainer)
        {
            try
            {
                if (aDContainer == null)
                {
                    return(null);
                }
                DataTable containerData = new DataTable();
                containerData.Columns.Add("Property", typeof(string));
                containerData.Columns.Add("Value", typeof(string));
                foreach (object ADProperties in aDContainer.Properties.PropertyNames)
                {
                    if (!(ADProperties.ToString().Contains("ms-Mcs-AdmPwdExpirationTime") | (ADProperties.ToString().Contains("ms-Mcs-AdmPwd"))))
                    {
                        IADsPropertyList  oPropList  = (aDContainer.NativeObject as IADsPropertyList);
                        IADsPropertyEntry oPropEntry = (oPropList.GetPropertyItem(ADProperties.ToString(), (int)ADSTYPEENUM.ADSTYPE_UNKNOWN) as IADsPropertyEntry);
                        int    iADsType = oPropEntry.ADsType;
                        string teste    = PropertyToString(aDContainer, oPropEntry, iADsType);
                        containerData.Rows.Add(ADProperties.ToString(), teste);

                        // ListViewItem ListItem = new ListViewItem(ADProperties.ToString(), 0);
                        //ListItem.SubItems.Add(PropertyToString(aDContainer, oPropEntry, iADsType));
                    }
                }
                return(containerData);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error while populating the Datatable", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
예제 #3
0
        public List <LDAPSearchResult> Search(ADProperties property, String propertyValue)
        {
            List <LDAPSearchResult> lstSearchResults = new List <LDAPSearchResult>();

            try
            {
                DirectorySearcher      search = new DirectorySearcher(entry);
                SearchResultCollection resultCollection;

                LoadProperties(ref search);

                search.Filter    = "(" + property + "=*" + propertyValue + "*)";
                resultCollection = search.FindAll();

                if (resultCollection != null)
                {
                    foreach (SearchResult result in resultCollection)
                    {
                        LDAPSearchResult objSearchResult = new LDAPSearchResult();

                        MapToObject(result, ref objSearchResult);

                        lstSearchResults.Add(objSearchResult);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            return(lstSearchResults);
        }
예제 #4
0
        /// <summary>
        /// Performs the search against ad by property
        /// </summary>
        /// <param name="property"></param>
        /// <param name="propertyValue"></param>
        /// <returns></returns>
        private SearchResult FindOne(ADProperties property, string propertyValue)
        {
            SearchResult result;

            try
            {
                DirectorySearcher search = new DirectorySearcher(entry);

                LoadProperties(ref search);

                search.Filter = "(" + property + "=" + propertyValue + ")";
                result        = search.FindOne();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Cleans up ad search by property and maps to user defined object
        /// </summary>
        /// <param name="property"></param>
        /// <param name="propertyValue"></param>
        /// <returns></returns>
        private LDAPSearchResult FindOneByProperty(ADProperties property, String propertyValue)
        {
            LDAPSearchResult objSearchResult = new LDAPSearchResult();

            try
            {
                SearchResult result = FindOne(property, propertyValue);

                if (result != null)
                {
                    MapToObject(result, ref objSearchResult);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            return(objSearchResult);
        }
예제 #6
0
        /// <summary>TBD</summary>
        /// <param name="userId">TBD</param>
        /// <param name="property">TBD</param>
        /// <returns>TBD</returns>
        public static string GetADProperty(string userId, ADProperties property)
        {
            if (String.IsNullOrEmpty(userId))
            {
                return(string.Empty);
            }
            DirectoryEntry    entry      = new DirectoryEntry("LDAP://SV-NYC-DC03");
            DirectorySearcher adSearcher = new DirectorySearcher(entry);

            adSearcher.Filter = "(& (samaccountname=" + userId.ToLower() + ")(objectClass=user))";
            adSearcher.PropertiesToLoad.Add("displayName");
            adSearcher.PropertiesToLoad.Add("mail");
            adSearcher.PropertiesToLoad.Add("co");
            adSearcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
            adSearcher.PropertyNamesOnly = true;
            SearchResult user = adSearcher.FindOne();

            if (user == null)
            {
                return(string.Empty);
            }
            switch (property)
            {
            case ADProperties.Company:
                return((string)user.GetDirectoryEntry().Properties["co"].Value);

            case ADProperties.Market:
                return((string)user.GetDirectoryEntry().Properties["physicalDeliveryOfficeName"].Value);

            case ADProperties.UserEmail:
                return((string)user.GetDirectoryEntry().Properties["mail"].Value);

            case ADProperties.UserFullName:
                return((string)user.GetDirectoryEntry().Properties["displayName"].Value);

            default:
                return(string.Empty);
            }
        }
예제 #7
0
        /// <summary>
        /// Performs the search against ad by property
        /// </summary>
        /// <param name="property"></param>
        /// <param name="propertyValue"></param>
        /// <returns></returns>
        private SearchResult FindOne(ADProperties property, string propertyValue)
        {
            SearchResult result;

            try
            {
                DirectorySearcher search = new DirectorySearcher(entry);

                LoadProperties(ref search);

                search.Filter = "(" + property + "=" + propertyValue + ")";
                result = search.FindOne();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            return result;
        }
예제 #8
0
        /// <summary>
        /// Cleans up ad search by property and maps to user defined object
        /// </summary>
        /// <param name="property"></param>
        /// <param name="propertyValue"></param>
        /// <returns></returns>
        private LDAPSearchResult FindOneByProperty(ADProperties property, String propertyValue)
        {
            LDAPSearchResult objSearchResult = new LDAPSearchResult();

            try
            {
                SearchResult result = FindOne(property, propertyValue);

                if (result != null)
                {
                    MapToObject(result, ref objSearchResult);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            return objSearchResult;
        }
예제 #9
0
        public List<LDAPSearchResult> Search(ADProperties property, String propertyValue)
        {
            List<LDAPSearchResult> lstSearchResults = new List<LDAPSearchResult>();

            try
            {
                DirectorySearcher search = new DirectorySearcher(entry);
                SearchResultCollection resultCollection;

                LoadProperties(ref search);

                search.Filter = "(" + property + "=*" + propertyValue + "*)";
                resultCollection = search.FindAll();

                if (resultCollection != null)
                {
                    foreach (SearchResult result in resultCollection)
                    {
                        LDAPSearchResult objSearchResult = new LDAPSearchResult();

                        MapToObject(result, ref objSearchResult);

                        lstSearchResults.Add(objSearchResult);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            return lstSearchResults;
        }
예제 #10
0
 /// <summary>TBD</summary>
 /// <param name="userId">TBD</param>
 /// <param name="property">TBD</param>
 /// <returns>TBD</returns>
 public static string GetADProperty(string userId, ADProperties property)
 {
     if (String.IsNullOrEmpty(userId))
     {
         return string.Empty;
     }
     DirectoryEntry entry = new DirectoryEntry("LDAP://SV-NYC-DC03");
     DirectorySearcher adSearcher = new DirectorySearcher(entry);
     adSearcher.Filter = "(& (samaccountname=" + userId.ToLower() + ")(objectClass=user))";
     adSearcher.PropertiesToLoad.Add("displayName");
     adSearcher.PropertiesToLoad.Add("mail");
     adSearcher.PropertiesToLoad.Add("co");
     adSearcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
     adSearcher.PropertyNamesOnly = true;
     SearchResult user = adSearcher.FindOne();
     if (user == null)
     {
         return string.Empty;
     }
     switch (property)
     {
         case ADProperties.Company:
             return (string)user.GetDirectoryEntry().Properties["co"].Value;
         case ADProperties.Market:
             return (string)user.GetDirectoryEntry().Properties["physicalDeliveryOfficeName"].Value;
         case ADProperties.UserEmail:
             return (string)user.GetDirectoryEntry().Properties["mail"].Value;
         case ADProperties.UserFullName:
             return (string)user.GetDirectoryEntry().Properties["displayName"].Value;
         default:
             return string.Empty;
     }
 }
        public ActionResult <ADProperties> GetAdsProperties(string userName)
        {
            ADProperties aDProperties = new ADProperties();

            try
            {
                const string LDAP_PATH = "LDAP://10.12.0.8"; //"/CN=VCH USERS,DC=MUSA,DC=net";
                                                             //const string LDAP_DOMAIN = "10.12.0.8";//"exldap.example.com:5555";
                //const string FirstName = "Cinthia";
                //const string LastName = "Schram";
                string titleValue      = "";
                string departmentValue = "";
                using (var ade = new System.DirectoryServices.DirectoryEntry(LDAP_PATH, "vgh\\ngediya", "Ayush080982"))
                    using (var dss = new System.DirectoryServices.DirectorySearcher(ade))
                    {
                        // string filter = @"(&(givenname=" + FirstName + ")(sn=" + LastName + "))";
                        string filter = @"(&(sAMAccountName=" + userName + "))";
                        //dss.Filter = "(sAMAccountName=ngediya)";
                        dss.Filter = filter;
                        System.DirectoryServices.SearchResult   sresult  = dss.FindOne();
                        System.DirectoryServices.DirectoryEntry dsresult = sresult.GetDirectoryEntry();
                        //Console.WriteLine("First Name:" + dsresult.Properties["givenname"][0].ToString());
                        //Console.WriteLine("Last Name:" + dsresult.Properties["cn"][0].ToString());
                        //Console.WriteLine("Full Name:" + dsresult.Properties["name"][0].ToString());
                        //Console.WriteLine("Mail:" + dsresult.Properties["mail"][0].ToString());
                        //Console.WriteLine("LoginId" + dsresult.Properties["sAMAccountName"][0].ToString());

                        foreach (var item in sresult.Properties.PropertyNames)
                        {
                            try
                            {
                                if (dsresult.Properties[item.ToString()].Count > 0)
                                { //Console.WriteLine(item.ToString() + ":" + dsresult.Properties[item.ToString()][0].ToString());
                                    if (item.ToString() == "title")
                                    {
                                        titleValue         = dsresult.Properties[item.ToString()][0].ToString();
                                        aDProperties.Title = titleValue;
                                    }
                                    if (item.ToString() == "department")
                                    {
                                        departmentValue       = dsresult.Properties[item.ToString()][0].ToString();
                                        aDProperties.Location = departmentValue;
                                    }
                                    if (item.ToString() == "givenname")
                                    {
                                        aDProperties.FirstName = dsresult.Properties[item.ToString()][0].ToString();
                                    }
                                    if (item.ToString() == "sn")
                                    {
                                        aDProperties.LastName = dsresult.Properties[item.ToString()][0].ToString();
                                    }
                                    if (item.ToString() == "mail")
                                    {
                                        aDProperties.EmailAddress = dsresult.Properties[item.ToString()][0].ToString();
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                //Console.WriteLine("Error ----->" + item.ToString());
                                return(null);
                            }
                        }
                    }

                return(aDProperties);
            }
            catch (Exception ex)
            {
                // _log.Log(LogLevel.Information, ex.Message);
                return(aDProperties);
            }
        }