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); }
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()); } }
/// <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)); }
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)); }
public bool IsSubsetOf(IDroit Droit) { foreach (IAccessCode at in this._accessTypes) { if (!Droit.Contains(at)) { return(false); } } return(true); }
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; } } } } }
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 ()); }
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)); }
public bool IsSubsetOf(IDroit Droit) { foreach (IAccessCode at in this._accessTypes) if (!Droit.Contains(at)) return false; return true; }
public BzurePermissionException(string msg, PermissionExceptionType error, IDroit droit) : base(msg) { this.Droit = droit; _permissionError = error; }
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; }
public BzurePermission(IDroit Droit) { _droit = Droit.Copy(); }
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; } } } }