public void OnAuthorization(AuthorizationFilterContext context)
        {
            if (!context.HttpContext.User.Identity.IsAuthenticated)
            {
                context.Result = new RedirectToRouteResult(new RouteValueDictionary(new { area = "", page = "/Identity/Signin", ReturnUrl = context.HttpContext.Request.Path.ToString() }));
                return;
            }

            if (!CustomAuthorization.ValidarRolesUsuario(context.HttpContext, _roleManager, _claim.Type, _claim.Value))
            {
                context.Result = new StatusCodeResult(403);
            }
        }
Exemple #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 = CustomAuthorization.ValidarRolesUsuario(_contextAccessor.HttpContext, _roleManager, IdentityRoleClaimName, IdentityRoleClaimValue);

            if (temAcesso)
            {
                return;
            }

            output.SuppressOutput();
        }
Exemple #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 = CustomAuthorization.ValidarRolesUsuario(_contextAccessor.HttpContext, _roleManager, IdentityClaimName, IdentityClaimValue);

            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"));
        }