创建一个带身份验证与用户授权的XAF (WinForm类型),需要安装的包与各项配置
本文描述:从一个不安全的基本XAF,转变成一个安全的XAF(带身份验证与用户授权),必须的包与配置。
1、创建一个基础XAF,包括的内容,参考: 新建一个 面向目标 net5 的基础 XAF 项目(WinForm,不带安全的身份认证与授权) 。
2、创建一个带安全的XAF,比较两者:包与配置的差异,以便学习如何配置 “身份认证与用户授权 ”。
创建面向NetCore的 WinForm 型 XAF方案,使用 XPO 数据存储框架,身份认证Authentication,有两个选择:Standard(登录用户+密码)、AD活动目录。
1) 三个项目都依赖 :DevExpress.ExpressApp.Security.Xpo 包 ,间接依赖:DevExpress.ExpressApp.Security
2)在通用模块,增加了两个类:ApplicationUser.cs 、 ApplicationUserLoginInfo.cs ,代表用户,但映射的表不变(PermissionPolicyUser)。
DatabaseUpdate 目录下,Updater.cs 文件增加了 初始化两个用户User,一个角色Role 。
3)主体项目的Program.cs 增加了:
XXWindowsFormsApplication winApplication = new XXWindowsFormsApplication ();
winApplication.GetSecurityStrategy().RegisterXPOAdapterProviders(); ----- 增加的,好像意义不大。取消也没有什么影响???
4)主要配置改变,在 WinApplication.cs 的部分类 WinApplication.Designer.cs 的 InitializeComponent() 中, 具体如下:
A、 WinApplication.Designer.cs 定义了 3个属性
private DevExpress.ExpressApp.Security.SecurityModule securityModule1;
private DevExpress.ExpressApp.Security.SecurityStrategyComplex securityStrategyComplex1;
private DevExpress.ExpressApp.Security.AuthenticationStandard authenticationStandard1;
或 private DevExpress.ExpressApp.Security.AuthenticationActiveDirectory authenticationActiveDirectory1; ---- 两选一。
B、通过 InitializeComponent() 方法初始化
this.securityModule1 = new DevExpress.ExpressApp.Security.SecurityModule();
this.securityStrategyComplex1 = new DevExpress.ExpressApp.Security.SecurityStrategyComplex();
this.authenticationStandard1 = new DevExpress.ExpressApp.Security.AuthenticationStandard();
或 this.authenticationActiveDirectory1 = new DevExpress.ExpressApp.Security.AuthenticationActiveDirectory();
//--------------------------((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
this.securityStrategyComplex1.SupportNavigationPermissionsForTypes = false;
this.securityStrategyComplex1.Authentication = this.authenticationStandard1;
或 this.securityStrategyComplex1.Authentication = this.authenticationActiveDirectory1;
this.securityStrategyComplex1.RoleType = typeof(DevExpress.Persistent.BaseImpl.PermissionPolicy.PermissionPolicyRole); ---- 可改变
this.securityStrategyComplex1.UserType = typeof(XXXX.Module.BusinessObjects.ApplicationUser); ---- 可改变用户User
this.securityModule1.UserType = typeof(XXXX.Module.BusinessObjects.ApplicationUser);
this.authenticationStandard1.LogonParametersType = typeof(DevExpress.ExpressApp.Security.AuthenticationStandardLogonParameters);
this.authenticationStandard1.UserLoginInfoType = typeof(XXXX.Module.BusinessObjects.ApplicationUserLoginInfo);
或 this.authenticationActiveDirectory1.CreateUserAutomatically = true;
或 this.authenticationActiveDirectory1.LogonParametersType = null;
或 this.authenticationActiveDirectory1.UserLoginInfoType = typeof(XXXX.Module.BusinessObjects.ApplicationUserLoginInfo);
this.Modules.Add(this.securityModule1); ---- 加入模块
this.Security = this.securityStrategyComplex1; ---- 安全属性设置 !!!
//--------------------------((System.ComponentModel.ISupportInitialize)(this)).EndInit();