Exemple #1
0
            public static Object CreateFromModel(AdUserModel b)
            {
                //CurrentContext.ToPrincipalContext();
                var a = b.AutoCheckAccount();



                var v = "";



                return(v);
            }
Exemple #2
0
        public ActionResult Index()
        {
            var loginId = User.Identity.Name;
            //If user Id has main name prefix
            var domainIdx = loginId.IndexOf("\\") + 1;

            if (domainIdx != -1)
            {
                loginId = loginId.Substring(domainIdx);
            }
            AdUserModel userDetails = ActiveDirectoryHelper.GetUserDetailsFromLoginId(loginId);

            return(View(userDetails));
        }
Exemple #3
0
        public static AdUserModel GetUserDetailsFromLoginId(string samAccountName)
        {
            AdUserModel user = new AdUserModel()
            {
                AdLogin = samAccountName
            };

            try
            {
                if (!string.IsNullOrEmpty(samAccountName))
                {
                    using (var root = GetGlobalCatalog())
                    {
                        using (var searcher = new DirectorySearcher(root))
                        {
                            const string queryFormat = "(&(objectCategory=person)(objectClass=user)(sAMAccountName={0}))";

                            searcher.Filter = string.Format(queryFormat, samAccountName);
                            searcher.PropertiesToLoad.Add("*");

                            var result = searcher.FindOne();

                            if (result != null)
                            {
                                user.FirstName   = GetInfoFromResult(result, "givenname");
                                user.LastName    = GetInfoFromResult(result, "sn");
                                user.Department  = GetInfoFromResult(result, "department");
                                user.Email       = GetInfoFromResult(result, "mail");
                                user.DisplayName = GetInfoFromResult(result, "displayName");
                            }
                        }
                    }
                }
            }
            catch
            {
                //Ignore
            }

            return(user);
        }
Exemple #4
0
        public static BaseAdUserModelParser GenerateAdUserListFromRequest(String requestData)
        {
            NumberFormatInfo nfi  = NumberFormatInfo.CurrentInfo;
            List <string>    keys = new List <string>()
            {
                "Limited user", "Prenume", "Nume", "Functie",
                "Departament", "Manager", "Distribution Group", "Home Folder", "Share Drive access", "Telefon", "Office", "Setare Printare", "Mobil",
            };

            Dictionary <String, String> d = new Dictionary <string, string> {
                { "L(.*)us(.*)", "LimitedUser" }, { "Nume", "Name" }, { "Pre", "Surname" },
                { "Functie|Title", "Title" }, { "Dep(.*)ment", "Department" }, { "Ma(.*)ger", "Manager" },
                { "Dis(.*)roup", "DistributionGroup" }, { "Ho(.*)er", "HomeFolder" }, { "Sh(.*)ive", "ShareDriveAccess" }, { "Te(.*)", "Phone" }, { "Mobil", "Mobile" },
                { "Loca(.*)|Off(.*)", "Office" }, { "Print", "Printers" }
            };

            String pattern = "";

            keys.ForEach(s => {
                pattern += "((" + s + ")\\:(.*)\\r)|";
            });
            pattern = pattern.Substring(0, pattern.Length - 1);

            Match m;

            m = Regex.Match(requestData, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
            List <Match>        mm = new List <Match>();
            List <PropertyInfo> f  = typeof(BaseAdUserModelParser).GetProperties().ToList();

            while (m.Success)
            {
                mm.Add(m);
                m = m.NextMatch();
            }
            Dictionary <String, String> Pairs = new Dictionary <string, string>()
            {
            };
            int i = 0;

            mm.ForEach(s =>
            {
                Pairs.Add(s.Groups[2 + i].ToString(), s.Groups[3 + i].ToString());
                i += 3;
            });
            var ret = new AdUserModel();

            Pairs.Keys.ToList().ForEach(k =>
            {
                d.Keys.ToList().ForEach(j =>
                {
                    if (Regex.IsMatch(k, j, RegexOptions.IgnoreCase))

                    {
                        f.Find(a =>
                        {
                            return(a.Name == "Raw" + d[j]);
                        }).SetValue(ret, Pairs[k]);
                        //ret.RawLimitedUser = Pairs[k];
                    }
                    ;
                });
            });
            (ret as BaseAdUserModelParser).PrepareFix();
            ret.GetValues();
            return(ret);
        }
Exemple #5
0
        public JsonResult GetUserByUserId(string loginId)
        {
            AdUserModel userDetails = ActiveDirectoryHelper.GetUserDetailsFromLoginId(loginId);

            return(Json(userDetails, JsonRequestBehavior.AllowGet));
        }
        private AdUserModel GetActiveDirectoryUserInfo(string username, string password)
        {
            var    obj    = new AdUserModel();
            string adPath = "LDAP://172.20.82.57";

            LdapAuthentication adAuth = new LdapAuthentication(adPath);

            try
            {
                DirectoryEntry    de = new DirectoryEntry(adPath, username, password);
                DirectorySearcher ds = new DirectorySearcher(de);

                ds.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(samaccountname=" + username + "))";

                obj.UserName = username;
                obj.Password = password;

                ds.SearchScope = SearchScope.Subtree;
                SearchResult rs = ds.FindOne();

                if (rs.GetDirectoryEntry().Properties["givenName"].Value != null)
                {
                    obj.FirstName = rs.GetDirectoryEntry().Properties["givenName"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["sn"].Value != null)
                {
                    obj.LastName = rs.GetDirectoryEntry().Properties["sn"].Value.ToString();;
                }

                if (rs.GetDirectoryEntry().Properties["mail"].Value != null)
                {
                    obj.Email = rs.GetDirectoryEntry().Properties["mail"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["description"].Value != null)
                {
                    obj.Description = rs.GetDirectoryEntry().Properties["description"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["st"].Value != null)
                {
                    obj.State = rs.GetDirectoryEntry().Properties["st"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["telephoneNumber"].Value != null)
                {
                    obj.Phone = rs.GetDirectoryEntry().Properties["telephoneNumber"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["title"].Value != null)
                {
                    obj.JobTitle = rs.GetDirectoryEntry().Properties["title"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["co"].Value != null)
                {
                    obj.Country = rs.GetDirectoryEntry().Properties["co"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["department"].Value != null)
                {
                    obj.Department = rs.GetDirectoryEntry().Properties["department"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["company"].Value != null)
                {
                    obj.Company = rs.GetDirectoryEntry().Properties["company"].Value.ToString();
                }
                if (rs.GetDirectoryEntry().Properties["mobile"].Value != null)
                {
                    obj.Mobile = rs.GetDirectoryEntry().Properties["mobile"].Value.ToString();
                }
            }

            catch (Exception ex)
            {
                throw;
            }

            return(obj);
        }