<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Wodsoft.ComBoost.Security
{
    public class ComBoostPrincipal : ClaimsPrincipal, IAuthentication
    {
        public ComBoostPrincipal(ISecurityProvider securityProvider)
        {
            if (securityProvider == null)
                throw new ArgumentNullException(nameof(securityProvider));
            SecurityProvider = securityProvider;
        }

        public ISecurityProvider SecurityProvider { get; private set; }

        public T GetUser<T>()
        {
            throw new NotImplementedException();
        }

        public bool IsInRole(object role)
        {
            throw new NotImplementedException();
        }
    }
}
<commit_msg>实现获取用户与判断权限方法<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Wodsoft.ComBoost.Security
{
    public class ComBoostPrincipal : ClaimsPrincipal, IAuthentication
    {
        public ComBoostPrincipal(ISecurityProvider securityProvider)
        {
            if (securityProvider == null)
                throw new ArgumentNullException(nameof(securityProvider));
            SecurityProvider = securityProvider;
        }

        public ISecurityProvider SecurityProvider { get; private set; }

        public T GetUser<T>()
        {
            if (!Identity.IsAuthenticated)
                return default(T);
            string id = ((ClaimsIdentity)Identity).FindFirst(t => t.Type == ClaimTypes.NameIdentifier).Value;
            return (T)SecurityProvider.GetPermissionAsync(id).Result;
        }

        public bool IsInRole(object role)
        {
            if (!Identity.IsAuthenticated)
                return false;
            string id = ((ClaimsIdentity)Identity).FindFirst(t => t.Type == ClaimTypes.NameIdentifier).Value;
            return SecurityProvider.GetPermissionAsync(id).Result.IsInRole(role);
        }
    }
}

{'fraction_non_alphanumeric': 0.08296943231441048, 'fraction_numerical': 0.0, 'mean_word_length': 2.5551724137931036, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4937870', 'n_tokens_mistral': 541, 'n_tokens_neox': 526, 'n_words': 110}