Esempio n. 1
0
        public void RefreshGroups()
        {
            DBEntities context       = COREobject.i.Context;
            string     groupADServer = WebConfigurationManager.AppSettings[$"Persona_AdGroupServer"];

            NexusLdapService ldap = new NexusLdapService();

            ldap.UseServer(groupADServer);

            // get ADgroup_User from AD
            List <ADgroup_User> rightsLdap = new List <ADgroup_User>();

            foreach (ADgroup group in context.ADgroups.ToList())
            {
                // For ADGroup with added RoleForApplication remove UserRoles
                if (!string.IsNullOrEmpty(group.RoleForApplication))
                {
                    foreach (User_Role userRole in context.Users_Roles.ToList())
                    {
                        if (userRole.ApplicationId == group.ApplicationId && userRole.RoleName == group.RoleForApplication)
                        {
                            context.Users_Roles.Remove(userRole);
                        }
                    }
                }

                var ADapps = ldap.GetGroups(group.Name);
                if (ADapps.Count() == 0)
                {
                    continue;
                }

                foreach (JToken ADapp in ADapps) // should be only 1
                {
                    foreach (JToken member in ADapp["member"])
                    {
                        // save user with groups
                        User user = AuthAD.getUserAndHisGroupsFromAD(identify: (string)member).Item1;

                        // Add UserRole according to ADGroup
                        if (!string.IsNullOrEmpty(group.RoleForApplication))
                        {
                            User_Role newUserRole = new User_Role();
                            newUserRole.UserId          = user.Id;
                            newUserRole.RoleName        = group.RoleForApplication;
                            newUserRole.ApplicationId   = group.ApplicationId ?? 0;
                            newUserRole.ApplicationName = context.Applications.Find(group.ApplicationId ?? 0).Name;
                            context.Users_Roles.Add(newUserRole);
                        }
                    }
                }
            }

            context.SaveChanges();
        }
Esempio n. 2
0
        public ActionResult Groups()
        {
            JToken           groups;
            List <string>    groupList = new List <string>();
            NexusLdapService service   = new NexusLdapService();

            ViewBag.Result = "";
            if (Request.HttpMethod == "POST")
            {
                string CN = Request.Form["query"];
                groups         = service.GetGroups(CN);
                ViewBag.Result = groups.ToString();
            }


            return(View("~/Views/Nexus/LDAP/GroupList.cshtml"));
        }
Esempio n. 3
0
        public static void RefreshFromAD(Modules.CORE.CORE core)
        {
            // refresh all users
            DBEntities context = core.Entitron.GetStaticTables();
            //foreach(User user in context.Users.ToList())
            //{
            //    core.Persona.RefreshUser(user);
            //}

            NexusLdapService ldap = new NexusLdapService();

            ldap.UseServer(groupADServer);

            // get ADgroup_User from AD
            List <ADgroup_User> rightsLdap = new List <ADgroup_User>();

            foreach (ADgroup group in context.ADgroups.ToList())
            {
                var ADapps = ldap.GetGroups(group.Name);
                if (ADapps.Count() == 0)
                {
                    continue;
                }

                foreach (JToken ADapp in ADapps) // should be only 1
                {
                    foreach (JToken member in ADapp["member"])
                    {
                        // save user with groups
                        core.Persona.GetUser(identify: (string)member);
                    }
                }
            }

            context.SaveChanges();
        }