예제 #1
0
        /// <summary>
        /// 注册权限
        /// </summary>
        public static void LoadAuthorize()
        {
            AuthorizeData.Add(typeof(Read <User>), typeof(User));
            AuthorizeData.Add(typeof(Update <User>), typeof(User));
            AuthorizeData.Add(typeof(Create <User>), typeof(User));
            AuthorizeData.Add(typeof(Delete <User>), typeof(User));

            AuthorizeData.Add(typeof(Read <Role>), typeof(Role));
            AuthorizeData.Add(typeof(Update <Role>), typeof(Role));
            AuthorizeData.Add(typeof(Create <Role>), typeof(Role));
            AuthorizeData.Add(typeof(Delete <Role>), typeof(Role));

            AuthorizeData.Add(typeof(Read <Menus>), typeof(Menus));
            AuthorizeData.Add(typeof(Update <Menus>), typeof(Menus));
            AuthorizeData.Add(typeof(Create <Menus>), typeof(Menus));
            AuthorizeData.Add(typeof(Delete <Menus>), typeof(Menus));

            AuthorizeData.Add(typeof(Read <Attachment>), typeof(Attachment));
            AuthorizeData.Add(typeof(Update <Attachment>), typeof(Attachment));
            AuthorizeData.Add(typeof(Create <Attachment>), typeof(Attachment));
            AuthorizeData.Add(typeof(Delete <Attachment>), typeof(Attachment));
            AuthorizeData.Add(typeof(DownLoad <Attachment>), typeof(Attachment));

            AuthorizeData.Add(typeof(Read <Configuration>), typeof(Configuration));
            AuthorizeData.Add(typeof(Update <Configuration>), typeof(Configuration));
        }
 public void AddAuthorizeAttribute(params IAuthorizeData[] authorizeAttributes)
 {
     if (authorizeAttributes != null)
     {
         AuthorizeData.AddRange(authorizeAttributes);
     }
 }
예제 #3
0
        private IAuthorizeDataManager MockAuthorizeDataManager(AuthorizeData authorizeData)
        {
            var mockAuthorizeDataManager = new Mock <IAuthorizeDataManager>();

            mockAuthorizeDataManager.Setup(m => m.GetAuthorizeDataAsync()).Returns(Task.FromResult <AuthorizeData>(authorizeData));
            return(mockAuthorizeDataManager.Object);
        }
 public JsonResult GetAllAuthorizationStringList()
 {
     return(new JsonResult(HttpResult.Success(AuthorizeData.GetAuthorizeStringListSecurity())));
 }
 public JsonResult GetAllAuthorization()
 {
     return(new JsonResult(HttpResult.Success(AuthorizeData.GetTextAndStringSecurity())));
 }
예제 #6
0
    /// <summary>
    /// 进入考试场景
    /// </summary>
    public void SwitchToExam(Callback callback = null)
    {
        AuthorizeData auth = ConfigDataMgr.Instance.authorizeData;

        if (!auth.authorize || auth.authExpire)
        {
            UITipsDialog.ShowTips("软件未授权或授权到期");
            return;
        }
//#if CHAPTER_ONE
//        Callback LoadFinish = () =>
//        {
//            switch (GameDataMgr.instance.carType)
//            {
//                case CarType.DaZhong:
//                    UIManager.Instance.OpenUI<UIExamWindowDaZhong>();
//                    break;
//                case CarType.AiLiShe:
//                    UIManager.Instance.OpenUI<UIExamWindowAiLiShe>();
//                    break;
//                case CarType.BenTengB30:
//                    UIManager.Instance.OpenUI<UIExamWindowBenTengB30>();
//                    break;
//                case CarType.AiLiShe2015:
//                    UIManager.Instance.OpenUI<UIExamWindowAiLiShe2015>();
//                    break;
//            }
//            if (callback != null)
//            {
//                callback();
//            }
//        };

//        if (!ConfigDataMgr.instance.gameConfig.ios_audit)
//        {
//            UILoadingWindow uiLoadingWindow = UIManager.Instance.OpenUI<UILoadingWindow>();
//            AsyncOperation async = SceneManager.LoadSceneAsync(ExamScene);
//            uiLoadingWindow.InitWith(async, LoadFinish, true);
//        }
//        else
//        {
//            UILoadingDialog uiLoadingDialog = UIManager.Instance.OpenUI<UILoadingDialog>();
//            AsyncOperation async = SceneManager.LoadSceneAsync(ExamScene);
//            uiLoadingDialog.InitWith(async, LoadFinish, true);
//        }
//#elif CHAPTER_TWO
        Callback LoadFinish = () =>
        {
            //switch ((CarUID)GameDataMgr.Instance.carTypeData.uid)
            //{
            //    case CarUID.SangTaNa_Old:
            //    case CarUID.SangTaNa_New:
            //        UIManager.Instance.OpenUI<UIExamWindowDaZhong>();
            //        break;
            //    case CarUID.AiLiShe_Old:
            //    case CarUID.AiLiShe_New:
            //        UIManager.Instance.OpenUI<UIExamWindowAiLiShe>();
            //        break;
            //    case CarUID.BenTengB30_Old:
            //    case CarUID.BenTengB30_New:
            //        UIManager.Instance.OpenUI<UIExamWindowBenTengB30>();
            //        break;
            //    case CarUID.AiLiShe2_Old:
            //    case CarUID.AiLiShe2_New:
            //        UIManager.Instance.OpenUI<UIExamWindowAiLiShe2015>();
            //        break;
            //}
            switch (GameDataMgr.Instance.carTypeData.chexingcode)
            {
            case "sangtana":
                UIManager.Instance.OpenUI <UIExamWindowDaZhong>();
                break;

            case "ailishe":
                UIManager.Instance.OpenUI <UIExamWindowAiLiShe>();
                break;

            case "bentengb30":
                UIManager.Instance.OpenUI <UIExamWindowBenTengB30>();
                break;

            case "ailishe2":
                UIManager.Instance.OpenUI <UIExamWindowAiLiShe2015>();
                break;
            }
            if (callback != null)
            {
                callback();
            }
        };

        UILoadingDialog uiLoadingDialog = UIManager.Instance.OpenUI <UILoadingDialog>();
        AsyncOperation  async           = SceneManager.LoadSceneAsync(ExamScene);

        uiLoadingDialog.InitWith(async, LoadFinish, true);
//#endif
    }
        public async Task CombineAsyncTest()
        {
            IServiceProvider serviceProvider = CreateServices();

            using IServiceScope scope = serviceProvider.CreateScope();
            IPolicyCombiner policyCombiner = scope.ServiceProvider.GetRequiredService <IPolicyCombiner>();
            //如果使用AuthorizeAttribute
            AuthorizeData authorizeData = new AuthorizeData();
            var           policy        = await policyCombiner.CombineAsync(authorizeData);

            policy.AuthenticationSchemes.ShouldBeEmpty();
            policy.Requirements.Count().ShouldBe(1);
            policy.Requirements[0].ShouldBeOfType <DenyAnonymousAuthorizationRequirement>();


            authorizeData = new AuthorizeData()
            {
                Policies = new string[] { "test" }
            };
            policy = await policyCombiner.CombineAsync(authorizeData);

            policy.AuthenticationSchemes.ShouldBeEmpty();
            policy.Requirements.Count().ShouldBe(1);
            policy.Requirements[0].ShouldBeOfType <NameAuthorizationRequirement>();

            authorizeData = new AuthorizeData()
            {
                AllowedRoles = new string[] { "Administrator", "User" }
            };
            policy = await policyCombiner.CombineAsync(authorizeData);

            policy.AuthenticationSchemes.ShouldBeEmpty();
            policy.Requirements.Count().ShouldBe(1);
            policy.Requirements[0].ShouldBeOfType <RolesOrUsersAuthorizationRequirement>();

            authorizeData = new AuthorizeData()
            {
                AllowedRoles = new string[] { "Administrator", "User" }, Policies = new string[] { "test" }
            };
            policy = await policyCombiner.CombineAsync(authorizeData);

            policy.AuthenticationSchemes.ShouldBeEmpty();
            policy.Requirements.Count().ShouldBe(2);
            policy.Requirements.Count(r => r.GetType() == typeof(NameAuthorizationRequirement)).ShouldBe(1);
            policy.Requirements.Count(r => r.GetType() == typeof(RolesOrUsersAuthorizationRequirement)).ShouldBe(1);

            authorizeData = new AuthorizeData()
            {
                AllowedAllRoles = true
            };
            policy = await policyCombiner.CombineAsync(authorizeData);

            policy.AuthenticationSchemes.ShouldBeEmpty();
            policy.Requirements.Count().ShouldBe(1);
            policy.Requirements[0].ShouldBeOfType <DenyAnonymousAuthorizationRequirement>();

            authorizeData = new AuthorizeData()
            {
                DeniedAll = true
            };
            policy = await policyCombiner.CombineAsync(authorizeData);

            policy.AuthenticationSchemes.ShouldBeEmpty();
            policy.Requirements.Count().ShouldBe(1);
            policy.Requirements[0].ShouldBeOfType <DenyAllAuthorizationRequirement>();

            authorizeData = new AuthorizeData()
            {
                AllowedRoles = new string[] { "Administrator", "User" },
                AllowedUsers = new string[] { "1", "2" }
            };
            policy = await policyCombiner.CombineAsync(authorizeData);

            policy.AuthenticationSchemes.ShouldBeEmpty();
            policy.Requirements.Count().ShouldBe(1);
            policy.Requirements[0].ShouldBeOfType <RolesOrUsersAuthorizationRequirement>();

            policy = await policyCombiner.CombineAsync(null);

            policy.ShouldBeNull();
        }