init lserp cs 5.0

This commit is contained in:
cyf
2026-07-10 15:25:05 +08:00
commit 90f3fda86a
3799 changed files with 976868 additions and 0 deletions
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace HTB.DevFx.Security
{
/// <summary>
/// 当前系统用户认证器,存储当前用户认证信息
/// </summary>
public class Authenticator
{
/// <summary>
/// 当前登录的用户编号,未登录则为0
/// </summary>
public static int UserID
{
get { return HttpContext.Current.User.Identity.IsAuthenticated ? Convert.ToInt32(HttpContext.Current.User.Identity.Name) : 0; }
}
/// <summary>
/// 标示当前用户是否已经通过认证
/// </summary>
public static bool IsAuthenticated
{
get { return HttpContext.Current.User.Identity.IsAuthenticated; }
}
}
}
@@ -0,0 +1,143 @@
using System;
using System.Collections.Generic;
using System.Text;
using NOVA.DevFx.Security.Model;
using System.Data;
using NOVA.DevFx.Data.Utils;
using System.Data.SqlClient;
namespace NOVA.DevFx.Security.DataHandler
{
/// <summary>
/// 角色数据操作类
/// </summary>
public static class RoleHandler
{
/// <summary>
/// 将数据转换成实体类
/// </summary>
public static Role DataReaderToEntites(IDataReader dr)
{
Role model = new Role();
if (dr["id"].ToString() != "")
{
model.id = int.Parse(dr["id"].ToString());
}
model.name = dr["name"].ToString();
model.description = dr["description"].ToString();
if (dr["sort_index"].ToString() != "")
{
model.sort_index = int.Parse(dr["sort_index"].ToString());
}
return model;
}
/// <summary>
/// 获取指定用户编码的所有角色列表
/// </summary>
/// <returns></returns>
public static List<Role> GetListByUserID(int userid)
{
return GetList(" [id] in (select role_id from s_user_in_role where user_id="+userid.ToString()+")");
}
/// <summary>
/// 获得数据列表
/// </summary>
public static List<Role> GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,name,description,sort_index ");
strSql.Append(" FROM s_role ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString());
List<Role> m_lst = new List<Role>();
while (read.Read())
{
Role item = DataReaderToEntites(read);
if (item != null)
{
m_lst.Add(item);
}
}
read.Close();
return m_lst;
}
/// <summary>
/// 获取指定编号的用户信息
/// </summary>
/// <param name="uid"></param>
/// <returns></returns>
public static Role GetItem(int rid)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,name,description,sort_index ");
strSql.Append(" FROM s_role ");
strSql.Append(" WHERE [id]=@id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
int n = 0;
parameters[n++].Value = rid;
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString(), parameters);
Role item = null;
if (read.Read())
{
item = DataReaderToEntites(read);
}
if (item != null)
{
read.Close();
return item;
}
else
{
return null;
}
}
/// <summary>
/// 获取指定用户名的用户信息
/// </summary>
/// <param name="uid"></param>
/// <returns></returns>
public static Role GetItemByName(int uname)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,name,description,sort_index ");
strSql.Append(" FROM s_role ");
strSql.Append(" WHERE [name]=@name ");
SqlParameter[] parameters = {
new SqlParameter("@name", SqlDbType.VarChar,50)};
int n = 0;
parameters[n++].Value = uname;
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString(), parameters);
Role item = null;
if (read.Read())
{
item = DataReaderToEntites(read);
}
if (item != null)
{
read.Close();
return item;
}
else
{
return null;
}
}
}
}
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Text;
using NOVA.DevFx.Security.Model;
using System.Data.SqlClient;
using NOVA.DevFx.Data.Utils;
using System.Data;
namespace NOVA.DevFx.Security.DataHandler
{
/// <summary>
/// 角色权限关联数据访问类
/// </summary>
public static class RolePermissionHandler
{
/// <summary>
/// 将数据转换成实体类
/// </summary>
public static Role_In_Permission DataReaderToEntites(IDataReader dr)
{
Role_In_Permission model = new Role_In_Permission();
if (dr["id"].ToString() != "")
{
model.id = int.Parse(dr["id"].ToString());
}
if (dr["module_id"].ToString() != "")
{
model.module_id = int.Parse(dr["module_id"].ToString());
}
if (dr["role_id"].ToString() != "")
{
model.role_id = int.Parse(dr["role_id"].ToString());
}
if (dr["permission_id"].ToString() != "")
{
model.permission_id = int.Parse(dr["permission_id"].ToString());
}
if (dr["enabled"].ToString() != "")
{
if ((dr["enabled"].ToString() == "1") || (dr["enabled"].ToString().ToLower() == "true"))
{
model.enabled = true;
}
else
{
model.enabled = false;
}
}
return model;
}
/// <summary>
/// 获得数据列表
/// </summary>
public static List<Role_In_Permission> GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,module_id,role_id,permission_id,enabled ");
strSql.Append(" FROM s_role_in_permission ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString());
List<Role_In_Permission> m_lst = new List<Role_In_Permission>();
while (read.Read())
{
Role_In_Permission item = DataReaderToEntites(read);
if (item != null)
{
m_lst.Add(item);
}
}
read.Close();
return m_lst;
}
/// <summary>
/// 根据角色编号获取所有权限列表
/// </summary>
/// <returns></returns>
public static List<Role_In_Permission> GetPermissionListByRoleID(int roleid)
{
return GetList(" (role_id=" + roleid.ToString() + ")");
}
}
}
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Text;
using NOVA.DevFx.Security.Model;
using System.Data;
using NOVA.DevFx.Data.Utils;
using System.Data.SqlClient;
namespace NOVA.DevFx.Security.DataHandler
{
/// <summary>
/// 系统用户数据库访问类
/// </summary>
public static class UserHandler
{
/// <summary>
/// 将数据转换成实体类
/// </summary>
public static User DataReaderToEntites(IDataReader dr)
{
User model= new User();
if (dr["id"].ToString() != "")
{
model.id = int.Parse(dr["id"].ToString());
}
model.staff_id = dr["staff_id"].ToString();
model.name = dr["name"].ToString();
model.password = dr["password"].ToString();
if (dr["super_flag"].ToString() != "")
{
model.super_flag = bool.Parse(dr["super_flag"].ToString());
}
model.last_login_ip = dr["last_login_ip"].ToString();
if (dr["last_login_time"].ToString() != "")
{
model.last_login_time = DateTime.Parse(dr["last_login_time"].ToString());
}
model.description = dr["description"].ToString();
if (dr["sort_index"].ToString() != "")
{
model.sort_index = int.Parse(dr["sort_index"].ToString());
}
return model;
}
/// <summary>
/// 获得数据列表
/// </summary>
public static List<User> GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,staff_id,name,password,super_flag,last_login_ip,last_login_time,description,sort_index ");
strSql.Append(" FROM s_user ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString());
List<User> m_lst = new List<User>();
while (read.Read())
{
User item = DataReaderToEntites(read);
if (item != null)
{
m_lst.Add(item);
}
}
read.Close();
return m_lst;
}
/// <summary>
/// 根据角色编号获取所有用户
/// </summary>
/// <returns></returns>
public static List<User> GetUserListByRoleID(int roleid)
{
return GetList(" [id] in(select user_id from s_user_in_role where role_id=" + roleid.ToString() + ")");
}
/// <summary>
/// 获取指定编号的用户信息
/// </summary>
/// <param name="uid"></param>
/// <returns></returns>
public static User GetItem(int uid)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,staff_id,name,password,super_flag,last_login_ip,last_login_time,description,sort_index ");
strSql.Append(" FROM s_user ");
strSql.Append(" WHERE [id]=@id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
int n = 0;
parameters[n++].Value = uid;
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString(), parameters);
User item=null;
if (read.Read())
{
item = DataReaderToEntites(read);
}
if (item != null)
{
read.Close();
return item;
}
else
{
return null;
}
}
/// <summary>
/// 获取指定用户名的用户信息
/// </summary>
/// <param name="uid"></param>
/// <returns></returns>
public static User GetItemByName(string uname)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,staff_id,name,password,super_flag,last_login_ip,last_login_time,description,sort_index ");
strSql.Append(" FROM s_user ");
strSql.Append(" WHERE [name]=@name ");
SqlParameter[] parameters = {
new SqlParameter("@name", SqlDbType.VarChar,20)};
int n = 0;
parameters[n++].Value = uname;
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString(), parameters);
User item = null;
if (read.Read())
{
item = DataReaderToEntites(read);
}
if (item != null)
{
read.Close();
return item;
}
else
{
return null;
}
}
}
}
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Text;
using NOVA.DevFx.Security.Model;
using System.Data.SqlClient;
using NOVA.DevFx.Data.Utils;
using System.Data;
namespace NOVA.DevFx.Security.DataHandler
{
/// <summary>
/// 角色权限关联数据访问类
/// </summary>
public static class UserRoleHandler
{
/// <summary>
/// 将数据转换成实体类
/// </summary>
public static User_In_Role DataReaderToEntites(IDataReader dr)
{
User_In_Role model = new User_In_Role();
if (dr["id"].ToString() != "")
{
model.id = int.Parse(dr["id"].ToString());
}
if (dr["user_id"].ToString() != "")
{
model.user_id = int.Parse(dr["user_id"].ToString());
}
if (dr["role_id"].ToString() != "")
{
model.role_id = int.Parse(dr["role_id"].ToString());
}
return model;
}
/// <summary>
/// 获得数据列表
/// </summary>
public static List<User_In_Role> GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,user_id,role_id ");
strSql.Append(" FROM s_user_in_role ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
SqlDataReader read = SqlHelper.ExecuteReader(strSql.ToString());
List<User_In_Role> m_lst = new List<User_In_Role>();
while (read.Read())
{
User_In_Role item = DataReaderToEntites(read);
if (item != null)
{
m_lst.Add(item);
}
}
read.Close();
return m_lst;
}
/// <summary>
/// 根据角色编号获取所有用户列表
/// </summary>
/// <returns></returns>
public static List<User_In_Role> GetUserListByRoleID(int roleid)
{
return GetList(" (role_id=" + roleid.ToString() + ")");
}
/// <summary>
/// 根据用户编号获取所有角色列表
/// </summary>
/// <returns></returns>
public static List<User_In_Role> GetRoleListByUserID(int userid)
{
return GetList(" (user_id=" + userid.ToString() + ")");
}
}
}
@@ -0,0 +1,240 @@
using System;
using System.Collections.Generic;
using System.Text;
using NOVA.DevFx.Security.Model;
using NOVA.DevFx.Cache;
using System.Collections;
using NOVA.DevFx.OnlineManagement;
namespace NOVA.DevFx.Security.Handler
{
/// <summary>
/// 系统用户数据处理类
/// </summary>
public class UserHandler
{
private static string m_CachePrefix = "cache";
private static string m_UserCacheName = "user";
private static string m_PermissionCacheName = "permission";
private static string m_userCacher = "userCacher";
/// <summary>
/// 获取用户缓存器名称
/// </summary>
public static string UserCacherName
{
get { return m_userCacher; }
}
/// <summary>
/// 系统用户信息缓存器
/// </summary>
public static ICache UserCacher
{
get
{
ICache cacher = CacheHelper.GetCache(m_userCacher);
if (cacher == null)
return CacheHelper.CreateCache(m_userCacher);
else
return cacher;
}
}
#region
/// <summary>
/// 根据用户ID获取用户资料(从缓存中获取)
/// </summary>
/// <param name="UserID">用户ID</param>
/// <returns></returns>
public static User GetUser(int UserID)
{
string CacheKey = string.Format("{0}-{1}-{2}", m_CachePrefix,m_UserCacheName, UserID);
if (UserCacher[CacheKey] != null)
{
return (User)UserCacher[CacheKey];
}
else
{
//根据用户编码获取实体信息
User sUT = DataHandler.UserHandler.GetItem(UserID);
//添加用户信息到缓存中
UserCacher.Add(CacheKey, sUT);
return sUT;
}
}
/// <summary>
/// 根据用户登陆名,获取用户资料
/// </summary>
/// <param name="u_Name">用户名</param>
/// <returns>用户实体类</returns>
public static User GetUser(string u_Name)
{
return DataHandler.UserHandler.GetItemByName(u_Name);
}
/// <summary>
/// 根据用户ID移除用户资料Cache
/// </summary>
/// <param name="UserID"></param>
public static void RemoveUserCache(int UserID)
{
UserCacher.Remove(string.Format("{0}-{1}-{2}", m_CachePrefix, m_UserCacheName, UserID));
}
#endregion
#region
/// <summary>
/// 根据用户ID,模块ID判断用户是否拥有指定模块权限
/// </summary>
/// <param name="UserID">用户ID</param>
/// <param name="ModuleId">应用ID</param>
/// <returns></returns>
public static bool CheckPermission(int UserID, int ModuleId)
{
bool bBool = false;
//获取用户权限
Hashtable UserPermission = GetUserPermission(UserID);
if (UserPermission.Count > 0)
{
//判断当前用户是否有当前模块权限
if (UserPermission.ContainsKey(ModuleId))
{
bBool = true;
}
}
return bBool;
}
/// <summary>
/// 根据用户ID,模块ID,要检测权限数值
/// </summary>
/// <param name="UserID">用户ID</param>
/// <param name="P_ApplicationID">应用ID</param>
/// <param name="P_PageCode">PageCode</param>
/// <param name="CheckPermissionValue">权限值</param>
/// <returns></returns>
public static bool CheckPermission(int UserID, int ModuleId, int PermissionId)
{
bool bBool = false;
//获取用户权限列表
Hashtable UserPermission = GetUserPermission(UserID);
if (UserPermission.Count > 0)
{
string Key = string.Format("{0}-{1}", ModuleId, PermissionId);
if (UserPermission.ContainsKey(Key))
{
bBool = true;
}
}
return bBool;
}
/// <summary>
/// 获取用户权限Hashtable
/// </summary>
/// <param name="UserID">用户ID</param>
/// <returns></returns>
private static Hashtable GetUserPermission(int UserID)
{
string Key = string.Format("{1}-{2}-{0}", UserID, m_CachePrefix, m_PermissionCacheName);
if (UserCacher[Key] != null)
{
return (Hashtable)UserCacher[Key];
}
else
{
//从数据库中加载用户的所有权限信息
Hashtable _Temp = GetUserPermissionFromDataBase(UserID);
//添加权限信息到缓存中
UserCacher.Add(Key, _Temp);
return _Temp;
}
}
/// <summary>
/// 移除用户权限Cache
/// </summary>
/// <param name="UserID">用户ID</param>
public static void RemoveUserPermissionCache(int UserID)
{
UserCacher.Remove(string.Format("{1}-{2}-{0}", UserID, m_CachePrefix, m_PermissionCacheName));
}
/// <summary>
/// 移除某个角色的用户权限Cache
/// </summary>
/// <param name="RoleID"></param>
public static void RemoveRolePermissionCache(int RoleID)
{
//获取属于该角色的所有用户列表
List<User> lst = DataHandler.UserHandler.GetUserListByRoleID(RoleID);
//循环移除所有用户的权限缓存
foreach (User var in lst)
{
RemoveUserPermissionCache(var.id);
}
}
/// <summary>
/// 根据用户ID,获取用户模块权限列表
/// </summary>
/// <param name="UserID">用户ID</param>
/// <returns></returns>
private static Hashtable GetUserPermissionFromDataBase(int UserID)
{
Hashtable hsPermissionListCache = new Hashtable();
List<Role_In_Permission> lsRolePermission = new List<Role_In_Permission>();
//获取指定用户所拥有的所有角色
List<User_In_Role> lst = DataHandler.UserRoleHandler.GetRoleListByUserID(UserID);
foreach (User_In_Role var in lst)
{
//获取每个角色的权限
lsRolePermission = GetRolesPermission(var.role_id);
//循环添加所有用户权限
for (int i = 0; i < lsRolePermission.Count; i++)
{
string Key = string.Format("{0}-{1}", lsRolePermission[i].module_id, lsRolePermission[i].permission_id);
if (!hsPermissionListCache.ContainsKey(Key))
{
hsPermissionListCache.Add(Key, lsRolePermission[i]);
}
}
}
return hsPermissionListCache;
}
/// <summary>
/// 根据用户角色ID,获取权限列表
/// </summary>
/// <param name="RoleID">角色ID</param>
/// <param name="List">权限列表</param>
private static List<Role_In_Permission> GetRolesPermission(int RoleID)
{
List<Role_In_Permission> lst = DataHandler.RolePermissionHandler.GetPermissionListByRoleID(RoleID);
return lst;
}
#endregion
///// <summary>
///// 获取当前登陆用户信息
///// </summary>
//public static User CurrentUser
//{
// get
// {
// return GetUser(Authenticator.UserID);
// }
//}
}
}
@@ -0,0 +1,32 @@
/******************************************************************************
Copyright 2005-2007 R2@DevFx.NET
DevFx.NET is free software; you can redistribute it and/or modify
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DevFx.NET is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/*******************************************************************************/
using System.Security.Permissions;
namespace Lskj.DevFx.Security
{
/// <summary>
/// 拦截动作
/// </summary>
public enum InterceptorAction
{
/// <summary>
/// 要求拦截认证
/// </summary>
Demand = SecurityAction.Demand
}
}
@@ -0,0 +1,99 @@
/******************************************************************************
Copyright 2005-2007 R2@DevFx.NET
DevFx.NET is free software; you can redistribute it and/or modify
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DevFx.NET is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/*******************************************************************************/
using System;
using System.Security;
using System.Security.Permissions;
namespace Lskj.DevFx.Security
{
/// <summary>
/// 拦截属性
/// </summary>
[Serializable, AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class InterceptorAttribute : CodeAccessSecurityAttribute, IPermission
{
/// <summary>
/// 保护构造方法,用于调用基类的构造方法
/// </summary>
/// <param name="action"><see cref="SecurityAction"/></param>
protected InterceptorAttribute(SecurityAction action) : base(action) { }
/// <summary>
/// 构造方法
/// </summary>
/// <param name="action">拦截动作,目前只有<see cref="InterceptorAction.Demand"/></param>
public InterceptorAttribute(InterceptorAction action) : this((SecurityAction)action) {
}
/// <summary>
/// 拦截执行的方法
/// </summary>
protected virtual void Demand() {
}
#region Overrides of SecurityAttribute
///<summary>
///When overridden in a derived class, creates a permission object that can then be serialized into binary form and persistently stored along with the <see cref="T:System.Security.Permissions.SecurityAction" /> in an assembly's metadata.
///</summary>
///<returns>
///A serializable permission object.
///</returns>
public override IPermission CreatePermission() {
return this;
}
#endregion
#region IPermission Members
IPermission IPermission.Copy() {
throw new NotImplementedException();
}
void IPermission.Demand() {
this.Demand();
}
IPermission IPermission.Intersect(IPermission target) {
throw new NotImplementedException();
}
bool IPermission.IsSubsetOf(IPermission target) {
throw new NotImplementedException();
}
IPermission IPermission.Union(IPermission target) {
throw new NotImplementedException();
}
#endregion
#region ISecurityEncodable Members
void ISecurityEncodable.FromXml(SecurityElement e) {
throw new NotImplementedException();
}
SecurityElement ISecurityEncodable.ToXml() {
throw new NotImplementedException();
}
#endregion
}
}
@@ -0,0 +1,72 @@
using System;
using System.Web.Security;
namespace NOVA.DevFx.Security.Model
{
/// <summary>
/// 系统功能模块实体类
/// </summary>
[Serializable]
public class Module : NOVA.DevFx.Security.Model.IModule
{
public Module()
{}
#region Model
private int _id;
private string _name;
private string _description;
private bool _enabled;
private bool _system_flag;
private int _sort_index;
/// <summary>
/// 编码
/// </summary>
public int id
{
set{ _id=value;}
get{return _id;}
}
/// <summary>
/// 名称
/// </summary>
public string name
{
set{ _name=value;}
get{return _name;}
}
/// <summary>
/// 备注
/// </summary>
public string description
{
set{ _description=value;}
get{return _description;}
}
/// <summary>
/// 是否启用
/// </summary>
public bool enabled
{
set{ _enabled=value;}
get{return _enabled;}
}
/// <summary>
/// 是否系统内置模块
/// </summary>
public bool system_flag
{
set{ _system_flag=value;}
get{return _system_flag;}
}
/// <summary>
/// 排序编码
/// </summary>
public int sort_index
{
set{ _sort_index=value;}
get{return _sort_index;}
}
#endregion Model
}
}
@@ -0,0 +1,125 @@
using System;
namespace NOVA.DevFx.Security.Model
{
/// <summary>
/// 权限列表实体类
/// </summary>
[Serializable]
public class Permission
{
public Permission()
{}
#region Model
private int _id;
private string _name;
private int? _super_id;
private string _url;
private string _icon;
private string _description;
private bool _panel_flag;
private bool _enabled;
private int _module_id;
private bool _system_flag;
private bool _visibled;
private int _sort_index;
/// <summary>
/// 编码
/// </summary>
public int id
{
set{ _id=value;}
get{return _id;}
}
/// <summary>
/// 名称
/// </summary>
public string name
{
set{ _name=value;}
get{return _name;}
}
/// <summary>
/// 上级编码
/// </summary>
public int? super_id
{
set{ _super_id=value;}
get{return _super_id;}
}
/// <summary>
/// 连接URL
/// </summary>
public string url
{
set{ _url=value;}
get{return _url;}
}
/// <summary>
/// 菜单图标
/// </summary>
public string icon
{
set{ _icon=value;}
get{return _icon;}
}
/// <summary>
/// 备注
/// </summary>
public string description
{
set{ _description=value;}
get{return _description;}
}
/// <summary>
/// 是否面板
/// </summary>
public bool panel_flag
{
set{ _panel_flag=value;}
get{return _panel_flag;}
}
/// <summary>
/// 是否启用
/// </summary>
public bool enabled
{
set{ _enabled=value;}
get{return _enabled;}
}
/// <summary>
/// 所属功能模块
/// </summary>
public int module_id
{
set{ _module_id=value;}
get{return _module_id;}
}
/// <summary>
/// 是否系统内置
/// </summary>
public bool system_flag
{
set{ _system_flag=value;}
get{return _system_flag;}
}
/// <summary>
/// 是否可视
/// </summary>
public bool visibled
{
set{ _visibled=value;}
get{return _visibled;}
}
/// <summary>
/// 排序编码
/// </summary>
public int sort_index
{
set{ _sort_index=value;}
get{return _sort_index;}
}
#endregion Model
}
}
@@ -0,0 +1,53 @@
using System;
namespace NOVA.DevFx.Security.Model
{
/// <summary>
/// 用户角色实体类
/// </summary>
[Serializable]
public class Role
{
public Role()
{}
#region Model
private int _id;
private string _name;
private string _description;
private int _sort_index;
/// <summary>
/// 编码
/// </summary>
public int id
{
set{ _id=value;}
get{return _id;}
}
/// <summary>
/// 名称
/// </summary>
public string name
{
set{ _name=value;}
get{return _name;}
}
/// <summary>
/// 备注
/// </summary>
public string description
{
set{ _description=value;}
get{return _description;}
}
/// <summary>
/// 排序编码
/// </summary>
public int sort_index
{
set{ _sort_index=value;}
get{return _sort_index;}
}
#endregion Model
}
}
@@ -0,0 +1,62 @@
using System;
namespace NOVA.DevFx.Security.Model
{
/// <summary>
/// 用户与权限对应实体类
/// </summary>
[Serializable]
public class Role_In_Permission
{
public Role_In_Permission()
{}
#region Model
private int _id;
private int _module_id;
private int _role_id;
private int _permission_id;
private bool _enabled;
/// <summary>
/// 编码
/// </summary>
public int id
{
set{ _id=value;}
get{return _id;}
}
/// <summary>
/// 所属模块编码
/// </summary>
public int module_id
{
set{ _module_id=value;}
get{return _module_id;}
}
/// <summary>
/// 所属角色编码
/// </summary>
public int role_id
{
set{ _role_id=value;}
get{return _role_id;}
}
/// <summary>
/// 所属权限编码
/// </summary>
public int permission_id
{
set{ _permission_id=value;}
get{return _permission_id;}
}
/// <summary>
/// 是否启用
/// </summary>
public bool enabled
{
set{ _enabled=value;}
get{return _enabled;}
}
#endregion Model
}
}
@@ -0,0 +1,97 @@
using System;
namespace NOVA.DevFx.Security.Model
{
/// <summary>
/// 系统用户实体类
/// </summary>
[Serializable]
public class User
{
public User()
{}
#region Model
private int _id;
private string _staff_id;
private string _name;
private string _password;
private string _last_login_ip;
private DateTime? _last_login_time;
private string _description;
private int _sort_index;
/// <summary>
/// 编码
/// </summary>
public int id
{
set{ _id=value;}
get{return _id;}
}
/// <summary>
/// 员工号
/// </summary>
public string staff_id
{
set{ _staff_id=value;}
get{return _staff_id;}
}
/// <summary>
/// 用户名
/// </summary>
public string name
{
set{ _name=value;}
get{return _name;}
}
/// <summary>
/// 密码
/// </summary>
public string password
{
set{ _password=value;}
get{return _password;}
}
/// <summary>
/// 系统管理员标记
/// </summary>
public bool super_flag
{
get;
set;
}
/// <summary>
/// 最后登录IP
/// </summary>
public string last_login_ip
{
set{ _last_login_ip=value;}
get{return _last_login_ip;}
}
/// <summary>
/// 最后登录时间
/// </summary>
public DateTime? last_login_time
{
set{ _last_login_time=value;}
get{return _last_login_time;}
}
/// <summary>
/// 备注
/// </summary>
public string description
{
set{ _description=value;}
get{return _description;}
}
/// <summary>
/// 排序编码
/// </summary>
public int sort_index
{
set{ _sort_index=value;}
get{return _sort_index;}
}
#endregion Model
}
}
@@ -0,0 +1,44 @@
using System;
namespace NOVA.DevFx.Security.Model
{
/// <summary>
/// 用户与角色对应实体类
/// </summary>
[Serializable]
public class User_In_Role
{
public User_In_Role()
{}
#region Model
private int _id;
private int _user_id;
private int _role_id;
/// <summary>
/// 编码
/// </summary>
public int id
{
set{ _id=value;}
get{return _id;}
}
/// <summary>
/// 所属用户编码
/// </summary>
public int user_id
{
set{ _user_id=value;}
get{return _user_id;}
}
/// <summary>
/// 所属角色编码
/// </summary>
public int role_id
{
set{ _role_id=value;}
get{return _role_id;}
}
#endregion Model
}
}
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace NOVA.DevFx.Security
{
/// <summary>
/// 权限验证属性,如果无操作权限该方法或函数将拒绝执行,并抛出安全异常
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = true, Inherited = true)]
public class PermissionAttaible : Attribute
{
/// <summary>
/// 权限验证属性,如果无操作权限该方法或函数将拒绝执行,并抛出安全异常
/// </summary>
/// <param name="iPermissionId">权限编码</param>
/// <param name="iModuleId">所属模块编码</param>
public PermissionAttaible(int iPermissionId,int iModuleId)
{
_PType = iPermissionId;
_module_id = iModuleId;
}
/// <summary>
/// 权限验证属性,如果无操作权限该方法或函数将拒绝执行,并抛出安全异常
/// </summary>
/// <param name="iPermissionId">权限编码</param>
public PermissionAttaible(int iPermissionId)
{
_PType = iPermissionId;
}
/// <summary>
/// 权限类型
/// </summary>
private int _PType;
/// <summary>
/// 权限编码
/// </summary>
public int PermissionId
{
get
{
return _PType;
}
}
private int _module_id;
/// <summary>
/// 权限所属模块编码
/// </summary>
public int ModuleId
{
get { return _module_id; }
}
}
}
@@ -0,0 +1,90 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Configuration;
using System.Collections.Specialized;
using NOVA.DevFx.Core;
namespace HTB.DevFx.Security
{
/// <summary>
/// 读取Web.Config中Permission配置内容
/// </summary>
public class PermissionConfigLoad : IConfigurationSectionHandler
{
/// <summary>
/// 实现IConfigurationSectionHandler接口Create方法
/// </summary>
/// <param name="parent"></param>
/// <param name="configContext"></param>
/// <param name="section"></param>
/// <returns></returns>
public object Create(Object parent, Object configContext, System.Xml.XmlNode section)
{
Permission P_Mission = new Permission();
XmlNode AppNode = section.SelectSingleNode("ApplicationID");
P_Mission.module_id = Convert.ToInt32(AppNode.InnerText);
P_Mission.module_name = AppNode.Attributes["name"].Value;
AppNode = section.SelectSingleNode("PageCode");
//P_Mission.PageCode = AppNode.InnerText;
//P_Mission.PageCodeName = AppNode.Attributes["name"].Value;
List<string> Files = Common.GetDirFileList("aspx");
XmlNodeList ItemNodes = section.SelectNodes("Item");
foreach (XmlNode Node in ItemNodes)
{
PermissionItem Item = new PermissionItem();
Item.Item_Name = Node.Attributes["name"].Value;
Item.Item_Value = Convert.ToInt32(Node.Attributes["value"].Value);
Item.Item_FileList = Node.InnerText.ToLower();
P_Mission.ItemList.Add(Item);
if (Item.Item_FileList.Trim() != "")
{
RemoveFile(Files, Item.Item_FileList.Trim());
}
}
UpdatePermissionConfig(P_Mission, Files);
return P_Mission;
}
/// <summary>
/// 移除存在文件
/// </summary>
/// <param name="Files">所有文件列表</param>
/// <param name="FileString">要移除的文件名,多个以,号分开如:,1343.aspx,2342.aspx,</param>
private void RemoveFile(List<string> Files, string FileString)
{
string[] FileStringArray = FileString.Split(',');
for (int i = 0; i < FileStringArray.Length; i++)
{
if (FileStringArray[i].Trim() != "")
{
Files.Remove(FileStringArray[i].Trim());
}
}
}
/// <summary>
/// 更新权限配置文件表
/// </summary>
/// <param name="P_Mission">权限配置</param>
/// <param name="Files">文件名</param>
private void UpdatePermissionConfig(Permission P_Mission, List<string> Files)
{
if (Files.Count > 0)
{
PermissionItem Item = new PermissionItem();
Item.Item_Value = 2;
Item.Item_Name = "Look";
Item.Item_FileList = "";
foreach (string var in Files)
{
Item.Item_FileList = string.Format(",{0}{1}", var, Item.Item_FileList);
}
Item.Item_FileList = Item.Item_FileList + ",";
P_Mission.ItemList.Add(Item);
}
}
}
}
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Text;
using Lskj.DevFx.ExceptionManagement;
namespace Lskj.DevFx.Security
{
/// <summary>
/// 权限拒绝异常
/// </summary>
public class PermissionException : BaseException
{
private int _permissionid = 0;
private int _moduleid = 0;
/// <summary>
/// 被拒绝的权限代码
/// </summary>
public int PermissionID
{
get { return _permissionid; }
set { _permissionid = value; }
}
/// <summary>
/// 被拒绝的模块代码
/// </summary>
public int ModuleID
{
get { return _moduleid; }
set { _moduleid = value; }
}
/// <summary>
/// 权限拒绝错误构造
/// </summary>
/// <param name="moduleid">模块编码</param>
/// <param name="permissionid">权限编码</param>
/// <param name="message">消息</param>
/// <param name="innerException">内部错误</param>
public PermissionException(int moduleid,int permissionid,string message, Exception innerException)
: base(0, message, innerException)
{
_moduleid = moduleid;
_permissionid = permissionid;
}
/// <summary>
/// 权限拒绝错误构造
/// </summary>
/// <param name="moduleid">模块编码</param>
/// <param name="permissionid">权限编码</param>
/// <param name="innerException">内部错误</param>
public PermissionException(int moduleid, int permissionid, Exception innerException)
: base(0, "", innerException)
{
_moduleid = moduleid;
_permissionid = permissionid;
}
/// <summary>
/// 权限拒绝错误构造
/// </summary>
/// <param name="moduleid">模块编码</param>
/// <param name="permissionid">权限编码</param>
/// <param name="message">异常消息</param>
public PermissionException(int moduleid, int permissionid, string message)
: base(0, message,null)
{
_moduleid = moduleid;
_permissionid = permissionid;
}
}
}
@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Text;
using HTB.DevFx.Core;
using System.Configuration;
using HTB.DevFx.Utils;
using HTB.DevFx.OnlineManagement;
namespace HTB.DevFx.Security
{
/// <summary>
/// 权限检测类
/// </summary>
public class PermissionHelper
{
/// <summary>
/// 检测权限
/// </summary>
private bool CheckPermission()
{
//获取当前访问的页面文件目录下的权限配置文件
Permission Pis = GetModulePermission();
//如果未配置权限集合则直接返回true
if (Pis == null)
return true;
//如果用户已经经过认证
if (Authenticator.IsAuthenticated)
{
int UserID = Authenticator.UserID;
//从缓存中检查当前用户是否为超级用户
//如果是管理员则直接返回true
OnlineUser<string> _curUserOnlineInfo = OnlineUserHelper.UserOnlineList.GetValue(UserID);
if (_curUserOnlineInfo.U_Super_Flag)
return true;
//检测页面文件名访问权限
PermissionItem PsItem = GetPermissionItem(Pis.ItemList);
if (PsItem == null)
return false;
if (string.IsNullOrEmpty(WebHelper.GetScriptNameQueryString()))
return UserData.CheckPageCode(UserID, Pis.module_id, Pis.PageCode, PsItem.Item_Value);
else
{
if (!UserData.CheckPageCode(UserID, Pis.module_id, Pis.PageCode, PsItem.Item_Value))
{
return false;
}
else
{
//检测页面文件url权限
PsItem = GetUrlPermissionItem(Pis.ItemList);
if (PsItem == null)
return true;
return UserData.CheckPageCode(UserID, Pis.module_id, Pis.PageCode, PsItem.Item_Value);
}
}
}
else
{
return true;
}
}
/// <summary>
/// 获取当前目录下权限配置集合
/// </summary>
public static Permission GetModulePermission()
{
return (Permission)ConfigurationManager.GetSection("Permission");
}
/// <summary>
/// 获取当前面页所属的PermissionItem
/// </summary>
/// <param name="List">权限列表</param>
/// <returns></returns>
public static PermissionItem GetPermissionItem(List<PermissionItem> List)
{
PermissionItem PI = null;
string curUrlFileName =WebHelper.GetScriptNameWithDot();
foreach (PermissionItem var in List)
{
if (var.Item_FileList.IndexOf(WebHelper.GetScriptName().ToLower()) >= 0)
{
return var;
}
}
return PI;
}
/// <summary>
/// 获取当前面页Url所属的PermissionItem
/// </summary>
/// <param name="List">权限</param>
/// <returns>权限值</returns>
public static PermissionItem GetUrlPermissionItem(List<PermissionItem> List)
{
PermissionItem PI = null;
foreach (PermissionItem var in List)
{
if (var.Item_FileList.IndexOf("," + WebHelper.GetScriptNameUrl().ToLower() + ",") >= 0)
{
return var;
}
}
return PI;
}
/// <summary>
/// 检测按钮权限
/// </summary>
/// <param name="PT"></param>
/// <returns></returns>
public static bool CheckButtonPermission(int PermissionId)
{
Permission Pis = GetModulePermission();
if (Pis == null)
return true;
return UserData.CheckPageCode(Authenticator.UserID, Pis.ApplicationID, Pis.PageCode, PermissionId);
}
/// <summary>
/// 检测权限,如果无操作权限则直接返回
/// </summary>
/// <param name="PT"></param>
public static void CheckPermissionVoid(int PermissionId)
{
if (!CheckButtonPermission(PermissionId))
{
//发送无权限操作提示
}
}
}
}
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Principal;
using System.Diagnostics;
namespace HTB.DevFx.Security
{
/// <summary>
/// 方法属性权限检测类
/// </summary>
public class PermissionPrincipal : IPrincipal
{
private IIdentity _identity;
private string[] _roles;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="_IID"></param>
public PermissionPrincipal(IIdentity _IID)
{
_identity = _IID;
_roles = new string[1] { "check" };
}
/// <summary>
/// 检测角色资料
/// </summary>
/// <param name="role"></param>
/// <returns></returns>
public bool IsInRole(string role)
{
return Check_PopedomTypeAttaible();
}
/// <summary>
/// 用户标识
/// </summary>
public IIdentity Identity
{
get
{
return _identity;
}
}
private bool Check_PopedomTypeAttaible()
{
//System.Web.HttpResponse rp = System.Web.HttpContext.Current.Response;
//rp.Write("执行方法名称!");
//rp.Write(System.Reflection.MethodBase.GetCurrentMethod().Name);
//rp.Write("<br>");
StackTrace stack = new StackTrace();
foreach (StackFrame sframe in stack.GetFrames())
{
//rp.Write(sframe.GetMethod().Name);
//rp.Write("<br>");
foreach (PermissionAttaible var in sframe.GetMethod().GetCustomAttributes(typeof(PermissionAttaible), true))
{
//rp.Write(var.PType.ToString());
//rp.Write("<br>");
//rp.Write("无权限!");
//rp.End();
//return false;
PermissionHelper.CheckPermissionVoid(var.PermissionId);
}
//rp.Write("------");
//rp.Write("<br>");
}
//rp.End();
return true;
}
}
/// <summary>
/// 权限方法属性
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true, Inherited = true)]
public class PermissionAttaible : Attribute
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="PT"></param>
public PermissionAttaible(int PT)
{
_PType = PT;
}
/// <summary>
/// 权限类型
/// </summary>
private int _PType;
/// <summary>
/// 权限编码
/// </summary>
public int PermissionId
{
get
{
return _PType;
}
}
}
}