Beispiel #1
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Uuid != null)
         {
             hashCode = hashCode * 59 + Uuid.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Description != null)
         {
             hashCode = hashCode * 59 + Description.GetHashCode();
         }
         if (SubRealmId != null)
         {
             hashCode = hashCode * 59 + SubRealmId.GetHashCode();
         }
         if (FunctionIds != null)
         {
             hashCode = hashCode * 59 + FunctionIds.GetHashCode();
         }
         if (RoleIds != null)
         {
             hashCode = hashCode * 59 + RoleIds.GetHashCode();
         }
         return(hashCode);
     }
 }
Beispiel #2
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var services    = context.HttpContext.RequestServices;
            var userManager = services.GetService <IUserManager>();
            var setting     = services.GetService <LexLibraryRbacSetting>();
            var request     = context.HttpContext.Request;

            // 跳過驗證
            if (context.ActionDescriptor.FilterDescriptors.Any(x => x.Filter is AllowAnonymousFilter))
            {
                return;
            }

            if (!userManager.IsLogin)
            {
                string returnUrl = request.GetDisplayUrl();
                string url       = string.Format("{0}?{1}={2}",
                                                 setting.LoginPath.ToString().TrimEnd('/'),
                                                 ApplicationConst.ReturnUrl,
                                                 HttpUtility.UrlEncode(returnUrl));

                context.Result = new RedirectResult(url);
                return;
            }

            IEnumerable <int> functionIds = null;

            if (!string.IsNullOrWhiteSpace(FunctionIds))
            {
                functionIds = FunctionIds
                              .Split(',')
                              .Select(x => int.TryParse(x, out int id) ? id : -1)
                              .Where(x => x > 0);
            }

            IEnumerable <int> roleIds = null;

            if (!string.IsNullOrWhiteSpace(RoleIds))
            {
                roleIds = RoleIds
                          .Split(',')
                          .Select(x => int.TryParse(x, out int id) ? id : -1)
                          .Where(x => x > 0);
            }

            if ((functionIds != null || roleIds != null) &&
                !userManager.HasPermission(functionIds, roleIds))
            {
                string url = request.GetBaseUrl();

                context.Result = redirectAndAlert(url, "權限不足,無法使用此功能。");
                return;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns true if Role instances are equal
        /// </summary>
        /// <param name="other">Instance of Role to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Role other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Uuid == other.Uuid ||
                     Uuid != null &&
                     Uuid.Equals(other.Uuid)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     FunctionIds == other.FunctionIds ||
                     FunctionIds != null &&
                     other.FunctionIds != null &&
                     FunctionIds.SequenceEqual(other.FunctionIds)
                 ) &&
                 (
                     UserIds == other.UserIds ||
                     UserIds != null &&
                     other.UserIds != null &&
                     UserIds.SequenceEqual(other.UserIds)
                 ) &&
                 (
                     RoleIds == other.RoleIds ||
                     RoleIds != null &&
                     other.RoleIds != null &&
                     RoleIds.SequenceEqual(other.RoleIds)
                 ));
        }