示例#1
0
        public virtual bool IsInRole(string role)
        {
            if (role == null)
            {
                return(false);                  // ArgumentNullException
            }
            if (Environment.IsUnix)
            {
                // note: Posix is always case-sensitive
                return(IsMemberOfGroupName(Token, role));
            }
            else
            {
                // Windows specific code that
                // (a) build the role cache like the MS framework (for compatibility)
                // (b) case sensitive (for Fx 1.0) and case insensitive (later Fx)
                if (m_roles == null)
                {
                    m_roles = WindowsIdentity._GetRoles(Token);
                }

                role = role.ToUpperInvariant();
                foreach (string check in m_roles)
                {
                    if ((check != null) && (role == check.ToUpperInvariant()))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
示例#2
0
 /// <summary>Determines whether the current principal belongs to the Windows user group with the specified name.</summary>
 /// <returns>true if the current principal is a member of the specified Windows user group; otherwise, false.</returns>
 /// <param name="role">The name of the Windows user group for which to check membership. </param>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="MemberAccess" />
 /// </PermissionSet>
 public virtual bool IsInRole(string role)
 {
     if (role == null)
     {
         return(false);
     }
     if (WindowsPrincipal.IsPosix)
     {
         return(WindowsPrincipal.IsMemberOfGroupName(this.Token, role));
     }
     if (this.m_roles == null)
     {
         this.m_roles = WindowsIdentity._GetRoles(this.Token);
     }
     role = role.ToUpperInvariant();
     foreach (string text in this.m_roles)
     {
         if (text != null && role == text.ToUpperInvariant())
         {
             return(true);
         }
     }
     return(false);
 }