Exemple #1
0
 /// <summary>
 /// 验证权限符SId,如果返回大于0或通过,如果等于0表示没有设置过,如果小于0表示没有通过
 /// </summary>
 /// <param name="sid">权限符SId</param>
 /// <param name="principal">用户身份</param>
 /// <returns></returns>
 public static int IsAuthorization(Guid sid, System.Security.Principal.IPrincipal principal)
 {
     if (principal == null)
     {
         throw new System.ArgumentNullException("principal");
     }
     if (!principal.IsInRole(UMC.Security.Membership.AdminRole))
     {
         AuthManager wMger = new AuthManager(principal);//as WildcardManager;
         return(wMger.Check(sid.ToString())[0]);
     }
     else
     {
         return(1);
     }
 }
Exemple #2
0
        /// <summary>
        /// 批量验证权限
        /// </summary>
        /// <param name="wildcards"></param>
        /// <returns></returns>
        public static bool[] IsAuthorization(System.Security.Principal.IPrincipal princ, params string[] wildcards)
        {
            bool[] rerValue = new bool[wildcards.Length];
            if (wildcards.Length > 0)
            {
                if (princ.IsInRole(UMC.Security.Membership.AdminRole))
                {
                    for (var i = 0; i < rerValue.Length; i++)
                    {
                        rerValue[i] = true;
                    }
                    return(rerValue);
                }
                var list = new List <String>();
                foreach (var wildcard in wildcards)
                {
                    list.Add(wildcard);
                    int l = wildcard.Length - 1;

                    while (l > -1)
                    {
                        switch (wildcard[l])
                        {
                        case '.':
                            list.Add(wildcard.Substring(0, l) + ".*");
                            break;
                        }
                        l--;
                    }
                }
                var wMger = new AuthManager(princ);
                var vs = wMger.Check(list.ToArray());
                int start = 0, end = 0;

                for (int i = 1; i < wildcards.Length; i++)
                {
                    end             = list.FindIndex(w => wildcards[i] == w);
                    rerValue[i - 1] = IsAuthorization(vs, start, end);
                    start           = end;
                }
                rerValue[wildcards.Length - 1] = IsAuthorization(vs, start, vs.Length);
            }
            return(rerValue);
        }