示例#1
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"));
        }
示例#2
0
        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);
        }
示例#3
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);
        }
        public void DeleteGroup(GroupStorageView groupToDelete)
        {
            if (m_groups == null || groupToDelete == null)
            {
                return;
            }

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

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

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

            m_groups = remainingGroups;
            m_users  = remainingUsers;
        }
示例#5
0
        private void GetGroupMembershipData()
        {
            try
            {
                lvGrp.Items.Clear();
                //get the group this user belongs to.
                GroupStorageView groupStorageView = console.Manager.Admon_GetGroup(console.Credentials, _User.GroupId);

                if (groupStorageView != null)
                {
                    GroupItem grpItem = new GroupItem(groupStorageView.GroupName);
                    grpItem.GroupView  = groupStorageView;
                    grpItem.ImageIndex = 2;
                    lvGrp.Items.Add(grpItem);
                }
            }
            catch (Exception ex)
            {
                if (ex is AuthorizationException)
                {
                    MessageBox.Show("Access denied. You do not have adequate permissions for this operation.", "Authorization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Could not get user-group membership details. Error: " + ex.Message, "Console Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#6
0
        /// <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)));
        }
示例#7
0
        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;
            }
        }
示例#8
0
        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();
            }
        }
示例#9
0
        public GroupStorageView GetGroup(int groupId)
        {
            GroupStorageView group     = null;
            IObjectContainer container = GetStorage();

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

                if (groups.Count > 0)
                {
                    group = groups[0];
                }
            }
            finally
            {
                container.Close();
            }
            return(group);
        }
示例#10
0
        /// THIS FUNCTIONALITY IS NOT FULLY IMPLEMENTED AND IT MIGHT BE DISCARDED ALTOGETHER
        ///
        /// Loading from an XML file is the perfect tool for complex storage setups which would be useful for more in-depth unit testing
        /// Saving to an XML file could be used to dump the current storage state for troubleshooting, for example to receive faulty storages from the field.


        /// <summary>
        /// Save the current storage state into an XML file.
        /// It is important that the file format is easily editable by humans so test cases can easily be maintained.
        /// For this reason we do not use the build-in persistence modules.
        /// </summary>
        /// <param name="filename"></param>
        public void SaveToHumanReadableXmlFile(String filename)
        {
            const String storageDocumentTemplate = "<storage><users/><groups/><group_permissions/><executors/><applications/><threads/></storage>";
            XmlDocument  storageDocument         = new XmlDocument();

            storageDocument.LoadXml(storageDocumentTemplate);

            XmlNode usersNode  = storageDocument.SelectSingleNode("/storage/users");
            XmlNode groupsNode = storageDocument.SelectSingleNode("/storage/groups");
            //XmlNode groupPermissionsNode = storageDocument.SelectSingleNode("/storage/group_permissions");
            XmlNode executorsNode    = storageDocument.SelectSingleNode("/storage/executors");
            XmlNode applicationsNode = storageDocument.SelectSingleNode("/storage/applications");
            XmlNode threadsNode      = storageDocument.SelectSingleNode("/storage/threads");

            if (m_users != null)
            {
                IEnumerator usersEnumerator = m_users.GetEnumerator();

                while (usersEnumerator.MoveNext())
                {
                    UserStorageView user = usersEnumerator.Current as UserStorageView;

                    XmlElement userElement = storageDocument.CreateElement("user");

                    userElement.SetAttribute("username", user.Username);
                    userElement.SetAttribute("password", user.Password);
                    userElement.SetAttribute("groupid", user.GroupId.ToString());

                    usersNode.AppendChild(userElement);
                }
            }

            if (m_groups != null)
            {
                IEnumerator groupsEnumerator = m_groups.GetEnumerator();

                while (groupsEnumerator.MoveNext())
                {
                    GroupStorageView group = groupsEnumerator.Current as GroupStorageView;

                    XmlElement groupElement = storageDocument.CreateElement("group");

                    groupElement.SetAttribute("groupname", group.GroupName);
                    groupElement.SetAttribute("groupid", group.GroupId.ToString());

                    groupsNode.AppendChild(groupElement);
                }
            }

            //		private Hashtable m_groupPermissions;
//			if (m_groupPermissions != null)
//			{
//				IEnumerator groupPermissionsEnumerator = m_groupPermissions.GetEnumerator();
//
//				while(groupPermissionsEnumerator.MoveNext())
//				{
//					GroupPermissionStorageView group = groupPermissionsEnumerator.Current as GroupStorageView;
//
//					XmlElement groupElement = storageDocument.CreateElement("group");
//
//					groupElement.SetAttribute("groupname", group.GroupName);
//					groupElement.SetAttribute("groupid", group.GroupId.ToString());
//
//					groupsNode.AppendChild(groupElement);
//				}
//			}


            if (m_executors != null)
            {
                IEnumerator executorsEnumerator = m_executors.GetEnumerator();

                while (executorsEnumerator.MoveNext())
                {
                    ExecutorStorageView executor = executorsEnumerator.Current as ExecutorStorageView;

                    XmlElement executorElement = storageDocument.CreateElement("executor");

                    executorElement.SetAttribute("executorid", executor.ExecutorId);
                    executorElement.SetAttribute("dedicated", executor.Dedicated.ToString());
                    executorElement.SetAttribute("connected", executor.Connected.ToString());
                    executorElement.SetAttribute("pingtime", executor.PingTime.ToString());
                    executorElement.SetAttribute("hostname", executor.HostName);
                    executorElement.SetAttribute("port", executor.Port.ToString());
                    executorElement.SetAttribute("username", executor.Username);
                    executorElement.SetAttribute("maxcpu", executor.MaxCpu.ToString());
                    executorElement.SetAttribute("cpuusage", executor.CpuUsage.ToString());
                    executorElement.SetAttribute("availablecpu", executor.AvailableCpu.ToString());
                    executorElement.SetAttribute("totalcpuusage", executor.TotalCpuUsage.ToString());
                    executorElement.SetAttribute("maxmemory", executor.MaxMemory.ToString());
                    executorElement.SetAttribute("maxdisk", executor.MaxDisk.ToString());
                    executorElement.SetAttribute("numberofcpu", executor.NumberOfCpu.ToString());
                    executorElement.SetAttribute("os", executor.Os);
                    executorElement.SetAttribute("architecture", executor.Architecture);

                    executorsNode.AppendChild(executorElement);
                }
            }

            if (m_applications != null)
            {
                IEnumerator applicationsEnumerator = m_applications.GetEnumerator();

                while (applicationsEnumerator.MoveNext())
                {
                    ApplicationStorageView application = applicationsEnumerator.Current as ApplicationStorageView;

                    XmlElement applicationElement = storageDocument.CreateElement("application");

                    applicationElement.SetAttribute("applicationid", application.ApplicationId);
                    applicationElement.SetAttribute("state", application.State.ToString());
                    applicationElement.SetAttribute("timecreated", application.TimeCreated.ToString());
                    applicationElement.SetAttribute("primary", application.Primary.ToString());
                    applicationElement.SetAttribute("username", application.Username.ToString());
                    applicationElement.SetAttribute("totalthreads", application.TotalThreads.ToString());
                    applicationElement.SetAttribute("unfinishedthreads", application.UnfinishedThreads.ToString());

                    applicationsNode.AppendChild(applicationElement);
                }
            }

            if (m_threads != null)
            {
                IEnumerator threadsEnumerator = m_threads.GetEnumerator();

                while (threadsEnumerator.MoveNext())
                {
                    ThreadStorageView thread = threadsEnumerator.Current as ThreadStorageView;

                    XmlElement threadElement = storageDocument.CreateElement("thread");

                    threadElement.SetAttribute("internalthreadid", thread.InternalThreadId.ToString());
                    threadElement.SetAttribute("applicationid", thread.ApplicationId);
                    threadElement.SetAttribute("executorid", thread.ExecutorId);
                    threadElement.SetAttribute("threadid", thread.ThreadId.ToString());
                    threadElement.SetAttribute("state", thread.State.ToString());
                    threadElement.SetAttribute("timestarted", thread.TimeStarted.ToString());
                    threadElement.SetAttribute("timefinished", thread.TimeFinished.ToString());
                    threadElement.SetAttribute("priority", thread.Priority.ToString());
                    threadElement.SetAttribute("failed", thread.Failed.ToString());

                    threadsNode.AppendChild(threadElement);
                }
            }

            storageDocument.Save(filename);
        }