Manages storage of role membership information for an ASP.NET application in a MySQL database.
Inheritance: System.Web.Security.RoleProvider
        private static MySqlSimpleRoleProvider CreateSimpleRoleProvider(string name, MySQLRoleProvider currentDefault)
        {
            MySqlSimpleRoleProvider simpleProvider = new MySqlSimpleRoleProvider(currentDefault);
            NameValueCollection     config         = new NameValueCollection();

            simpleProvider.Initialize(name, config);
            return(simpleProvider);
        }
        public void AddNonExistingUserToRole()
        {
            roleProvider = new MySQLRoleProvider();
              NameValueCollection config = new NameValueCollection();
              config.Add("connectionStringName", "LocalMySqlServer");
              config.Add("applicationName", "/");
              roleProvider.Initialize(null, config);

              roleProvider.CreateRole("Administrator");
              roleProvider.AddUsersToRoles(new string[] { "eve" },
            new string[] { "Administrator" });
              Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
        }
 public void AttemptLatestSchemaVersion()
 {
     // UTF32 is only supported
       if (Version.Minor >= 5)
       {
     execSQL(string.Format("alter database `{0}` character set = 'utf32' collate = 'utf32_general_ci'", database0));
     for (int i = 1; i <= 4; i++)
     {
       LoadSchema(i);
     }
     MySQLRoleProvider roleProvider = new MySQLRoleProvider();
     NameValueCollection config = new NameValueCollection();
     config.Add("connectionStringName", "LocalMySqlServer");
     config.Add("applicationName", "/");
     config.Add("autogenerateschema", "true");
     roleProvider.Initialize(null, config);
       }
 }
Example #4
0
        public void CreateAndDeleteRoles()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

            // Add the role
            roleProvider.CreateRole("Administrator");
            string[] roles = roleProvider.GetAllRoles();
            Assert.AreEqual(1, roles.Length);
            Assert.AreEqual("Administrator", roles[0]);

            // now delete the role
            roleProvider.DeleteRole("Administrator", false);
            roles = roleProvider.GetAllRoles();
            Assert.AreEqual(0, roles.Length);
        }
Example #5
0
        public void IllegalRoleAndUserNames()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

            AttemptToAddUserToRole("test", null);
            AttemptToAddUserToRole("test", "");
            roleProvider.CreateRole("Administrator");
            AttemptToAddUserToRole(null, "Administrator");
            AttemptToAddUserToRole("", "Administrator");
        }
        public void TestUserRemoveFindFromRole()
        {
            roleProvider = new MySQLRoleProvider();
              NameValueCollection config = new NameValueCollection();
              config.Add("connectionStringName", "LocalMySqlServer");
              config.Add("applicationName", "/");
              roleProvider.Initialize(null, config);

              AddUser("eve", "eveeve!");
              roleProvider.CreateRole("Administrator");
              roleProvider.AddUsersToRoles(new string[] { "eve" },
            new string[] { "Administrator" });
              Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
              string[] users = roleProvider.FindUsersInRole("Administrator", "eve");
              Assert.AreEqual( 1, users.Length );
              Assert.AreEqual("eve", users[0]);
              roleProvider.RemoveUsersFromRoles(new string[] { "eve" }, new string[] { "Administrator" } );
              Assert.IsFalse(roleProvider.IsUserInRole("eve", "Administrator"));
        }
        public void IsUserInRoleCrossDomain()
        {
            MySQLMembershipProvider provider = new MySQLMembershipProvider();
              NameValueCollection config1 = new NameValueCollection();
              config1.Add("connectionStringName", "LocalMySqlServer");
              config1.Add("applicationName", "/");
              config1.Add("passwordStrengthRegularExpression", "bar.*");
              config1.Add("passwordFormat", "Clear");
              provider.Initialize(null, config1);
              MembershipCreateStatus status;
              provider.CreateUser("foo", "bar!bar", null, null, null, true, null, out status);

              MySQLMembershipProvider provider2 = new MySQLMembershipProvider();
              NameValueCollection config2 = new NameValueCollection();
              config2.Add("connectionStringName", "LocalMySqlServer");
              config2.Add("applicationName", "/myapp");
              config2.Add("passwordStrengthRegularExpression", ".*");
              config2.Add("passwordFormat", "Clear");
              provider2.Initialize(null, config2);

              roleProvider = new MySQLRoleProvider();
              NameValueCollection config = new NameValueCollection();
              config.Add("connectionStringName", "LocalMySqlServer");
              config.Add("applicationName", "/");
              roleProvider.Initialize(null, config);

              MySQLRoleProvider r2 = new MySQLRoleProvider();
              NameValueCollection configr2 = new NameValueCollection();
              configr2.Add("connectionStringName", "LocalMySqlServer");
              configr2.Add("applicationName", "/myapp");
              r2.Initialize(null, configr2);

              roleProvider.CreateRole("Administrator");
              roleProvider.AddUsersToRoles(new string[] { "foo" },
            new string[] { "Administrator" });
              Assert.IsFalse(r2.IsUserInRole("foo", "Administrator"));
        }