public void OnAuthorization(AuthorizationFilterContext context)
 {
     if (!context.HttpContext.User.Identity.IsAuthenticated)
     {
         var route = new RouteValueDictionary(new {
             area      = "Identity",
             page      = "/Account/Login",
             ReturnUrl = context.HttpContext.Request.Path.ToString()
         });
         context.Result = new RedirectToRouteResult(route);
         return;
     }
     if (!CustomAutorization.ValidaClaimsUsuario(context.HttpContext, _claim.Type, _claim.Value))
     {
         context.Result = new StatusCodeResult(403);
     }
 }
Example #2
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var temAcesso = CustomAutorization.ValidaClaimsUsuario(_contextAcessor.HttpContext, IdentityClaimName, IdentityClaimValue);

            if (temAcesso)
            {
                return;
            }

            output.SuppressOutput();
        }
Example #3
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var temAcesso = CustomAutorization.ValidaClaimsUsuario(_contextAcessor.HttpContext, IdentityClaimName, IdentityClaimValue);

            if (temAcesso)
            {
                return;
            }

            output.Attributes.RemoveAll("href");
            output.Attributes.Add(new TagHelperAttribute("style", "cursor: not-allowed"));
            output.Attributes.Add(new TagHelperAttribute("title", "Acesso negado"));
            output.Attributes.Add(new TagHelperAttribute("disable", "disable"));
        }
 public static IHtmlContent IfClaim(this IHtmlContent page, HttpContext context, string claimName, string claimValue)
 {
     return(CustomAutorization.ValidaClaimsUsuario(context, claimName, claimValue) ? page : null);
 }
 public static bool IfClaim(this RazorPage page, string claimName, string claimValue)
 {
     return(CustomAutorization.ValidaClaimsUsuario(page.Context, claimName, claimValue));
 }