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);
     }
 }
Exemplo n.º 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();
        }
Exemplo n.º 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"));
        }
Exemplo n.º 4
0
 public static IHtmlContent IfClaim(this IHtmlContent page, HttpContext context, string claimName, string claimValue)
 {
     return(CustomAutorization.ValidaClaimsUsuario(context, claimName, claimValue) ? page : null);
 }
Exemplo n.º 5
0
 public static bool IfClaim(this RazorPage page, string claimName, string claimValue)
 {
     return(CustomAutorization.ValidaClaimsUsuario(page.Context, claimName, claimValue));
 }