BExISMigration.SecurityMigration.GetBexisUsersInRole C# (CSharp) Method

GetBexisUsersInRole() private method

private GetBexisUsersInRole ( string dataBase, string roleName ) : List
dataBase string
roleName string
return List
        internal List<string> GetBexisUsersInRole(string dataBase, string roleName)
        {
            List<string> bexisUsersInRole = new List<string>();
            // DB query
            string mySelectQuery = "SELECT USERNAME FROM \"PROVIDER\".\"USERSINROLES\" where ROLENAME='" + roleName + "'";
            DB2Connection connect = new DB2Connection(dataBase);
            DB2Command myCommand = new DB2Command(mySelectQuery, connect);
            connect.Open();
            DB2DataReader myReader = myCommand.ExecuteReader();
            while (myReader.Read())
            {
                bexisUsersInRole.Add(myReader.GetValue(0).ToString());
            }
            myReader.Close();
            connect.Close();
            return bexisUsersInRole;
        }

Usage Example

Example #1
0
        public string TransferRoles()
        {
            SecurityMigration securityMigration = new SecurityMigration();
            List<string> roles = securityMigration.GetBexisRoles(DataBase);
            SubjectManager subjectManager = new SubjectManager();
            int newGroups = 0;
            foreach (string role in roles)
            {
                string roleName = role;
                if (role.IndexOf('_') == 0)
                    roleName = role.Substring(1, role.Length - 1);
                if (subjectManager.GetGroupByName(roleName) == null)
                {
                    newGroups++;
                    subjectManager.CreateGroup(roleName, roleName);
                    List<string> usersInRole = securityMigration.GetBexisUsersInRole(DataBase, roleName);
                    foreach (string userName in usersInRole)
                    {
                        if (subjectManager.GetUserByName(userName) != null)
                            subjectManager.AddUserToGroup(userName, roleName);
                    }

                }
            }
            return "Groups was successfully transfered and old bexis users added to them";
        }