Beispiel #1
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            if (!context.HttpContext.User.Identity.IsAuthenticated)
            {
                context.Result = new RedirectToRouteResult(
                    new RouteValueDictionary(new { area = "Identity", page = "/Account/Login", ReturnUrl = context.HttpContext.Request.Path.ToString() })
                    );

                return;
            }

            if (!CustomAuthorizarion.ValidarClaimsUsuario(context.HttpContext, _claim.Type, _claim.Value))
            {
                context.Result = new StatusCodeResult(403);
            }
        }
Beispiel #2
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context is null)
            {
                throw new ArgumentException(nameof(context));
            }

            if (output is null)
            {
                throw new ArgumentException(nameof(output));
            }

            var temAcesso = CustomAuthorizarion.ValidarClaimsUsuario(_contextAccessor.HttpContext, IdentityClaimType, IdentityClaimName);

            if (temAcesso)
            {
                return;
            }

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

            if (output is null)
            {
                throw new ArgumentException(nameof(output));
            }

            var temAcesso = CustomAuthorizarion.ValidarClaimsUsuario(_contextAccessor.HttpContext, IdentityClaimType, IdentityClaimName);

            if (temAcesso)
            {
                return;
            }

            output.Attributes.RemoveAll("href");
            output.Attributes.Add(new TagHelperAttribute("style", "cursor:not-allowed"));
            output.Attributes.Add(new TagHelperAttribute("title", "Você não tem Permissão"));
        }