Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAssignAdminRoleAfterBadSetting() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAssignAdminRoleAfterBadSetting()
        {
            UserRepository userRepository        = new InMemoryUserRepository();
            UserRepository initialUserRepository = new InMemoryUserRepository();
            UserRepository adminUserRepository   = new InMemoryUserRepository();
            RoleRepository roleRepository        = new InMemoryRoleRepository();

            userRepository.Create(NewUser("morpheus", "123", false));
            userRepository.Create(NewUser("trinity", "123", false));

            InternalFlatFileRealm realm = new InternalFlatFileRealm(userRepository, roleRepository, new BasicPasswordPolicy(), NewRateLimitedAuthStrategy(), new InternalFlatFileRealmIT.TestJobScheduler(), initialUserRepository, adminUserRepository);

            try
            {
                realm.Initialize();
                realm.Start();
                fail("Multiple users, no default admin provided");
            }
            catch (InvalidArgumentsException)
            {
                realm.Stop();
                realm.Shutdown();
            }
            adminUserRepository.Create((new User.Builder("trinity", LegacyCredential.INACCESSIBLE)).build());
            realm.Initialize();
            realm.Start();
            assertThat(realm.GetUsernamesForRole(PredefinedRoles.ADMIN).Count, equalTo(1));
            assertThat(realm.GetUsernamesForRole(PredefinedRoles.ADMIN), contains("trinity"));
        }
Exemple #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private InternalFlatFileRealm internalTestRealmWithUsers(java.util.List<String> existing, java.util.List<String> defaultAdmin) throws Throwable
        private InternalFlatFileRealm InternalTestRealmWithUsers(IList <string> existing, IList <string> defaultAdmin)
        {
            UserRepository userRepository        = new InMemoryUserRepository();
            UserRepository initialUserRepository = new InMemoryUserRepository();
            UserRepository adminUserRepository   = new InMemoryUserRepository();
            RoleRepository roleRepository        = new InMemoryRoleRepository();

            foreach (string user in existing)
            {
                userRepository.Create(NewUser(user, "123", false));
            }
            foreach (string user in defaultAdmin)
            {
                adminUserRepository.Create((new User.Builder(user, LegacyCredential.INACCESSIBLE)).build());
            }
            return(new InternalFlatFileRealm(userRepository, roleRepository, new BasicPasswordPolicy(), NewRateLimitedAuthStrategy(), new InternalFlatFileRealmIT.TestJobScheduler(), initialUserRepository, adminUserRepository));
        }