/// <summary> /// 一种操作的权限删除 /// </summary> /// <param name="priv"></param> /// <returns></returns> public static int RemoveResource(Priv priv) { //using (DaoManager dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); try { //dao.BeginTransaction(); //删除权限表信息 privlogic.Delete(priv); //删除权限和角色对照表 privlogic.DelResRoleMap(priv.Id); //删除用户权限对照表 new AuthorityLogic().DeletePriByPriv(priv.Id); //dao.CommitTransaction(); return(1); } catch { //dao.RollBackTransaction(); return(0); } //} }
/// <summary> /// 删除权限 /// </summary> /// <param name="priv"></param> /// <returns></returns> public int Delete(Priv priv) { //using (DaoManager _dao = new DaoManager()) //{ // AbstractSqlModel _sql = new SqlModel("Security.Resource.DeleteForOneOp"); // _sql["resourceid"] = priv.Id; // DbCommand _command = _dao.DataConnection.CreateTextCommand(); // SqlMapping _mapping = new Neusoft.Framework.DataAccess.SqlMapping.SqlMapping(_dao, _sql); // _mapping.Mapper(_command); // return _command.ExecuteNonQuery(); //} string sql = ""; if (this.Sql.GetSql("SECURITY.RESOURCE.DELETEFORONEOP", ref sql) == -1) { return(-1); } try { sql = string.Format(sql, priv.Id); } catch (Exception ex) { this.Err = ex.Message; return(-1); } if (this.ExecNoQuery(sql) <= 0) { return(-1); } return(0); }
/// <summary> /// 撤销角色权限 /// </summary> public int Revoke(Role role, Priv resource, IList <Operation> operations) { // using (DaoManager _dao = new DaoManager()) // { PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); string _pmsExp = ""; if (_permission != null && _permission.Count > 0) //修改 { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } foreach (KeyValuePair <Priv, IList <Operation> > _pair in _permission) { foreach (Operation _opera in _pair.Value) { if (!IsContainOperation(_opera, operations)) { _pmsExp = _pmsExp + _opera.Id + "|"; } } break; } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, "")); } return(0); //} }
private TreeListViewItem GetTreeListViewItem(Priv _res) { TreeListViewItem _child = new TreeListViewItem(_res.Name, 5); _child.SubItems.AddRange(new string[] { _res.Id, _res.Description }); _child.Tag = _res; return(_child); }
/// <summary> /// 查询权限操作关系 /// </summary> /// <param name="resTypeId"></param> /// <param name="resId"></param> /// <param name="role"></param> /// <returns></returns> public IDictionary <Priv, IList <Operation> > QueryPermission(string resTypeId, string resId, Role role) { IDictionary <Priv, IList <Operation> > _permission = new Dictionary <Priv, IList <Operation> >(); //using (DaoManager _dao = new DaoManager()) //{ // AbstractSqlModel _sql = new SqlModel("Security.Resource.QueryPermission"); // _sql["resourcetype"] = resTypeId; // _sql["resourceid"] = resId; // _sql["roleid"] = role.Id; // DbCommand _command = _dao.DataConnection.CreateTextCommand(); // SqlMapping _mapping = new Neusoft.Framework.DataAccess.SqlMapping.SqlMapping(_dao, _sql); // _mapping.Mapper(_command); // DbDataReader _reader = _command.ExecuteReader(); //} string[] args = new string[] { resTypeId, resId, role.ID }; string sql = ""; if (this.Sql.GetSql("SECURITY.RESOURCE.QUERYPERMISSION", ref sql) == -1) { return(null); } try { sql = string.Format(sql, args); } catch (Exception ex) { this.Err = ex.Message; return(null); } if (this.ExecQuery(sql) < 0) { return(null); } while (this.Reader.Read()) { Priv _res = new Priv(); _res.Id = Reader[0].ToString(); _res.Name = Reader[1].ToString(); _res.ParentId = Reader[2].ToString(); _res.Type = Reader[3].ToString(); _res.Description = Reader[4].ToString(); IList <Operation> _operations = QueryOperation(Reader[5].ToString()); _permission.Add(_res, _operations); } Reader.Close(); return(_permission); }
private bool Judge(Dictionary <Priv, List <Organization> > privOrg, Priv currentPriv) { foreach (Priv priv in privOrg.Keys) { if (currentPriv.Id == priv.Id) { return(true); } } return(false); }
public LocalUserDTO(string computerName, string userName, bool enabled, uint rid, Priv userType, string comment, DateTime pwdLastSet, DateTime lastLogon, uint numLogins) { ComputerName = computerName; UserName = userName; Enabled = enabled; Rid = rid; UserType = userType; Comment = comment; PwdLastSet = pwdLastSet; LastLogon = lastLogon; NumLogins = numLogins; }
/// <summary> /// 撤销权限 /// </summary> /// <param name="ResourceType"></param> /// <param name="role"></param> /// <param name="resource"></param> /// <param name="operations"></param> /// <returns></returns> public int Revoke(string ResourceType, Role role, Priv resource, IList <Operation> operations) { // LoadPermissionProvider(); PermissionFactory.LoadPermissionProvider(); ResourceType _resType = GetResourceTypeByID(ResourceType); if (_resType == null) { throw new Exception("没有类型为:" + ResourceType + "的资源!"); } return(GetPermissionProviderByResType(_resType).Revoke(role, resource, operations)); }
private void SetCheckBox(TreeListViewItemCollection currentItemList, Priv res) { foreach (TreeListViewItem currentItem in currentItemList) { if ((currentItem.Tag as Priv).Id == res.Id) { currentItem.Checked = true; } if (currentItem != null) { SetCheckBox(currentItem.Items, res); } } }
/// <summary> /// 保存权限信息 /// </summary> /// <param name="res"></param> /// <returns></returns> public static int SaveResource(Priv res) { PrivLogic privlogic = new PrivLogic(); //using (DaoManager _dao = new DaoManager()) //{ int rtn = privlogic.Update(res); if (rtn == 0) { return(privlogic.Insert(res)); } //} return(0); }
private void SetChildNode(TreeNode parentNode) { Priv parentRes = parentNode.Tag as Priv; foreach (Priv res in privs) { if (res.ParentId == parentRes.Id && res.Type == parentRes.Type) { TreeNode newNode = new TreeNode(res.Name); newNode.Tag = res; parentNode.Nodes.Add(newNode); SetChildNode(newNode); } } }
/// <summary> /// 角色授权 /// </summary> public int Grant(Role role, Priv resource, IList <Operation> operations, object param) { //using (DaoManager _dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); string _pmsExp = ""; //新增 if (_permission.Count == 0) { foreach (Operation _opera in operations) { _pmsExp = _pmsExp + _opera.Id + "|"; } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, (param == null ? "" : param.ToString()))); } else //修改 { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } foreach (KeyValuePair <Priv, IList <Operation> > _pair in _permission) { foreach (Operation _opera in _pair.Value) { _pmsExp = _pmsExp + _opera.Id + "|"; } break; } foreach (Operation _opera in operations) { if (_pmsExp.IndexOf(_opera.Id) < 0) { _pmsExp = _pmsExp + _opera.Id + "|"; } } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, (param == null ? "" : param.ToString()))); } //} }
/// <summary> /// 查询权限 /// </summary> /// <param name="resourceType"></param> /// <returns></returns> public IList <Neusoft.HISFC.BizLogic.Privilege.Model.Priv> Query(string resourceType) { IList <Priv> _resources = new List <Priv>(); //using (DaoManager _dao = new DaoManager()) //{ //AbstractSqlModel _sql = new SqlModel("Security.Resource.QueryByType"); //_sql["resourcetype"] = resourceType; //DbCommand _command = _dao.DataConnection.CreateTextCommand(); //SqlMapping _mapping = new Neusoft.Framework.DataAccess.SqlMapping.SqlMapping(_dao, _sql); //_mapping.Mapper(_command); //DbDataReader _reader = _command.ExecuteReader(); //} string sql = ""; if (this.Sql.GetSql("SECURITY.RESOURCE.UPDATE", ref sql) == -1) { return(null); } try { sql = string.Format(sql, resourceType); } catch (Exception ex) { this.Err = ex.Message; return(null); } if (this.ExecQuery(sql) < 0) { return(null); } while (this.Reader.Read()) { Priv _res = new Priv(); _res.Id = Reader[0].ToString(); _res.Name = Reader[1].ToString(); _res.ParentId = Reader[2].ToString(); _res.Type = Reader[3].ToString(); _res.Description = Reader[4].ToString(); _resources.Add(_res); } Reader.Close(); return(_resources); }
/// <summary> /// 撤销角色对某一资源全部权限 /// </summary> public int Revoke(Role role, Priv resource) { //using (DaoManager _dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); if (_permission != null && _permission.Count > 0) //修改 { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } } return(0); //} }
/// <summary> /// 保存权限 /// </summary> /// <param name="resType"></param> /// <param name="role"></param> /// <param name="resource"></param> /// <param name="pmsExp"></param> /// <returns></returns> public static int SavePermission(string resType, Role role, Priv resource, string pmsExp) { //using (DaoManager _dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resType, resource.Id, role); //新增 if (_permission.Count > 0) { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } } return(privlogic.InsertResRoleMap(resource, role.ID, pmsExp, "")); //} }
/// <summary> /// 插入角色权限授权 /// </summary> /// <param name="resource"></param> /// <param name="roleId"></param> /// <param name="permission"></param> /// <param name="param"></param> /// <returns></returns> public int InsertResRoleMap(Priv resource, string roleId, string permission, string param) { //using (DaoManager _dao = new DaoManager()) //{ // AbstractSqlModel _sql = new SqlModel("Security.Resource.AddRoleMap"); // _sql["roleid"] = roleId; // _sql["resourceid"] = resource.Id; // _sql["resourcetype"] = resource.Type; // _sql["permission"] = permission; // _sql["param"] = param; // DbCommand _command = _dao.DataConnection.CreateTextCommand(); // SqlMapping _mapping = new Neusoft.Framework.DataAccess.SqlMapping.SqlMapping(_dao, _sql); // _mapping.Mapper(_command); // return _command.ExecuteNonQuery(); //} string[] args = new string[] { roleId, resource.Id, resource.Type, permission, param }; string sql = ""; if (this.Sql.GetSql("SECURITY.RESOURCE.ADDROLEMAP", ref sql) == -1) { return(-1); } try { sql = string.Format(sql, args); } catch (Exception ex) { this.Err = ex.Message; return(-1); } if (this.ExecNoQuery(sql) <= 0) { return(-1); } return(0); }
/// <summary> ///更新权限 /// </summary> /// <param name="res"></param> /// <returns></returns> public int Update(Priv res) { //using (DaoManager _dao = new DaoManager()) //{ // AbstractSqlModel _sql = new SqlModel("Security.Resource.Update"); // _sql["resourceid"] = res.Id; // _sql["resourcename"] = res.Name; // _sql["parentid"] = res.ParentId; // _sql["resourcetype"] = res.Type; // _sql["description"] = res.Description; // DbCommand _command = _dao.DataConnection.CreateTextCommand(); // SqlMapping _mapping = new Neusoft.Framework.DataAccess.SqlMapping.SqlMapping(_dao, _sql); // _mapping.Mapper(_command); // return _command.ExecuteNonQuery(); //} string[] args = new string[] { res.Id, res.Name, res.ParentId, res.Type, res.Description }; string sql = ""; if (this.Sql.GetSql("SECURITY.RESOURCE.UPDATE", ref sql) == -1) { return(-1); } try { sql = string.Format(sql, args); } catch (Exception ex) { this.Err = ex.Message; return(-1); } if (this.ExecNoQuery(sql) <= 0) { return(-1); } return(0); }
/// <summary> /// 是否允许角色对资源的操作 /// </summary> public bool IsAllowed(Role role, Priv resource, Operation operation) { PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); if (_permission == null || _permission.Count == 0) { return(false); } foreach (KeyValuePair <Priv, IList <Operation> > _pair in _permission) { foreach (Operation _opera in _pair.Value) { if (_opera.Id == operation.Id) { return(true); } } break; } return(false); }
/// <summary> /// 保存权限 /// </summary> /// <param name="resType"></param> /// <param name="role"></param> /// <param name="resource"></param> /// <param name="pmsExp"></param> /// <returns></returns> public int SavePermission(string resType, Role role, Priv resource, string pmsExp) { return(SecurityService.SavePermission(resType, role, resource, pmsExp)); }
/// <summary> /// 保存资源 /// </summary> /// <param name="res"></param> /// <returns></returns> public int SaveResource(Priv res) { return(SecurityService.SaveResource(res)); }
/// <summary> /// 删除资源 /// </summary> /// <param name="priv"></param> /// <returns></returns> public int RemoveResource(Priv priv) { return(SecurityService.RemoveResource(priv)); }