Пример #1
0
        public Task <ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
        {
            ClaimsPrincipal newPrincipal = new ComBoostPrincipal(SecurityProvider);

            newPrincipal.AddIdentities(principal.Identities);
            return(Task.FromResult(newPrincipal));
        }
        public Task <ClaimsPrincipal> TransformAsync(ClaimsTransformationContext context)
        {
            var             securityProvider = context.Context.RequestServices.GetRequiredService <ISecurityProvider>();
            ClaimsPrincipal principal        = new ComBoostPrincipal(securityProvider);

            principal.AddIdentities(context.Principal.Identities);
            return(Task.FromResult(principal));
        }
        public static bool IsInDynamicRole(this IPrincipal principal, object role)
        {
            if (principal == null)
            {
                throw new ArgumentNullException(nameof(principal));
            }
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }
            if (!principal.Identity.IsAuthenticated)
            {
                return(false);
            }
            ComBoostPrincipal comboostPrincipal = principal as ComBoostPrincipal;

            if (comboostPrincipal == null)
            {
                return(false);
            }
            return(comboostPrincipal.IsInRole(role));
        }
        public static async Task <TPermission> GetPermission <TPermission>(this IPrincipal principal)
            where TPermission : IPermission
        {
            if (principal == null)
            {
                throw new ArgumentNullException(nameof(principal));
            }
            if (!principal.Identity.IsAuthenticated)
            {
                return(default(TPermission));
            }
            ComBoostPrincipal comboostPrincipal = principal as ComBoostPrincipal;

            if (comboostPrincipal == null)
            {
                return(default(TPermission));
            }
            string identity   = comboostPrincipal.Claims.First(t => t.Type == ClaimTypes.NameIdentifier).Value;
            var    permission = await comboostPrincipal.SecurityProvider.GetPermissionAsync(identity);

            return((TPermission)permission);
        }
        public static bool IsInStaticRole(this IPrincipal principal, object role)
        {
            if (principal == null)
            {
                throw new ArgumentNullException(nameof(principal));
            }
            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }
            if (!principal.Identity.IsAuthenticated)
            {
                return(false);
            }
            ComBoostPrincipal comboostPrincipal = principal as ComBoostPrincipal;

            if (comboostPrincipal == null)
            {
                return(false);
            }
            string roleName = comboostPrincipal.SecurityProvider.ConvertRoleToString(role);

            return(principal.IsInRole(roleName));
        }