public bool AddUsersToGroups(UserBase[] users, int[] groupIds)
        {
            if (ArrayIsNullOrEmpty(users) || ArrayIsNullOrEmpty(groupIds))
            {
                throw new ArgumentNullException("users,groupIds", "Users or UserGroups can not be null or empty!");
            }
            bool flag = false;
            _session.BeginTransaction();
            try
            {
                foreach (int gid in groupIds)
                {
                    UserGroup grp = UserGroup.Retrieve(_session, gid);

                    flag = AddUsersToGroup(users, grp);
                    _session.Commit();

                }
            }
            catch
            {
                _session.Rollback();
                throw;
            }
            return flag;
        }
Ejemplo n.º 2
0
 public IList<IUserGroup> GetUserGroupsForUser(UserBase user)
 {
     using (Session session = new Session())
     {
         AuthorizationRepository repository = new AuthorizationRepository(session);
         return repository.GetGroupsForUser(user);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 新增用户到用户组
        /// </summary>
        /// <param name="user"></param>
        /// <param name="session"></param>
        /// <returns></returns>
        public bool AddUser(UserBase user, ISession session)
        {
            if (!this.UserIsInGroup(user, session))
            {
                UserToGroup utg = new UserToGroup();
                utg.CreateTime = DateTime.Now;
                utg.GroupId = this.GroupId;
                utg.OperateBy = SecuritySession.CurrentUser.UserId;
                utg.UserId = user.UserId;

                return utg.Create(session);
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 获取可以分配给用户的用户组
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public IList<UserGroup> GetAssigningGroupsForUser(UserBase user)
        {
            IList<UserGroup> grps = new List<UserGroup>();
            //string sql = @"select * from sys_usergroup g where g.group_id not in (select group_id from sys_user_to_group where user_id=@USER_ID)";
            string oql = "select g.* from UserGroup g where g.GroupId not in(select GroupId from UserToGroup where UserId=@UserId)";

            return _session
                .CreateObjectQuery(oql)
                .Attach(typeof(UserGroup))
                .Attach(typeof(UserToGroup))
                .SetValue("@UserId", user.UserId, DbTypeInfo.Int32())
                .List<UserGroup>();
        }
Ejemplo n.º 5
0
 /// <summary>
 ///  是否允许操作
 /// </summary>
 /// <param name="user"></param>
 /// <param name="operation"></param>
 /// <returns></returns>
 public static bool IsAllowed(UserBase user, string operation)
 {
     return(_azService.IsAllowed(user, operation));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 用户是否有操作某个指定对象的权限
 /// </summary>
 /// <param name="user"></param>
 /// <param name="operation"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static bool IsAllowed(UserBase user, string operation, IEntitySecurityKey key)
 {
     return _azService.IsAllowed(user, operation, key);
 }
        private bool AddUsersToGroup(UserBase[] users, UserGroup grp)
        {
            bool flag = false;

            if (grp != null)
            {
                foreach (UserBase user in users)
                {
                    if (!grp.UserIsInGroup(user, this._session))
                    {
                        if (user != null)
                        {
                            flag = grp.AddUser(user, this._session);
                        }
                    }
                }
            }
            return flag;
        }
 public void RemoveUser(UserBase user)
 {
     //如果User是IEntity,则调用其本身的Delete方法,否则使用EntityManager删除它。
     if (user is IEntity)
     {
         IEntity userEntity = (IEntity)user;
         userEntity.Delete(this._session);
     }
     else
     {
         EntityManager.Delete(this._session, user.GetType(), user.UserId);
     }
 }
        void IAuthorizationRepository.RemoveUsersFromGroups(UserBase[] users, IUserGroup[] userGroups)
        {
            if (ArrayIsNullOrEmpty(users) || ArrayIsNullOrEmpty(userGroups))
            {
                throw new ArgumentNullException("users,groups", "Users or UserGroups can not be null or empty!");
            }

            foreach (IUserGroup grp in userGroups)
            {
                if (!grp.RemoveUserFromGroup(users, this._session))
                {
                    throw new ApplicationException(string.Format("从用户组{0}中移出用户失败!", grp.Name));
                }
            }
        }
Ejemplo n.º 10
0
 public void AddPermissionsToQuery(UserBase urser, string operation, Magic.Framework.ORM.IEntityQuery criteria)
 {
     
 }
        /// <summary>
        /// 验证用户,并返回合法用户的
        /// </summary>
        /// <param name="session"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="validUser"></param>
        /// <returns>true:通过,false:不通过</returns>
        private bool ValidateUser(string userName, string password, out UserBase validUser)
        {
            validUser = null;

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("UserName and Password can not be NULL!");
            }
            using (ISession session = new Session())
            {
                IList<Magic.Sys.User> list = session.CreateEntityQuery<Magic.Sys.User>()
                .And(Exp.Eq("UserName", userName))
               // .And(Exp.Eq("Password", Magic.Security.Utility.Encryption.MD5(password, 32)))
               .And(Exp.Eq("Password",password))
                .List<User>();

                if (list == null || list.Count == 0)
                {
                    return false;
                }

                validUser = list[0];
                return true;
            }
        }
 private void SetCurrentUser(UserBase user)
 {
     if (CheckHttpContext())
     {
         HttpContext.Current.Session[USER_SESSION_ID] = user;
     }
 }
Ejemplo n.º 13
0
 public bool UserIsInGroup(UserBase user,ISession session)
 {
     string oql = @"select 1 from UserToGroup";
     return
      session.CreateObjectQuery(oql)
      .Attach(typeof(UserToGroup))
      .And(Exp.Eq("UserId", user.UserId))
      .And(Exp.Eq("GroupId", this.GroupId))
      .Count() > 0;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 用户是否有操作某个指定对象的权限
 /// </summary>
 /// <param name="user"></param>
 /// <param name="operation"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static bool IsAllowed(UserBase user, string operation, IEntitySecurityKey key)
 {
     return(_azService.IsAllowed(user, operation, key));
 }
        /// <summary>
        /// 获取指定用户所在的用户组
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public IList<IUserGroup> GetGroupsForUser(UserBase user)
        {
            string oql = @"select g.* from UserGroup g inner join UserToGroup ug on g.GroupId=ug.GroupId
                                where UserId=@UserId";

            IList<IUserGroup> grps = new List<IUserGroup>();
            ObjectQuery query = _session.CreateObjectQuery(oql).Attach(typeof(UserGroup)).Attach(typeof(UserToGroup));
            query.SetValue("@UserId", user.UserId, DbTypeInfo.Int32());
            IList<UserGroup> userGroups = query.List<UserGroup>();
            foreach (UserGroup ug in userGroups)
                grps.Add(ug);
            return grps;
        }
 bool IAuthorizationRepository.AddUsersToGroups(UserBase[] users, IUserGroup[] userGroups)
 {
     if (ArrayIsNullOrEmpty(users) || ArrayIsNullOrEmpty(userGroups))
     {
         throw new ArgumentNullException("users,groups", "Users or UserGroups can not be null or empty!");
     }
     bool flag = false;
     foreach (UserGroup grp in userGroups)
     {
         flag = this.AddUsersToGroup(users, grp);
     }
     return flag;
 }
Ejemplo n.º 17
0
 public bool IsAllowed(UserBase user, string operation)
 {
     return true;
 }
        /// <summary>
        /// 判断用户是否在用户组
        /// </summary>
        /// <param name="user"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public bool IsUserInGroup(UserBase user, IUserGroup group)
        {
            if (group == null)
                throw new ArgumentNullException("group");
            if (user == null)
                throw new ArgumentNullException("user");

            return IsUserInGroup(user.UserId, ((UserGroup)group).GroupId);
        }
Ejemplo n.º 19
0
 public bool IsAllowed(UserBase user, string operation, IEntitySecurityKey key)
 {
     return true;
 }
 public void RemoveUsersFromGroups(UserBase[] users, int[] groupIds)
 {
     if (ArrayIsNullOrEmpty(users) || ArrayIsNullOrEmpty(groupIds))
     {
         throw new ArgumentNullException("users,groupIds", "Users or UserGroups can not be null or empty!");
     }
     this._session.BeginTransaction();
     try
     {
         foreach (int gid in groupIds)
         {
             UserGroup group = UserGroup.Retrieve(_session, gid);
             if (!group.RemoveUserFromGroup(users, this._session))
             {
                 throw new ApplicationException(string.Format("从用户组{0}中移出用户失败!", group.Name));
             }
         }
         _session.Commit();
     }
     catch
     {
         this._session.Rollback();
         throw;
     }
 }
Ejemplo n.º 21
0
 public AuthorizationInformation GetAuthorizationInformation(UserBase urser, string operation)
 {
     return new AuthorizationInformation();
 }     
Ejemplo n.º 22
0
 /// <summary>
 ///  是否允许操作
 /// </summary>
 /// <param name="user"></param>
 /// <param name="operation"></param>
 /// <returns></returns>
 public static bool IsAllowed(UserBase user, string operation)
 {
     return _azService.IsAllowed(user, operation);
 }
 /// <summary>
 /// 获取当前用户在指定用户组上的所有祖先用户组
 /// </summary>
 /// <param name="user"></param>
 /// <param name="group"></param>
 /// <returns></returns>
 public IList<IUserGroup> GetAncestryAssociation(UserBase user, IUserGroup group)
 {
     return null;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// 向查询添加权限控制
 /// </summary>
 /// <param name="urser"></param>
 /// <param name="operation"></param>
 /// <param name="criteria"></param>
 public static void AddPermissionsToQuery(UserBase urser, string operation, Magic.Framework.ORM.IEntityQuery criteria)
 {
     _azService.AddPermissionsToQuery(urser, operation, criteria);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// 向查询添加权限控制
 /// </summary>
 /// <param name="urser"></param>
 /// <param name="operation"></param>
 /// <param name="criteria"></param>
 public static void AddPermissionsToQuery(UserBase urser, string operation, Magic.Framework.ORM.IEntityQuery criteria)
 {
     _azService.AddPermissionsToQuery(urser, operation, criteria);
 }