예제 #1
0
파일: UserPermission.cs 프로젝트: bzure/BCF
 public virtual bool Authentication(IDroit Droit)
 {
     if (this.TokenLoadTime < Actor.Public.GetLastPermissionChangeTime())
         InitPermission(true);
     IDroit dt = this[Droit.Guid.ToString()];
     return dt == null ? false : Droit.IsSubsetOf(dt);
 }
예제 #2
0
        public virtual void AddDroit(IDroit droit)
        {
            IDroit drt  = _droitList.ContainsKey(droit.Guid.ToString()) ? _droitList[droit.Guid.ToString()] : null;
            bool   find = false;

            if (drt != null)
            {
                foreach (IAccessCode accessType in droit.AccessCodes)
                {
                    find = false;
                    foreach (IAccessCode at in drt.AccessCodes)
                    {
                        if (at.CodeValue == accessType.CodeValue)
                        {
                            find = true;
                            break;
                        }
                    }
                    if (!find)
                    {
                        drt.AccessCodes.Add(accessType.Copy());
                    }
                }
            }
            else
            {
                _droitList.Add(droit.Guid.ToString(), droit.Copy());
            }
        }
예제 #3
0
        /// <summary>
        /// 当前用户是否具有指定
        /// </summary>
        /// <param name="Me"></param>
        /// <param name="droit"></param>
        /// <returns></returns>
        public static bool Authorize(this Me Me, IDroit droit)
        {
            BzurePrincipal principal = Me.Principal as BzurePrincipal;

            if (principal == default(BzurePrincipal))
            {
                return(false);
            }
            return(principal.GetPermission().Authentication(droit));
        }
예제 #4
0
        public virtual bool Authentication(IDroit Droit)
        {
            if (this.TokenLoadTime < Actor.Public.GetLastPermissionChangeTime())
            {
                InitPermission(true);
            }
            IDroit dt = this[Droit.Guid.ToString()];

            return(dt == null ? false : Droit.IsSubsetOf(dt));
        }
예제 #5
0
파일: Droit.cs 프로젝트: bzure/BCF
 public bool IsSubsetOf(IDroit Droit)
 {
     foreach (IAccessCode at in this._accessTypes)
     {
         if (!Droit.Contains(at))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #6
0
        public virtual void RemoveDroit(IDroit droit)
        {
            IDroit drt = _droitList[droit.Guid.ToString()];

            if (drt != null)
            {
                foreach (IAccessCode accessType in droit.AccessCodes)
                {
                    foreach (IAccessCode at in drt.AccessCodes)
                    {
                        if (at.CodeValue == accessType.CodeValue)
                        {
                            drt.AccessCodes.Remove(at);
                            break;
                        }
                    }
                }
            }
        }
예제 #7
0
 public virtual void AddDroit(IDroit droit)
 {
     IDroit drt = _droitList.ContainsKey(droit.Guid.ToString()) ? _droitList[droit.Guid.ToString()] : null;
     bool find = false;
     if (drt != null)
     {
         foreach (IAccessCode accessType in droit.AccessCodes)
         {
             find = false;
             foreach (IAccessCode at in drt.AccessCodes)
                 if (at.CodeValue == accessType.CodeValue)
                 {
                     find = true;
                     break;
                 }
             if (!find)
                 drt.AccessCodes.Add(accessType.Copy ());
         }
     }
     else
         _droitList.Add(droit.Guid.ToString(), droit.Copy ());
 }
예제 #8
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            foreach (IAccessCode code in codes)
            {
                this._droit.AddAccessCode(code);
            }
            IDroit droit = this._droit.Copy();

            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            if (!httpContext.User.Identity.IsAuthenticated)
            {
                return(false);
            }
            BzurePrincipal principal = httpContext.User as BzurePrincipal;

            if (principal == default(BzurePrincipal))
            {
                return(false);
            }
            return(principal.GetPermission().Authentication(droit));
        }
예제 #9
0
파일: Droit.cs 프로젝트: bzure/BCF
 public bool IsSubsetOf(IDroit Droit)
 {
     foreach (IAccessCode at in this._accessTypes)
         if (!Droit.Contains(at))
             return false;
     return true;
 }
예제 #10
0
 public BzurePermissionException(string msg, PermissionExceptionType error, IDroit droit) :
     base(msg)
 {
     this.Droit       = droit;
     _permissionError = error;
 }
예제 #11
0
 public BzurePermissionException(string msg, PermissionExceptionType error, IDroit droit)
     : base(msg)
 {
     this.Droit = droit;
     _permissionError = error;
 }
예제 #12
0
 public virtual void FromXml(SecurityElement e)
 {
     if (e == null)
         throw new ArgumentNullException("e");
     if (e.Tag != "BzurePermission")
     {
         throw new ArgumentException("invalid tag type");
     }
     if (!(e.Attributes["class"] as string).StartsWith("Bzure.Security.Permissions.CAS.BzurePermission"))
     {
         throw new ArgumentException("invalid type");
     }
     if ((e.Attributes["version"] as string) != "1")
     {
         throw new ArgumentException("invalid version");
     }
     IDroit droit = new Droit(e.Attributes["guid"] as string);
     if (e.Children != null)
     {
         foreach (SecurityElement se in e.Children)
         {
             switch (se.Tag)
             {
                 case "accessType":
                     droit.AddAccessCode(new AccessCode(Convert.ToInt32(se.Text)));
                     break;
                 default:
                     break;
             }
         }
     }
     this._droit = droit;
 }
예제 #13
0
 public BzurePermission(IDroit Droit)
 {
     _droit = Droit.Copy();
 }
예제 #14
0
 public virtual void RemoveDroit(IDroit droit)
 {
     IDroit drt = _droitList[droit.Guid.ToString()];
     if (drt != null)
     {
         foreach (IAccessCode accessType in droit.AccessCodes)
         {
             foreach (IAccessCode at in drt.AccessCodes)
                 if (at.CodeValue == accessType.CodeValue)
                 {
                     drt.AccessCodes.Remove(at);
                     break;
                 }
         }
     }
 }