/// <summary>
        /// Create the default objects to complete initializing the manager storage.
        /// </summary>
        /// <param name="managerStorage"></param>
        protected void CreateDefaultObjects(IManagerStorage managerStorage)
        {
            // create default groups
            ArrayList defaultGroups = new ArrayList();
            GroupStorageView newGroup;

            newGroup = new GroupStorageView(c_AdminsGroupId, "Administrators");
            newGroup.Description = "Administrators Group";
            newGroup.IsSystem = true;
            defaultGroups.Add(newGroup);

            newGroup = new GroupStorageView(c_ExecutorsGroupId, "Executors");
            newGroup.Description = "Executors Group";
            newGroup.IsSystem = true;
            defaultGroups.Add(newGroup);

            newGroup = new GroupStorageView(c_UsersGroupId, "Users");
            newGroup.Description = "Users Group";
            newGroup.IsSystem = true;
            defaultGroups.Add(newGroup);

            managerStorage.AddGroups((GroupStorageView[])defaultGroups.ToArray(typeof(GroupStorageView)));

            // set default permissions

            //permissions for admins group
            managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ExecuteThread);
            managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageOwnApp);
            managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageAllApps);
            managerStorage.AddGroupPermission(c_AdminsGroupId, Permission.ManageUsers);

            //permissions for executors group
            managerStorage.AddGroupPermission(c_ExecutorsGroupId, Permission.ExecuteThread);

            //permissions for users group
            managerStorage.AddGroupPermission(c_UsersGroupId, Permission.ManageOwnApp);

            // create default users
            ArrayList defaultUsers = new ArrayList();
            UserStorageView newUser;

            newUser = new UserStorageView("admin", "admin", c_AdminsGroupId);
            newUser.IsSystem = true;
            defaultUsers.Add(newUser);

            newUser = new UserStorageView("executor", "executor", c_ExecutorsGroupId);
            newUser.IsSystem = true;
            defaultUsers.Add(newUser);

            newUser = new UserStorageView("user", "user", c_UsersGroupId);
            newUser.IsSystem = true;
            defaultUsers.Add(newUser);

            managerStorage.AddUsers((UserStorageView[])defaultUsers.ToArray(typeof(UserStorageView)));
        }
        public void SetData(GroupStorageView group)
        {
            this._Group = group;
            this.Text = _Group.GroupName + " Properties";
            this.lbName.Text = _Group.GroupName;

            GetMemberData();
            GetPermissionData();

            if (group.IsSystem)
            {
                btnAdd.Enabled = false;
                btnRemove.Enabled = false;

                btnAddPrm.Enabled = false;
                btnRemovePrm.Enabled = false;
            }
        }
 public void AddGroups(GroupStorageView[] groups)
 {
     if (groups == null)
         return;
     IObjectContainer container = GetStorage();
     try
     {
         foreach (GroupStorageView group in groups)
             container.Set(group);
     }
     finally
     {
         container.Close();
     }
 }
        public GroupStorageView[] GetGroups()
        {
            ArrayList groupList = new ArrayList();

            using(IDataReader dataReader = RunSqlReturnDataReader("select grp_id, grp_name, is_system from grp"))
            {
                while(dataReader.Read())
                {
                    int groupId = dataReader.GetInt32(dataReader.GetOrdinal("grp_id"));
                    string groupName = dataReader.GetString(dataReader.GetOrdinal("grp_name"));
                    bool isSystem = false;
                    if (!dataReader.IsDBNull(dataReader.GetOrdinal("is_system")))
                    {
                        isSystem = dataReader.GetBoolean(dataReader.GetOrdinal("is_system"));
                    }
                    GroupStorageView group = new GroupStorageView(groupId, groupName);
                    group.IsSystem = isSystem;

                    groupList.Add(group);
                }

                dataReader.Close();
            }

            return (GroupStorageView[])groupList.ToArray(typeof(GroupStorageView));
        }
        public GroupStorageView GetGroup(int groupId)
        {
            using(IDataReader dataReader = RunSqlReturnDataReader(String.Format("select grp_id, grp_name, is_system from grp where grp_id={0}", groupId)))
            {
                if(dataReader.Read())
                {
                    string groupName = dataReader.GetString(dataReader.GetOrdinal("grp_name"));
                    bool isSystem = false;
                    if (!dataReader.IsDBNull(dataReader.GetOrdinal("is_system")))
                    {
                        isSystem = dataReader.GetBoolean(dataReader.GetOrdinal("is_system"));
                    }

                    GroupStorageView group = new GroupStorageView(groupId, groupName);
                    group.IsSystem = isSystem;

                    dataReader.Close();
                    return group;
                }
                else
                {
                    dataReader.Close();
                    return null;
                }

            }
        }
        public void DeleteGroup(GroupStorageView groupToDelete)
        {
            if (groupToDelete == null)
            {
                return;
            }

            string sqlQuery;

            sqlQuery = String.Format("DELETE FROM usr WHERE grp_id='{0}'; DELETE FROM grp WHERE grp_id='{0}';",
                groupToDelete.GroupId);

            logger.Debug(String.Format("Deleting group {0} and all users associated with it.", groupToDelete.GroupId));

            RunSql(sqlQuery);
        }
        public void AddGroups(GroupStorageView[] groups)
        {
            if (groups == null)
            {
                return;
            }

            foreach (GroupStorageView group in groups)
            {
                string sqlQuery;

                sqlQuery = String.Format("insert into grp(grp_id, grp_name, is_system) values({0}, '{1}', {2})",
                    group.GroupId,
                    Utils.MakeSqlSafe(group.GroupName),
                    Utils.BoolToSqlBit(group.IsSystem)
                    );

                RunSql(sqlQuery);
            }
        }
Exemple #8
0
        private void SetData(GroupStorageView[] allGroups)
        {
            this.allGroups = allGroups;
            cboGroup.Items.Clear();
            foreach(GroupStorageView group in allGroups)
            {
                cboGroup.Items.Add(group.GroupName);

            }
        }
        public void DeleteGroup(GroupStorageView groupToDelete)
        {
            if( groupToDelete == null )
            {
                return;
            }

            ArrayList remainingGroups = new ArrayList();
            ArrayList remainingUsers = new ArrayList();

            foreach (UserStorageView user in _users)
            {
                if (user.GroupId != groupToDelete.GroupId)
                {
                    remainingUsers.Add(user);
                }
            }

            foreach (GroupStorageView group in _groups)
            {
                if (group.GroupId != groupToDelete.GroupId)
                {
                    remainingGroups.Add(group);
                }
            }

            _groups = remainingGroups;
            _users = remainingUsers;
        }
 public void AddGroups(GroupStorageView[] groups)
 {
     if (groups == null)
         return;
     _groups.AddRange(groups);
 }
Exemple #11
0
        /// <summary>
        /// Delete group and all associated users.
        /// </summary>
        /// <param name="sc"></param>
        /// <param name="groupToDelete"></param>
        public void Admon_DeleteGroup(SecurityCredentials sc, GroupStorageView groupToDelete)
        {
            AuthenticateUser(sc);
            EnsurePermission(sc, Permission.ManageUsers);

            logger.Debug(String.Format("Deleting group.", groupToDelete.GroupId));

            ManagerStorageFactory.ManagerStorage().DeleteGroup(groupToDelete);
        }
Exemple #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sc"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public PermissionStorageView[] Admon_GetGroupPermissions(SecurityCredentials sc, GroupStorageView group)
        {
            AuthenticateUser(sc);
            EnsurePermission(sc, Permission.ManageUsers);

            logger.Debug(String.Format("Getting group permission for group ", group.GroupId));

            return ManagerStorageFactory.ManagerStorage().GetGroupPermissionStorageView(group.GroupId);
        }
Exemple #13
0
        private void SetupApplicationsGroupsAndUsers(Permission permission)
        {
            // add permissions
            int groupId = 12;

            GroupStorageView[] groups = new GroupStorageView[1];

            groups[0] = new GroupStorageView(groupId, "test1");

            UserStorageView[] users = new UserStorageView[1];

            users[0] = new UserStorageView("username1", "password1", groupId);

            _managerStorage.AddGroups(groups);

            _managerStorage.AddUsers(users);

            _managerStorage.AddGroupPermission(groupId, permission);

            SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5));

            // add applications, only one assigned to this user

            _managerStorage.AddApplication(new ApplicationStorageView("username1"));
            _managerStorage.AddApplication(new ApplicationStorageView("username2"));
            _managerStorage.AddApplication(new ApplicationStorageView("username3"));
        }
Exemple #14
0
        public void EnsurePermissionTestSimpleScenario()
        {
            int groupId = 12;

            GroupStorageView[] groups = new GroupStorageView[1];

            groups[0] = new GroupStorageView(groupId, "test1");

            UserStorageView[] users = new UserStorageView[1];

            users[0] = new UserStorageView("username1", "password1", groupId);

            _managerStorage.AddGroups(groups);

            _managerStorage.AddUsers(users);

            _managerStorage.AddGroupPermission(groupId, Permission.ExecuteThread);

            SecurityCredentials sc = new SecurityCredentials("username1", HashUtil.GetHash("password1", HashType.MD5));

            EnsurePermission(sc, Permission.ExecuteThread);

            // the above throws an exception if something is wrong so we are doing OK if we get this far
            Assert.IsTrue(true);
        }
        private void AddGroup(int groupId, string groupName)
        {
            GroupStorageView[] groups = new GroupStorageView[1];

            groups[0] = new GroupStorageView(groupId, groupName);

            ManagerStorage.AddGroups(groups);
        }
        public void DeleteGroup(GroupStorageView groupToDelete)
        {
            if (groupToDelete == null)
            {
                return;
            }

            IObjectContainer container = GetStorage();
            try
            {
                IList<UserStorageView> users =
                    container.Query<UserStorageView>(delegate(UserStorageView userFinder)
                {
                    return userFinder.GroupId == groupToDelete.GroupId;
                });
                foreach (UserStorageView user in users)
                    container.Delete(user);

                IList<GroupStorageView> groups =
                    container.Query<GroupStorageView>(delegate(GroupStorageView groupFinder)
                {
                    return groupFinder.GroupId == groupToDelete.GroupId;
                });

                if (groups.Count > 0)
                    container.Delete(groups[0]);
            }
            finally
            {
                container.Close();
            }
        }
        public GroupStorageView[] GetGroups()
        {
            GroupStorageView[] allGroups;
            IObjectContainer container = GetStorage();
            try
            {
                IList<GroupStorageView> groups =
                    container.Query<GroupStorageView>(delegate(GroupStorageView groupFinder)
                {
                    return true;
                });

                if (groups.Count > 0)
                {
                    allGroups = new GroupStorageView[groups.Count];
                    groups.CopyTo(allGroups, 0);
                }
                else
                    allGroups = new GroupStorageView[0];
            }
            finally
            {
                container.Close();
            }
            return allGroups;
        }
        public void AddGroups(GroupStorageView[] groups)
        {
            if (groups == null)
            {
                return;
            }

            if (m_groups == null)
            {
                m_groups = new ArrayList();
            }

            m_groups.AddRange(groups);
        }