Пример #1
0
        public static IEnumerable <KeyValuePair <string, string> > GetSpecialistList(AdGroup grp)
        {
            var list = new Dictionary <string, string>();

            using (WindowsImpersonationContextFacade impersonationContext
                       = new WindowsImpersonationContextFacade(
                             nc))
            {
                var domain = new PrincipalContext(ContextType.Domain);
                var group  = GroupPrincipal.FindByIdentity(domain, IdentityType.Sid, AdUserGroup.GetSidByAdGroup(grp));
                if (group != null)
                {
                    var members = group.GetMembers(true);
                    foreach (var principal in members)
                    {
                        var userPrincipal = UserPrincipal.FindByIdentity(domain, principal.SamAccountName);
                        if (userPrincipal != null)
                        {
                            var name = StringHelper.ShortName(userPrincipal.DisplayName);
                            var sid  = userPrincipal.Sid.Value;
                            list.Add(sid, name);
                        }
                    }
                }

                return(list.OrderBy(x => x.Value));
            }
        }
Пример #2
0
        public static IEnumerable <Specialist> GetSpecialistListS(AdGroup grp)
        {
            var list = new List <Specialist>();

            using (WindowsImpersonationContextFacade impersonationContext
                       = new WindowsImpersonationContextFacade(
                             nc))
            {
                var domain = new PrincipalContext(ContextType.Domain);
                var group  = GroupPrincipal.FindByIdentity(domain, IdentityType.Sid, AdUserGroup.GetSidByAdGroup(grp));
                if (group != null)
                {
                    var members = group.GetMembers(true);
                    foreach (var principal in members)
                    {
                        var userPrincipal = UserPrincipal.FindByIdentity(domain, principal.SamAccountName);
                        if (userPrincipal != null)
                        {
                            var fullName    = userPrincipal.DisplayName;
                            var displayName = StringHelper.ShortName(userPrincipal.DisplayName);
                            var sid         = userPrincipal.Sid.Value;
                            list.Add(new Specialist()
                            {
                                SpecialistSid = sid,
                                FullName      = fullName,
                                DisplayName   = displayName
                            });
                        }
                    }
                }

                return(list);
            }
        }
Пример #3
0
        public static bool UserInGroup(string sid, params AdGroup[] groups)
        {
            using (WindowsImpersonationContextFacade impersonationContext
                       = new WindowsImpersonationContextFacade(
                             nc))
            {
                var context       = new PrincipalContext(ContextType.Domain);
                var userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.Sid, sid);

                if (userPrincipal == null)
                {
                    return(false);
                }
                ////if (userPrincipal.IsMemberOf(context, IdentityType.Sid, AdUserGroup.GetSidByAdGroup(AdGroup.SuperAdmin))) { return true; }//Если юзер Суперадмин

                foreach (var grp in groups)
                {
                    if (userPrincipal.IsMemberOf(context, IdentityType.Sid, AdUserGroup.GetSidByAdGroup(grp)))
                    {
                        return(true);
                    }
                }


                return(false);
            }
        }