/// <summary>查询应用的权限信息</summary> /// <param name="command">通用SQL命令对象</param> /// <param name="scopeTableName">数据表的名称</param> /// <param name="entityId">实体标识</param> /// <param name="entityClassName">实体类名称</param> /// <param name="authorityName">权限名称</param> /// <returns></returns> public IList <MembershipAuthorizationScopeObject> GetAuthorizationScopeObjects(GenericSqlCommand command, string scopeTableName, string entityId, string entityClassName, string authorityName) { if (string.IsNullOrEmpty(entityId)) { new Exception("实体对象的标识不允许为空。"); } string scopeText = null; Dictionary <string, object> args = new Dictionary <string, object>(); AuthorityInfo authority = AuthorityContext.Instance.AuthorityService[authorityName]; args.Add("ScopeTableName", scopeTableName); args.Add("EntityId", entityId); args.Add("EntityClassName", entityClassName); args.Add("AuthorityId", authority.Id); string commandText = this.ibatisMapper.QueryForCommandText(StringHelper.ToProcedurePrefix(string.Format("{0}_GetAuthorizationScopeObjects", tableName)), args); DataTable table = command.ExecuteQueryForDataTable(commandText); foreach (DataRow row in table.Rows) { scopeText += row["AuthorizationObjectType"] + "#" + row["AuthorizationObjectId"] + "#" + row["AuthorizationObjectName"] + ";"; } IList <MembershipAuthorizationScopeObject> list = MembershipAuthorizationScopeManagement.GetAuthorizationScopeObjects(scopeText); return(list); }
/// <summary>查询应用的权限信息</summary> /// <param name="applicationId">应用标识</param> /// <param name="authorityName">权限名称</param> /// <returns></returns> public IList <MembershipAuthorizationScopeObject> GetAuthorizationScopeObjects(string applicationId, string authorityName) { if (string.IsNullOrEmpty(applicationId)) { new Exception("应用标识不允许为空."); } string scopeText = null; Dictionary <string, object> args = new Dictionary <string, object>(); AuthorityInfo authority = AuthorityContext.Instance.AuthorityService[authorityName]; args.Add("ApplicationId", applicationId); args.Add("AuthorityId", authority.Id); DataTable table = this.ibatisMapper.QueryForDataTable(StringHelper.ToProcedurePrefix(string.Format("{0}_GetAuthorizationScopeObjects", tableName)), args); foreach (DataRow row in table.Rows) { scopeText += row["AuthorizationObjectType"] + "#" + row["AuthorizationObjectId"] + ";"; } IList <MembershipAuthorizationScopeObject> list = MembershipAuthorizationScopeManagement.GetAuthorizationScopeObjects(scopeText); return(list); }
/// <summary>绑定查看权限</summary> /// <param name="scopeText"></param> public void BindAuthorizationReadScope(string scopeText) { // 清空缓存数据 this.m_AuthorizationReadScopeObjectText = null; this.m_AuthorizationReadScopeObjectView = null; MembershipAuthorizationScopeManagement.BindAuthorizationScopeObjects(this.AuthorizationReadScopeObjects, scopeText); }
/// <summary>绑定修改权限</summary> /// <param name="scopeText"></param> public void BindAuthorizationEditScope(string scopeText) { // 清空缓存数据 this.m_AuthorizationEditScopeObjectText = null; this.m_AuthorizationEditScopeObjectView = null; if (this.m_AuthorizationEditScopeObjects == null) { this.m_AuthorizationEditScopeObjects = new List <MembershipAuthorizationScopeObject>(); } MembershipAuthorizationScopeManagement.BindAuthorizationScopeObjects(this.m_AuthorizationEditScopeObjects, scopeText); }
// ------------------------------------------------------- // 权限 // ------------------------------------------------------- #region 私有函数:GetAuthorizationReadObject(ApplicationMenuInfo param) ///<summary>验证对象的权限</summary> ///<param name="param">需验证的对象</param> ///<returns>对象</returns> private ApplicationMenuInfo GetAuthorizationReadObject(ApplicationMenuInfo param) { IAccountInfo account = KernelContext.Current.User; if (AppsSecurity.IsAdministrator(account, AppsConfiguration.ApplicationName)) { return(param); } else { if (MembershipAuthorizationScopeManagement.Authenticate(param.AuthorizationReadScopeObjects, account)) { return(param); } return(null); } }
/// <summary>获取帐号相关的权限对象</summary> /// <param name="account">IAccount 实例的详细信息</param> public IList <MembershipAuthorizationScopeObject> GetAuthorizationScopeObjects(IAccountInfo account) { string scopeText = null; IList <IAuthorizationScope> result = new List <IAuthorizationScope>(); Dictionary <string, object> args = new Dictionary <string, object>(); args.Add("WhereClause", string.Format(" AccountId = '{0}' ", StringHelper.ToSafeSQL(account.Id))); DataTable table = this.ibatisMapper.QueryForDataTable(StringHelper.ToProcedurePrefix(string.Format("{0}_GetAuthorizationScopesByAccount", tableName)), args); foreach (DataRow row in table.Rows) { scopeText += row["AuthorizationObjectType"] + "#" + row["AuthorizationObjectId"] + "#" + row["AuthorizationObjectName"] + ";"; } return(MembershipAuthorizationScopeManagement.GetAuthorizationScopeObjects(scopeText)); }
// ------------------------------------------------------- // 权限设置 // ------------------------------------------------------- #region 函数:HasAuthorizationReadObject(BugInfo param) /// <summary>验证对象的权限</summary> /// <param name="param">需验证的对象</param> /// <returns>对象</returns> private bool HasAuthority(BugInfo param) { IAccountInfo account = KernelContext.Current.User; if (AppsSecurity.IsAdministrator(account, "Bug") || param.AccountId == account.Id || param.AssignToAccountId == account.Id) { return(true); } else { if (MembershipAuthorizationScopeManagement.Authenticate(param.AuthorizationReadScopeObjects, account)) { return(true); } return(false); } }
// ------------------------------------------------------- // 权限设置 // ------------------------------------------------------- #region 函数:GetAuthorizationScopeObjects(string entityId, string authorityName) /// <summary>查询实体对象的权限信息</summary> /// <param name="entityId">实体标识</param> /// <param name="authorityName">权限名称</param> /// <returns></returns> public IList <MembershipAuthorizationScopeObject> GetAuthorizationScopeObjects(string entityId, string authorityName) { string scopeText = null; IList <IAuthorizationScope> result = new List <IAuthorizationScope>(); Dictionary <string, object> args = new Dictionary <string, object>(); args.Add("Id", StringHelper.ToSafeSQL(entityId)); DataTable table = this.ibatisMapper.QueryForDataTable(StringHelper.ToProcedurePrefix(string.Format("{0}_GetAuthorizationScope", this.tableName)), args); foreach (DataRow row in table.Rows) { if (!string.IsNullOrEmpty(row["AuthorizationObjectType"].ToString()) && !string.IsNullOrEmpty(row["AuthorizationObjectId"].ToString())) { scopeText += row["AuthorizationObjectType"] + "#" + row["AuthorizationObjectId"] + ";"; } } return(MembershipAuthorizationScopeManagement.GetAuthorizationScopeObjects(scopeText)); }