DefaultUserValidator.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:11k
源码类别:
OA系统
开发平台:
C#
- using System;
- using OThinker.Data;
- namespace OThinker.H3.Portal
- {
- /// <summary>
- /// 该类用于读取活动目录中的用户权限信息
- /// </summary>
- [System.Serializable]
- public class DefaultUserValidator : UserValidator
- {
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="UserID"></param>
- public DefaultUserValidator(string UserID)
- :
- base(UserID)
- {
- }
- #region 是否用于管理员权限
- /// <summary>
- /// 用于缓存验证,以免每次都去访问数据库
- /// </summary>
- private BoolMatchValue _ValidateAdministrator = BoolMatchValue.Unspecified;
- /// <summary>
- /// 验证当前用户是否具有管理员的权限
- /// </summary>
- /// <returns></returns>
- public override bool ValidateAdministrator()
- {
- // 首先检查是否是第一次获取该信息
- if(this._ValidateAdministrator == BoolMatchValue.Unspecified)
- {
- // 检查当前用户是否管理员
- if (OThinker.H3.Server.Engine.Organization.IsAdministrator(this.UserID))
- {
- this._ValidateAdministrator = BoolMatchValue.True;
- }
- else
- {
- this._ValidateAdministrator = BoolMatchValue.False;
- // 检查隶属于的组是否是服务器系统上的管理员或者域管理员
- if(this.MemberOfs != null && this.MemberOfs.Length != 0)
- {
- foreach(string memberOf in this.MemberOfs)
- {
- // 如果是管理员组的或者域管理员组的
- if (OThinker.H3.Server.Engine.Organization.IsAdministrator(memberOf))
- {
- this._ValidateAdministrator = BoolMatchValue.True;
- break;
- }
- }
- }
- // 如果属于服务器上的管理员,则不再检查,否则去数据库中检查该用户或者他属于的组是否管理员
- if(this._ValidateAdministrator == BoolMatchValue.True)
- {
- }
- else if (OThinker.H3.Server.Engine.SystemAclManager.Check(new string[]{this.UserID}, Acl.AclType.Admin))
- {
- // 检查是否属于本系统的管理员
- this._ValidateAdministrator = BoolMatchValue.True;
- }
- else if(OThinker.H3.Server.Engine.SystemAclManager.Check(this.RecursiveMemberOfs, Acl.AclType.Admin))
- {
- // 检查该用户所在的组或者组织单元是否拥有该权限
- this._ValidateAdministrator = BoolMatchValue.True;
- }
- else
- {
- this._ValidateAdministrator = BoolMatchValue.False;
- }
- }
- }
- return this._ValidateAdministrator == BoolMatchValue.True;
- }
- #endregion
- #region 是否能够发布新的流程
- private BoolMatchValue _ValidatePublishWorkflow = BoolMatchValue.Unspecified;
- /// <summary>
- /// 验证是否能够发布新版本
- /// </summary>
- /// <returns></returns>
- public override bool ValidatePublishWorkflow()
- {
- if(this._ValidatePublishWorkflow == BoolMatchValue.Unspecified)
- {
- if(this.ValidateAdministrator())
- {
- this._ValidatePublishWorkflow = BoolMatchValue.True;
- }
- else if (
- OThinker.H3.Server.Engine.SystemAclManager.Check(new string[]{this.UserID}, Acl.AclType.PublishWorkflow) ||
- OThinker.H3.Server.Engine.SystemAclManager.Check(this.RecursiveMemberOfs, Acl.AclType.PublishWorkflow))
- {
- // 检查该用户所在的组或者组织单元是否拥有该权限
- this._ValidatePublishWorkflow = BoolMatchValue.True;
- }
- else
- {
- this._ValidatePublishWorkflow = BoolMatchValue.False;
- }
- }
- return this._ValidatePublishWorkflow == BoolMatchValue.True;
- }
- #endregion
- #region 是否能够查看报表
- private BoolMatchValue _ValidateViewReport = BoolMatchValue.Unspecified;
- /// <summary>
- /// 是否能够查看报表
- /// </summary>
- /// <returns></returns>
- public override bool ValidateViewReport()
- {
- if (this._ValidateViewReport == BoolMatchValue.Unspecified)
- {
- if (this.ValidateAdministrator())
- {
- this._ValidateViewReport = BoolMatchValue.True;
- }
- else if (
- OThinker.H3.Server.Engine.SystemAclManager.Check(new string[] { this.UserID }, Acl.AclType.ViewReport) ||
- OThinker.H3.Server.Engine.SystemAclManager.Check(this.RecursiveMemberOfs, Acl.AclType.ViewReport))
- {
- // 检查该用户所在的组或者组织单元是否拥有该权限
- this._ValidateViewReport = BoolMatchValue.True;
- }
- else
- {
- this._ValidateViewReport = BoolMatchValue.False;
- }
- }
- return this._ValidateViewReport == BoolMatchValue.True;
- }
- #endregion
- #region 是否拥有流程模板的授权权限
- // 单元为(WorkflowFullName, BoolMatchValue)
- private System.Collections.Hashtable WorkflowAdministrotorValidationTable = new System.Collections.Hashtable();
- /// <summary>
- /// 是否拥有流程模板的授权权限
- /// </summary>
- /// <param name="WorkflowPackage"></param>
- /// <param name="WorkflowName"></param>
- /// <returns></returns>
- public override bool ValidateWorkflowAdministrator(string WorkflowPackage, string WorkflowName)
- {
- string processFullName = H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(WorkflowPackage, WorkflowName);
- if(!this.WorkflowAdministrotorValidationTable.Contains(processFullName))
- {
- OThinker.Data.BoolMatchValue validation;
- if(
- // 是否是系统管理员权限
- this.ValidateAdministrator() ||
- // 是否拥有流程管理员权限
- OThinker.H3.Server.Engine.WorkflowAclManager.Check(
- new string[]{this.UserID},
- WorkflowPackage,
- WorkflowName,
- Acl.AclType.Admin) ||
- // 所属的组是否拥有流程管理员的权限
- OThinker.H3.Server.Engine.WorkflowAclManager.Check(
- this.RecursiveMemberOfs,
- WorkflowPackage,
- WorkflowName,
- Acl.AclType.Admin))
- {
- // 检查该用户所在的组或者组织单元是否拥有该权限
- validation = BoolMatchValue.True;
- }
- else
- {
- validation = BoolMatchValue.False;
- }
- this.WorkflowAdministrotorValidationTable.Add(processFullName, validation);
- }
- return (BoolMatchValue)this.WorkflowAdministrotorValidationTable[processFullName] == BoolMatchValue.True;
- }
- #endregion
- #region 发起流程的权限
- // 单元为(WorkflowFullName, BoolMatchValue)
- private System.Collections.Hashtable CreateInstanceValidationTable = new System.Collections.Hashtable();
- /// <summary>
- /// 是否拥有创建流程的权限
- /// </summary>
- /// <param name="WorkflowPackage"></param>
- /// <param name="WorkflowName"></param>
- /// <returns></returns>
- public override bool ValidateCreateInstance(string WorkflowPackage, string WorkflowName)
- {
- string processFullName = H3.WorkflowTemplate.WorkflowTemplate.GetWorkflowFullName(WorkflowPackage, WorkflowName);
- if(!this.CreateInstanceValidationTable.Contains(processFullName))
- {
- OThinker.Data.BoolMatchValue validation;
- if(
- // 是否是系统管理员权限
- this.ValidateAdministrator() ||
- // 是否为流程管理员
- this.ValidateWorkflowAdministrator(WorkflowPackage, WorkflowName) ||
- // 没有对工作流模板权限做定义
- OThinker.H3.Server.Engine.WorkflowAclManager.GetAclCount(
- WorkflowPackage,
- WorkflowName) == 0 ||
- // 是否拥有流程发起权限
- OThinker.H3.Server.Engine.WorkflowAclManager.Check(
- new string[]{this.UserID},
- WorkflowPackage,
- WorkflowName,
- Acl.AclType.CreateInstance) ||
- // 所在的组是否拥有流程发起权限
- OThinker.H3.Server.Engine.WorkflowAclManager.Check(
- this.RecursiveMemberOfs,
- WorkflowPackage,
- WorkflowName,
- Acl.AclType.CreateInstance))
- {
- // 检查该用户所在的组或者组织单元是否拥有该权限
- validation = BoolMatchValue.True;
- }
- else
- {
- validation = BoolMatchValue.False;
- }
- this.CreateInstanceValidationTable.Add(processFullName, validation);
- }
- return (BoolMatchValue)this.CreateInstanceValidationTable[processFullName] == BoolMatchValue.True;
- }
- #endregion
- #region 管理实例的权限
- // 单元为(InstanceId, BoolMatchValue)
- private System.Collections.Hashtable InstanceAdministrotorValidationTable = new System.Collections.Hashtable();
- /// <summary>
- /// 管理流程实例的权限
- /// </summary>
- /// <param name="InstanceId"></param>
- /// <returns></returns>
- public override bool ValidateInstanceAdministrator(string InstanceId)
- {
- if(!this.InstanceAdministrotorValidationTable.Contains(InstanceId))
- {
- OThinker.Data.BoolMatchValue validation;
- if(
- // 是否是系统管理员权限
- this.ValidateAdministrator() ||
- // 是否拥有流程管理员权限
- OThinker.H3.Server.Engine.InstanceAclManager.Query(
- new string[]{this.UserID},
- InstanceId,
- OThinker.Data.BoolMatchValue.True,
- OThinker.Data.BoolMatchValue.Unspecified).Length != 0 ||
- // 所属的组是否拥有流程管理员的权限
- OThinker.H3.Server.Engine.InstanceAclManager.Query(
- this.RecursiveMemberOfs,
- InstanceId,
- OThinker.Data.BoolMatchValue.True,
- OThinker.Data.BoolMatchValue.Unspecified).Length != 0)
- {
- // 检查该用户所在的组或者组织单元是否拥有该权限
- validation = BoolMatchValue.True;
- }
- else
- {
- validation = BoolMatchValue.False;
- }
- this.InstanceAdministrotorValidationTable.Add(InstanceId, validation);
- }
- return (BoolMatchValue)this.InstanceAdministrotorValidationTable[InstanceId] == BoolMatchValue.True;
- }
- #endregion
- #region 查看实例的权限
- // 单元为(InstanceId, BoolMatchValue)
- private System.Collections.Hashtable InstanceViewValidationTable = new System.Collections.Hashtable();
- /// <summary>
- /// 查看流程实例的权限
- /// </summary>
- /// <param name="InstanceId"></param>
- /// <returns></returns>
- public override bool ValidateInstanceView(string InstanceId)
- {
- if(!this.InstanceViewValidationTable.Contains(InstanceId))
- {
- OThinker.Data.BoolMatchValue validation;
- if(
- // 是否是系统管理员权限
- this.ValidateAdministrator() ||
- // 是否有管理该实例的权限
- this.ValidateInstanceAdministrator(InstanceId) ||
- // 是否拥有流程管理员权限
- OThinker.H3.Server.Engine.InstanceAclManager.Query(
- new string[]{this.UserID},
- InstanceId,
- OThinker.Data.BoolMatchValue.Unspecified,
- OThinker.Data.BoolMatchValue.True).Length != 0 ||
- // 所属的组是否拥有流程管理员的权限
- OThinker.H3.Server.Engine.InstanceAclManager.Query(
- this.RecursiveMemberOfs,
- InstanceId,
- OThinker.Data.BoolMatchValue.Unspecified,
- OThinker.Data.BoolMatchValue.True).Length != 0)
- {
- // 检查该用户所在的组或者组织单元是否拥有该权限
- validation = BoolMatchValue.True;
- }
- else
- {
- validation = BoolMatchValue.False;
- }
- this.InstanceViewValidationTable.Add(InstanceId, validation);
- }
- return (BoolMatchValue)this.InstanceViewValidationTable[InstanceId] == BoolMatchValue.True;
- }
- #endregion
- }
- }