public void AuthorizeAsAttribute_SetsAction() { String actual = new AuthorizeAsAttribute("Action").Action; String expected = "Action"; Assert.Equal(expected, actual); }
private String GetAuthorizedAs(MethodInfo action) { AuthorizeAsAttribute authorizedAs = action.GetCustomAttribute <AuthorizeAsAttribute>(); if (authorizedAs == null || authorizedAs.Action == action.Name) { return(null); } return(authorizedAs.Action); }
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); }
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()); }
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()); }