示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.internal.kernel.api.security.LoginContext login(java.util.Map<String,Object> authToken) throws org.neo4j.kernel.api.security.exception.InvalidAuthTokenException
        public override LoginContext Login(IDictionary <string, object> authToken)
        {
            try
            {
                AssertValidScheme(authToken);

                string  username = AuthToken.safeCast(Org.Neo4j.Kernel.api.security.AuthToken_Fields.PRINCIPAL, authToken);
                sbyte[] password = AuthToken.safeCastCredentials(Org.Neo4j.Kernel.api.security.AuthToken_Fields.CREDENTIALS, authToken);

                User user = UserRepository.getUserByName(username);
                AuthenticationResult result = AuthenticationResult.FAILURE;
                if (user != null)
                {
                    result = AuthStrategy.authenticate(user, password);
                    if (result == AuthenticationResult.SUCCESS && user.PasswordChangeRequired())
                    {
                        result = AuthenticationResult.PASSWORD_CHANGE_REQUIRED;
                    }
                }
                return(new BasicLoginContext(user, result));
            }
            finally
            {
                AuthToken.clearCredentials(authToken);
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFindAndAuthenticateUserSuccessfully() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFindAndAuthenticateUserSuccessfully()
        {
            // Given
            _manager.start();
            User user1 = NewUser("jake", "abc123", false);

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

            // When
            when(_authStrategy.authenticate(user, Password("abc123"))).thenReturn(SUCCESS);

            // Then
            AssertLoginGivesResult("jake", "abc123", SUCCESS);
        }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected org.apache.shiro.authc.AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) throws org.apache.shiro.authc.AuthenticationException
		 protected internal override AuthenticationInfo DoGetAuthenticationInfo( AuthenticationToken token )
		 {
			  if ( !_authenticationEnabled )
			  {
					return null;
			  }

			  ShiroAuthToken shiroAuthToken = ( ShiroAuthToken ) token;

			  string username;
			  sbyte[] password;
			  try
			  {
					username = AuthToken.safeCast( Org.Neo4j.Kernel.api.security.AuthToken_Fields.PRINCIPAL, shiroAuthToken.AuthTokenMap );
					password = AuthToken.safeCastCredentials( Org.Neo4j.Kernel.api.security.AuthToken_Fields.CREDENTIALS, shiroAuthToken.AuthTokenMap );
			  }
			  catch ( InvalidAuthTokenException e )
			  {
					throw new UnsupportedTokenException( e );
			  }

			  User user = _userRepository.getUserByName( username );
			  if ( user == null )
			  {
					throw new UnknownAccountException();
			  }

			  AuthenticationResult result = _authenticationStrategy.authenticate( user, password );

			  switch ( result )
			  {
			  case AuthenticationResult.FAILURE:
					throw new IncorrectCredentialsException();
			  case AuthenticationResult.TOO_MANY_ATTEMPTS:
					throw new ExcessiveAttemptsException();
			  default:
					break;
			  }

			  if ( user.HasFlag( InternalFlatFileRealm.IS_SUSPENDED ) )
			  {
					throw new DisabledAccountException( "User '" + user.Name() + "' is suspended." );
			  }

			  if ( user.PasswordChangeRequired() )
			  {
					result = AuthenticationResult.PASSWORD_CHANGE_REQUIRED;
			  }

			  // NOTE: We do not cache the authentication info using the Shiro cache manager,
			  // so all authentication request will go through this method.
			  // Hence the credentials matcher is set to AllowAllCredentialsMatcher,
			  // and we do not need to store hashed credentials in the AuthenticationInfo.
			  return new ShiroAuthenticationInfo( user.Name(), Name, result );
		 }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldActivateActiveUser() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldActivateActiveUser()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.security.User user = newUser("jake", "abc123", false);
            User user = NewUser("jake", "abc123", false);

            Users.create(user);
            _manager.start();
            when(_authStrategy.authenticate(user, password("abc123"))).thenReturn(AuthenticationResult.SUCCESS);

            // When
            _userManager.activateUser("jake", false);
            SetMockAuthenticationStrategyResult("jake", "abc123", AuthenticationResult.SUCCESS);

            // Then
            AuthenticationResult result = _manager.login(authToken("jake", "abc123")).subject().AuthenticationResult;

            assertThat(result, equalTo(AuthenticationResult.SUCCESS));
        }