Example #1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="id">权限数值</param>
        public AuthorizationFilter(int id)
        {
            string description = "";
            string key = ConvertToEnumName(id,out description);
            var per = new PermissionsPoint(id.ToString(), key, description);

            CurrentPermissionsPoint = per;
            _permissionsProvider.SetCurrentPermissions(UserIdentityFactory.Instance.UserIdentity, per);
            _permissionsProvider = UserIdentityCollection.Instance;
        }
        /// <summary>
        /// 验证用户是否具有当前操作的权限
        /// </summary>
        /// <param name="userIdentityKey"></param>
        /// <param name="currentAccessPermissions"></param>
        /// <param name="userData"></param>
        /// <returns></returns>
        public bool UserHasPermission(string userIdentityKey,User.UserData userData, PermissionsPoint currentAccessPermissions)
        {
            IList<PermissionsPoint> pointList = _PermissionsProvider.GetUserHasPermissionsPoints(userIdentityKey, userData);
            if (pointList == null)
                return false;
            var l = pointList.ToList().ToList(m => m.PermissionsId);
            var s = l.ToString(",");
            var searchResult = pointList.Where(p =>
                (!string.IsNullOrEmpty(currentAccessPermissions.Key) && p.Key == currentAccessPermissions.Key)
                || (!string.IsNullOrEmpty(currentAccessPermissions.PermissionsId) && p.PermissionsId == currentAccessPermissions.PermissionsId));

            if (searchResult.Count() >0)
                return true;
            return false;
        }
 /// <summary>
 /// 验证用户是否具有当前操作的权限
 /// </summary>
 /// <param name="userIdentityKey">用户标识</param>
 /// <param name="currentAccessPermissions"></param>
 /// <param name="userData"></param>
 public void Authenticate(string userIdentityKey, User.UserData userData, PermissionsPoint currentAccessPermissions)
 {
     if (!UserHasPermission(userIdentityKey,userData, currentAccessPermissions))
         throw new AuthorizationException(Resources.Messages.NoPermission);
 }
Example #4
0
 /// <summary>
 /// 权限点移除
 /// </summary>
 /// <param name="point"></param>
 public void RemovePermissions(PermissionsPoint point)
 {
     HasPermissionsPoint.Remove(point);
 }
Example #5
0
 /// <summary>
 /// 权限添加
 /// </summary>
 /// <param name="point"></param>
 public void AddPermissions(PermissionsPoint point)
 {
     HasPermissionsPoint.Add(point);
 }
Example #6
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="currentPermissionsPoint">当前权限点实体</param>
 public AuthorizationFilter(PermissionsPoint currentPermissionsPoint)
 {
     CurrentPermissionsPoint = currentPermissionsPoint;
     _permissionsProvider.SetCurrentPermissions(UserIdentityFactory.Instance.UserIdentity, currentPermissionsPoint);
     _permissionsProvider = UserIdentityCollection.Instance;
 }
Example #7
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="currentPermissionsPoint">当前权限点实体</param>
 /// <param name="permissionsProvider">存储和获取权限的提供者</param>
 public AuthorizationFilter(PermissionsPoint currentPermissionsPoint, IProvidePermissions permissionsProvider)
 {
     CurrentPermissionsPoint = currentPermissionsPoint;
     _permissionsProvider = permissionsProvider;
 }