Esempio n. 1
0
        public static void CreateTestData(ConfigurationContext context)
        {
            UserRoleManager urm = new UserRoleManager("EntLibSecurity", context);

            DeleteTestData(context);

            byte[] pwd = SHA1Managed.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes("Password"));
            byte [] emptyPasswd = SHA1Managed.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes(""));

            urm.CreateUser("testuser", pwd);
            urm.CreateUser("bogususer", pwd);
            urm.CreateUser("emptyUser", emptyPasswd);

            urm.CreateRole("Admins");
            urm.CreateRole("Managers");
            urm.CreateRole("Users");

            urm.CreateUserRole("testuser", "Users");
            urm.CreateUserRole("testuser", "Managers");
        }
Esempio n. 2
0
        public static void CreateTestData(ConfigurationContext context)
        {
            UserRoleManager urm = new UserRoleManager("EntLibSecurity", context);

            DeleteTestData(context);

            byte[]  pwd         = SHA1Managed.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes("Password"));
            byte [] emptyPasswd = SHA1Managed.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes(""));

            urm.CreateUser("testuser", pwd);
            urm.CreateUser("bogususer", pwd);
            urm.CreateUser("emptyUser", emptyPasswd);

            urm.CreateRole("Admins");
            urm.CreateRole("Managers");
            urm.CreateRole("Users");

            urm.CreateUserRole("testuser", "Users");
            urm.CreateUserRole("testuser", "Managers");
        }
Esempio n. 3
0
        /// <summary>
        ///  create a role
        /// </summary>
        /// <param name="roleName">role name</param>
        /// <param name="roleDescription">roleDescription's description</param>
        /// <param name="users">user ad's</param>
        public static void CreateRole(string roleName, string roleDescription, string users)
        {
            if (string.IsNullOrEmpty(users))
            {
                return;
            }

            SourceCode.Security.UserRoleManager.Management.UserRoleManager roleManager = new UserRoleManager();

            try
            {
                roleManager.CreateConnection();
                roleManager.Connection.Open(GetServerConnectionSetup());
                if (roleManager.GetRole(roleName) == null)
                {
                    SourceCode.Security.UserRoleManager.Management.Role role = new SourceCode.Security.UserRoleManager.Management.Role();

                    // Set Role Name, Description and Properties
                    role.Name        = roleName;
                    role.Description = roleDescription;
                    role.IsDynamic   = true;

                    ////Add users to Include in Role
                    ////role.Include.Add(new UserItem("K2:DENALLIX\\Anthony"));
                    string[] user = users.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string u in user)
                    {
                        string us = SecurityLabelName + ":" + u;
                        if (role.Include[us] == null)
                        {
                            role.Include.Add(new UserItem(us));
                        }
                    }

                    roleManager.CreateRole(role);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (roleManager != null)
                {
                    roleManager.Connection.Close();
                    roleManager.Connection.Dispose();
                    roleManager.DeleteConnection();
                    roleManager.Connection = null;
                    roleManager            = null;
                }
            }
        }
Esempio n. 4
0
        private void AddRole()
        {
            base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable       results   = base.ServiceBroker.ServicePackage.ResultTable;
            Role            role      = new Role();
            UserRoleManager urmServer = new UserRoleManager();

            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);

                role.Name        = base.GetStringProperty(Constants.SOProperties.Role.RoleName, true);
                role.Description = base.GetStringProperty(Constants.SOProperties.Role.RoleDescription);;
                role.IsDynamic   = base.GetBoolProperty(Constants.SOProperties.Role.RoleDynamic);

                // At least one roleItem has to be created with the new group
                string   roleItemName = base.GetStringProperty(Constants.SOProperties.Role.RoleItem, true);
                string   roleItemType = base.GetStringProperty(Constants.SOProperties.Role.RoleItemType, true);
                RoleItem ri;
                switch (roleItemType.ToUpper())
                {
                case "GROUP":
                    ri = new GroupItem(roleItemName);
                    break;

                case "USER":
                    ri = new UserItem(roleItemName);
                    break;

                default:
                    throw new ApplicationException(string.Format(Constants.ErrorMessages.RoleTypeNotSupported, roleItemType));
                    //break;
                }
                role.RoleItems.Add(ri);
                urmServer.CreateRole(role);
                urmServer.Connection.Close();
            }
        }
Esempio n. 5
0
        private void AddRole()
        {
            base.ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;
            Role role = new Role();
            UserRoleManager urmServer = new UserRoleManager();
            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(base.BaseAPIConnectionString);

                role.Name = base.GetStringProperty(Constants.SOProperties.Role.RoleName, true);
                role.Description = base.GetStringProperty(Constants.SOProperties.Role.RoleDescription);;
                role.IsDynamic = base.GetBoolProperty(Constants.SOProperties.Role.RoleDynamic);

                // At least one roleItem has to be created with the new group
                string roleItemName = base.GetStringProperty(Constants.SOProperties.Role.RoleItem, true);
                string roleItemType = base.GetStringProperty(Constants.SOProperties.Role.RoleItemType, true);
                switch (roleItemType.ToUpper())
                {
                    case "GROUP":
                        GroupItem gi = new GroupItem(roleItemName);
                        role.Include.Add(gi);
                        break;
                    case "USER":
                        UserItem ui = new UserItem(roleItemName);
                        role.Include.Add(ui);
                        break;
                    default:
                        throw new ApplicationException(string.Format(Constants.ErrorMessages.RoleTypeNotSupported, roleItemType));
                    //break;
                }
                urmServer.CreateRole(role);
                urmServer.Connection.Close();
            }
        }
        public void CreateAndDeleteRole()
        {
            manager.CreateRole(roleName);

            DataSet ds = SelectRole(roleName);

            Assert.AreEqual(1, ds.Tables[0].Rows.Count);
            Assert.AreEqual(roleName, ds.Tables[0].Rows[0]["RoleName"]);

            // delete the row
            manager.DeleteRole(roleName);
            ds = SelectIdentity();
            Assert.AreEqual(0, ds.Tables[0].Rows.Count);
        }
Esempio n. 7
0
 private void CreateRoleDelegate(params object[] methodParams)
 {
     manager.CreateRole((string)methodParams[0]);
 }
        private void AddRole()
        {
            ServiceObject serviceObject = this.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();

            Role role = new Role();
            UserRoleManager urmServer = new UserRoleManager();

            using (urmServer.CreateConnection())
            {
                urmServer.Connection.Open(WFMServerConnectionString);

                string roleName = serviceObject.Properties[Constants.Properties.RoleName].Value as string;
                string roleDescription = serviceObject.Properties[Constants.Properties.RoleDescription].Value as string;
                bool roleIsDynamic = Convert.ToBoolean(serviceObject.Properties[Constants.Properties.RoleDynamic].Value as string);

                role.Name = roleName;
                role.Description = roleDescription;
                role.IsDynamic = roleIsDynamic;

                // At least one roleItem has to be created with the new group
                string roleItemName = serviceObject.Properties[Constants.Properties.RoleItem].Value as string;
                string roleItemType = serviceObject.Properties[Constants.Properties.RoleItemType].Value as string;

                switch (roleItemType)
                {
                    case Constants.RoleItemType.Group:
                        GroupItem gi = new GroupItem(roleItemName);
                        role.Include.Add(gi);
                        break;
                    case Constants.RoleItemType.User:
                        UserItem ui = new UserItem(roleItemName);
                        role.Include.Add(ui);
                        break;
                    default:
                        throw new ApplicationException(string.Format(Constants.ErrorText.RoleTypeNotSupported, roleItemType));
                    //break;
                }

                urmServer.CreateRole(role);
                urmServer.Connection.Close();
            }
        }