Inheritance: System.Attribute
コード例 #1
0
        public void AuthorizeAsAttribute_SetsAction()
        {
            String actual = new AuthorizeAsAttribute("Action").Action;
            String expected = "Action";

            Assert.Equal(expected, actual);
        }
コード例 #2
0
        private String GetAuthorizedAs(MethodInfo action)
        {
            AuthorizeAsAttribute authorizedAs = action.GetCustomAttribute <AuthorizeAsAttribute>();

            if (authorizedAs == null || authorizedAs.Action == action.Name)
            {
                return(null);
            }

            return(authorizedAs.Action);
        }
コード例 #3
0
        private String GetAuthorizedAs(MemberInfo action)
        {
            if (!action.IsDefined(typeof(AuthorizeAsAttribute), false))
            {
                return(null);
            }

            AuthorizeAsAttribute authorizedAs = action.GetCustomAttribute <AuthorizeAsAttribute>(false);

            if (authorizedAs.Action == action.Name)
            {
                return(null);
            }

            return(authorizedAs.Action);
        }
コード例 #4
0
        private String GetRequiredPermission(Type type, MethodInfo method)
        {
            AuthorizeAsAttribute authorizeAs = method.GetCustomAttribute <AuthorizeAsAttribute>(false);
            String controller = GetController(type);
            String action     = GetAction(method);
            String area       = GetArea(type);

            if (authorizeAs != null)
            {
                type = GetControllerType(authorizeAs.Area ?? area, authorizeAs.Controller ?? controller);
                MethodInfo authorizeAsMethod = GetMethod(type, authorizeAs.Action);

                if (authorizeAsMethod != method)
                {
                    return(GetRequiredPermission(type, authorizeAsMethod));
                }
            }

            return(AllowsUnauthorized(type, method) ? null : (area + "/" + controller + "/" + action).ToLower());
        }
コード例 #5
0
        private String GetRequiredPermission(Type type, MethodInfo method)
        {
            AuthorizeAsAttribute authorizeAs = GetAuthorizeAs(method);
            String controller = GetController(type);
            String action     = GetAction(method);
            String area       = GetArea(type);

            if (authorizeAs != null)
            {
                type   = GetControllerType(authorizeAs.Area ?? area, authorizeAs.Controller ?? controller);
                method = GetMethod(type, authorizeAs.Action);

                return(GetRequiredPermission(type, method));
            }

            if (AllowsUnauthorized(type, method))
            {
                return(null);
            }

            return((area + "/" + controller + "/" + action).ToLower());
        }