Пример #1
0
 private static int GetPermission(User user, System.Reflection.CustomAttributeData customAttributeData)
 {
     if (customAttributeData != null)
     {
         var argument = customAttributeData.NamedArguments.FirstOrDefault(x => x.MemberName == "Role");
         if (argument != null && argument.TypedValue != null)
         {
             if (argument.TypedValue.Value != null)
             {
                 var value = (Role)argument.TypedValue.Value;
                 if (user.Role == value)
                 {
                     return(1);
                 }
                 else if (value == Role.Normal && user.Role == Role.Super || user.Role == Role.PartnerAccount)
                 {
                     return(1);
                 }
                 else
                 {
                     return(0);
                 }
             }
         }
     }
     return(-1);
 }
Пример #2
0
        public CustomAttributeData([NotNull] System.Reflection.CustomAttributeData customAttributeData)
        {
            Guard.ArgumentNotNull(customAttributeData,
                                  nameof(customAttributeData));

            _customAttributeData = customAttributeData;
        }
Пример #3
0
        /// <summary>
        /// Try Parse a <c>System.Reflection.CustomAttributeData</c> into a string
        /// </summary>
        /// <param name="attribute">(this)</param>
        /// <param name="s">Strng to parse into</param>
        /// <returns>True if success</returns>
        public static bool TryParse(this System.Reflection.CustomAttributeData attribute, out string s)
        {
            var flag = false;

            s = string.Empty;
            if (attribute != null)
            {
                s = attribute.ToString();
                var i = s.IndexOf('"');
                if (i >= 0)
                {
                    s    = s.Substring(i + 1);
                    flag = true;
                }

                i = s.IndexOf('"');
                if (i >= 0)
                {
                    s    = s.Substring(0, i);
                    flag = true;
                }
            }

            return(flag);
        }
Пример #4
0
        internal static string ParametersToString(System.Reflection.CustomAttributeData attr)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("[").Append(attr.Constructor.ReflectedType.FullName);
            if (attr.NamedArguments.Count > 0)
            {
                sb.Append("(");
                bool first = true;
                foreach (var x in attr.NamedArguments)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(", ");
                    }
                    sb.Append(x.MemberInfo.Name).Append(" = ").Append(x.TypedValue.Value);
                }
                sb.Append(")");
            }
            sb.Append("]");
            return(sb.ToString());
        }
        public static bool TryParse(this System.Reflection.CustomAttributeData attribute, out string s)
        {
            var flag = false;

            s = attribute.ToString();
            var i = s.IndexOf('"');

            if (i >= 0)
            {
                s = s[(i + 1)..]; flag = true;
        public void Constructor_ForCustomAttributeDataIsNull_Throws( )
        {
            _customAttributeData = null;

            Action action = () => CreateSut( );

            action.Should( )
            .Throw <ArgumentNullException> ( )
            .WithParameter("customAttributeData");
        }
Пример #7
0
 public static string GetId(this System.Reflection.CustomAttributeData a)
 {
     if (a.AttributeType != typeof(TestAttribute))
     {
         throw new ArgumentException();
     }
     foreach (var n in a.NamedArguments)
     {
         if (n.MemberName == "Id")
         {
             return(n.TypedValue.Value.ToString());
         }
     }
     return(null);
 }
        public void TestInitialize( )
        {
            var methodInfo = typeof(ParameterInfoTests).GetMethod(MethodNameWithString,
                                                                  new []
            {
                typeof(string)
            });

            if (methodInfo == null)
            {
                var message = string.Format(CultureInfo.InvariantCulture,
                                            $"Can't find method {MethodNameWithString}");

                throw new Exception(message);
            }

            var infos = methodInfo.GetParameters( );
            var info  = infos.First( );

            _customAttributeData = info.CustomAttributes.First( );
        }
Пример #9
0
        //private static CompositeFilterDescriptor DoManipulationOnFilterDescriptorItem(IFilterDescriptor filterDescriptor, Type viewType)
        //{
        //    var filterDescriptorItem = filterDescriptor as Kendo.Mvc.FilterDescriptor;
        //    var customAttributes = (viewType.GetProperty(filterDescriptorItem.Member) as System.Reflection.MemberInfo).CustomAttributes.SingleOrDefault(attr => attr.AttributeType.FullName == "Core.Mvc.Attribute.Filter.ComputedPropertyInfoAttribute");
        //    var filterItemCopy = filterDescriptorItem;
        //    if (customAttributes != null)
        //    {
        //        ReplaceViewModelFiltersToModelEquivalent(customAttributes, filterItemCopy);
        //    }
        //}


        private static void ReplaceViewModelFiltersToModelEquivalent(System.Reflection.CustomAttributeData customAttributes, FilterDescriptor filterItem)
        {
            //var ctrosArguments = customAttributes.ConstructorArguments;
            //var compositeFilterDescriptorItem = new CompositeFilterDescriptor();
            //if (ctrosArguments.Count != 0)
            //{
            //    compositeFilterDescriptorItem.FilterDescriptors = new Kendo.Mvc.Infrastructure.Implementation.FilterDescriptorCollection();
            //}
            //foreach (var argumentItem in ctrosArguments)
            //{
            //    if(argumentItem.ArgumentType.FullName == "System.String")
            //    {

            //    }
            //    else if(argumentItem.ArgumentType.FullName == "System.Array")
            //    {
            //        foreach(var arrItem in argumentItem.Value as System.Array){
            //            var filterDescriptor = new FilterDescriptor(arrItem.ToString(), filterItem.Operator, filterItem.Value);
            //            compositeFilterDescriptorItem.FilterDescriptors.Add(filterDescriptor);
            //       }

            //    }
            //}
        }
        public override bool IsAuthorized(AuthFilterContext context)
        {
            string AllowedAccessRoles = AccessRoles;

            dynamic Controller = context.ActionContext.ControllerContext.Controller;

            if (context.ActionContext.ActionDescriptor.ActionBinding.ActionDescriptor != null)
            {
                ReflectedHttpActionDescriptor reflectedHttpActionDescriptor = context.ActionContext.ActionDescriptor.ActionBinding.ActionDescriptor as ReflectedHttpActionDescriptor;

                if (reflectedHttpActionDescriptor != null && reflectedHttpActionDescriptor.MethodInfo != null && reflectedHttpActionDescriptor.MethodInfo.CustomAttributes != null)
                {
                    System.Reflection.CustomAttributeData MethodAuthorizeAccessRolesAttribute = reflectedHttpActionDescriptor.MethodInfo.CustomAttributes.Where(a => a.AttributeType.Name == "AuthorizeAccessRolesAttribute").FirstOrDefault();

                    if (MethodAuthorizeAccessRolesAttribute != null)
                    {
                        AllowedAccessRoles = MethodAuthorizeAccessRolesAttribute.NamedArguments[0].TypedValue.Value.ToString();
                    }
                }
            }

            try
            {
                //There are no explictly specifiled roles in attribute
                if (string.IsNullOrEmpty(AllowedAccessRoles))
                {
                    NameValueCollection QueryString = HttpUtility.ParseQueryString(context.ActionContext.Request.RequestUri.Query);

                    if (PortalSettings.Current.UserInfo.IsSuperUser)
                    {
                        return(true);
                    }

                    if (!string.IsNullOrEmpty(QueryString["identifier"]) && QueryString["identifier"] == "common_controls_editorconfig" && (PortalSettings.Current.UserInfo.IsInRole("Administrators") || ModulePermissionController.CanEditModuleContent(Controller.ModuleInfo())))
                    {
                        return(true);
                    }

                    if (QueryString != null && !string.IsNullOrEmpty(QueryString["identifier"]))
                    {
                        AllowedAccessRoles = Controller.AllowedAccessRoles(QueryString["identifier"]);
                    }

                    if (!string.IsNullOrEmpty(AllowedAccessRoles) && !string.IsNullOrEmpty(context.ActionContext.ActionDescriptor.ActionName) && context.ActionContext.ActionDescriptor.ActionName.ToLower() == "updatedata")
                    {
                        List <string> AllowedAccessRolesRolesArray = AllowedAccessRoles.Split(',').Distinct().ToList();
                        AllowedAccessRolesRolesArray.Remove("user");
                        AllowedAccessRolesRolesArray.Remove("anonymous");
                        AllowedAccessRoles = string.Join(",", AllowedAccessRolesRolesArray.Distinct());
                    }
                }

                if (!string.IsNullOrEmpty(AllowedAccessRoles))
                {
                    string   InRoles = Controller.AccessRoles();
                    string[] AllowedAccessRolesRolesArray = AllowedAccessRoles.Split(',');

                    if (!string.IsNullOrEmpty(InRoles))
                    {
                        foreach (string role in InRoles.Split(','))
                        {
                            if (AllowedAccessRolesRolesArray.Where(a => a == role).SingleOrDefault() != null)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
            }
            return(false);
        }
Пример #11
0
 internal CustomAttributeDataImpl(System.Reflection.CustomAttributeData customAttributeData)
 {
     Debug.Assert(customAttributeData != null);
     this.CustomAttributeData = customAttributeData;
 }
Пример #12
0
 internal CustomAttributeDataImpl(System.Reflection.CustomAttributeData customAttributeData)
 {
     Debug.Assert(customAttributeData != null);
     this.CustomAttributeData = customAttributeData;
 }