Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAddInitialUserIfUsersExist() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAddInitialUserIfUsersExist()
        {
            // Given
            FileUserRepository initialUserRepository = CommunitySecurityModule.GetInitialUserRepository(Config, NullLogProvider.Instance, FsRule.get());

            initialUserRepository.Start();
            initialUserRepository.Create(NewUser("initUser", "123", false));
            initialUserRepository.Shutdown();
            Users.start();
            Users.create(NewUser("oldUser", "321", false));
            Users.shutdown();

            // When
            AuthManager().start();

            // Then
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.security.User initUser = users.getUserByName("initUser");
            User initUser = Users.getUserByName("initUser");

            assertNull(initUser);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.security.User oldUser = users.getUserByName("oldUser");
            User oldUser = Users.getUserByName("oldUser");

            assertNotNull(oldUser);
            assertTrue(oldUser.Credentials().matchesPassword("321"));
            assertFalse(oldUser.PasswordChangeRequired());
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnFailureForInvalidAttempt()
        public virtual void ShouldReturnFailureForInvalidAttempt()
        {
            // Given
            FakeClock clock = FakeClock;
            AuthenticationStrategy authStrategy = NewAuthStrategy(clock, 3);
            User user = (new User.Builder("user", LegacyCredential.ForPassword("right"))).build();

            // Then
            assertThat(authStrategy.Authenticate(user, password("wrong")), equalTo(AuthenticationResult.FAILURE));
        }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertAuthIniFile(String password) throws Throwable
        private void AssertAuthIniFile(string password)
        {
            assertTrue(_fileSystem.fileExists(_authInitFile));
            FileUserRepository userRepository = new FileUserRepository(_fileSystem, _authInitFile, NullLogProvider.Instance);

            userRepository.Start();
            User neo4j = userRepository.GetUserByName(Org.Neo4j.Kernel.api.security.UserManager_Fields.INITIAL_USER_NAME);

            assertNotNull(neo4j);
            assertTrue(neo4j.Credentials().matchesPassword(password));
            assertFalse(neo4j.HasFlag(User.PASSWORD_CHANGE_REQUIRED));
        }
Exemple #4
0
        private void TestUnlimitedFailedAuthAttempts(int maxFailedAttempts)
        {
            FakeClock clock = FakeClock;
            AuthenticationStrategy authStrategy = NewAuthStrategy(clock, maxFailedAttempts);
            User user = (new User.Builder("user", LegacyCredential.ForPassword("right"))).build();

            int attempts = ThreadLocalRandom.current().Next(5, 100);

            for (int i = 0; i < attempts; i++)
            {
                assertEquals(AuthenticationResult.FAILURE, authStrategy.Authenticate(user, password("wrong")));
            }
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateDefaultUserIfNoneExist() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateDefaultUserIfNoneExist()
        {
            // When
            AuthManager().start();

            // Then
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.security.User user = users.getUserByName("neo4j");
            User user = Users.getUserByName("neo4j");

            assertNotNull(user);
            assertTrue(user.Credentials().matchesPassword("neo4j"));
            assertTrue(user.PasswordChangeRequired());
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotSlowRequestRateOnLessThanMaxFailedAttempts()
        public virtual void ShouldNotSlowRequestRateOnLessThanMaxFailedAttempts()
        {
            // Given
            FakeClock clock = FakeClock;
            AuthenticationStrategy authStrategy = NewAuthStrategy(clock, 3);
            User user = (new User.Builder("user", LegacyCredential.ForPassword("right"))).build();

            // When we've failed two times
            assertThat(authStrategy.Authenticate(user, password("wrong")), equalTo(AuthenticationResult.FAILURE));
            assertThat(authStrategy.Authenticate(user, password("wrong")), equalTo(AuthenticationResult.FAILURE));

            // Then
            assertThat(authStrategy.Authenticate(user, password("right")), equalTo(AuthenticationResult.SUCCESS));
        }
Exemple #7
0
        public BasicLoginContext(User user, AuthenticationResult authenticationResult)
        {
            this._authSubject = new BasicAuthSubject(this, user, authenticationResult);

            switch (authenticationResult)
            {
            case AuthenticationResult.SUCCESS:
                _accessMode = [email protected]_Static.Full;
                break;

            case AuthenticationResult.PASSWORD_CHANGE_REQUIRED:
                _accessMode = [email protected]_Static.CredentialsExpired;
                break;

            default:
                _accessMode = [email protected]_Static.None;
                break;
            }
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLoadInitialUserIfNoneExistEvenWithSamePassword() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLoadInitialUserIfNoneExistEvenWithSamePassword()
        {
            // Given
            FileUserRepository initialUserRepository = CommunitySecurityModule.GetInitialUserRepository(Config, NullLogProvider.Instance, FsRule.get());

            initialUserRepository.Start();
            initialUserRepository.create(new User.Builder("neo4j", LegacyCredential.ForPassword("neo4j"))
                                         .withRequiredPasswordChange(false).build());
            initialUserRepository.Shutdown();

            // When
            AuthManager().start();

            // Then
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.security.User user = users.getUserByName("neo4j");
            User user = Users.getUserByName("neo4j");

            assertNotNull(user);
            assertTrue(user.Credentials().matchesPassword("neo4j"));
            assertFalse(user.PasswordChangeRequired());
        }
Exemple #9
0
        private void TestSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid(int maxFailedAttempts, Duration lockDuration)
        {
            // Given
            FakeClock clock = FakeClock;
            AuthenticationStrategy authStrategy = NewAuthStrategy(clock, maxFailedAttempts, lockDuration);
            User user = (new User.Builder("user", LegacyCredential.ForPassword("right"))).build();

            // When we've failed max number of times
            for (int i = 0; i < maxFailedAttempts; i++)
            {
                assertThat(authStrategy.Authenticate(user, password("wrong")), equalTo(AuthenticationResult.FAILURE));
            }

            // Then
            assertThat(authStrategy.Authenticate(user, password("right")), equalTo(AuthenticationResult.TOO_MANY_ATTEMPTS));

            // But when time heals all wounds
            clock.Forward(lockDuration.plus(1, SECONDS));

            // Then things should be alright
            assertThat(authStrategy.Authenticate(user, password("right")), equalTo(AuthenticationResult.SUCCESS));
        }
Exemple #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBuildImmutableUser()
        public virtual void ShouldBuildImmutableUser()
        {
            LegacyCredential abc   = LegacyCredential.ForPassword("123abc");
            LegacyCredential fruit = LegacyCredential.ForPassword("fruit");
            User             u1    = (new User.Builder("Steve", abc)).build();
            User             u2    = (new User.Builder("Steve", fruit)).withRequiredPasswordChange(true).withFlag("nice_guy").build();

            assertThat(u1, equalTo(u1));
            assertThat(u1, not(equalTo(u2)));

            User u1AsU2 = u1.Augment().withCredentials(fruit).withRequiredPasswordChange(true).withFlag("nice_guy").build();

            assertThat(u1, not(equalTo(u1AsU2)));
            assertThat(u2, equalTo(u1AsU2));

            User u2AsU1 = u2.Augment().withCredentials(abc).withRequiredPasswordChange(false).withoutFlag("nice_guy").build();

            assertThat(u2, not(equalTo(u2AsU1)));
            assertThat(u1, equalTo(u2AsU1));

            assertThat(u1, not(equalTo(u2)));
        }
Exemple #11
0
 public override void Logout()
 {
     User = null;
     AuthenticationResultConflict = FAILURE;
 }
Exemple #12
0
 internal BasicAuthSubject(BasicLoginContext outerInstance, User user, AuthenticationResult authenticationResult)
 {
     this._outerInstance = outerInstance;
     this.User           = user;
     this.AuthenticationResultConflict = authenticationResult;
 }
Exemple #13
0
 public AuthorizationRepresentation(User user) : base(RepresentationType.Authorization)
 {
     this._user = user;
 }