Search in sources :

Example 1 with AuthorizationExpiredException

use of org.neo4j.graphdb.security.AuthorizationExpiredException in project neo4j by neo4j.

the class LdapRealm method queryForAuthorizationInfo.

@Override
protected AuthorizationInfo queryForAuthorizationInfo(PrincipalCollection principals, LdapContextFactory ldapContextFactory) throws NamingException {
    if (authorizationEnabled) {
        String username = getUsername(principals);
        if (username == null) {
            return null;
        }
        if (useSystemAccountForAuthorization) {
            // Perform context search using the system context
            LdapContext ldapContext = useStartTls ? getSystemLdapContextUsingStartTls(ldapContextFactory) : ldapContextFactory.getSystemLdapContext();
            Set<String> roleNames;
            try {
                roleNames = findRoleNamesForUser(username, ldapContext);
            } finally {
                LdapUtils.closeContext(ldapContext);
            }
            return new SimpleAuthorizationInfo(roleNames);
        } else {
            // Authorization info is cached during authentication
            Cache<Object, AuthorizationInfo> authorizationCache = getAuthorizationCache();
            AuthorizationInfo authorizationInfo = authorizationCache.get(username);
            if (authorizationInfo == null) {
                // so that the client can react by re-authenticating.
                throw new AuthorizationExpiredException("LDAP authorization info expired.");
            }
            return authorizationInfo;
        }
    }
    return null;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) AuthorizationInfo(org.apache.shiro.authz.AuthorizationInfo) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapContext(javax.naming.ldap.LdapContext)

Example 2 with AuthorizationExpiredException

use of org.neo4j.graphdb.security.AuthorizationExpiredException in project neo4j by neo4j.

the class BoltStateMachineTest method shouldTerminateOnAuthExpiryDuringSTREAMING.

@SuppressWarnings("unchecked")
@Test
public void shouldTerminateOnAuthExpiryDuringSTREAMING() throws Throwable {
    // Given
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onRecords(any(), anyBoolean());
    BoltStateMachine machine = newMachine(STREAMING);
    // We assume the only implementation of statement processor is TransactionStateMachine
    ((TransactionStateMachine) machine.statementProcessor()).ctx.currentResult = BoltResult.EMPTY;
    // When & Then
    assertException(() -> machine.pullAll(responseHandler), BoltConnectionAuthFatality.class, "Auth expired!");
    // When & Then
    assertException(() -> machine.discardAll(responseHandler), BoltConnectionAuthFatality.class, "Auth expired!");
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) Test(org.junit.Test)

Example 3 with AuthorizationExpiredException

use of org.neo4j.graphdb.security.AuthorizationExpiredException in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringREADYRun.

@SuppressWarnings("unchecked")
@Test
void shouldTerminateOnAuthExpiryDuringREADYRun() throws Throwable {
    // Given
    TransactionStateMachineSPI transactionSPI = mock(TransactionStateMachineSPI.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(transactionSPI).beginTransaction(any(), any(), any(), any(), any(), any());
    BoltStateMachine machine = newMachineWithTransactionSPI(transactionSPI);
    // When & Then
    try {
        machine.process(BoltV4Messages.run("THIS WILL BE IGNORED"), nullResponseHandler());
        fail("Exception expected");
    } catch (BoltConnectionAuthFatality e) {
        assertEquals("Auth expired!", e.getCause().getMessage());
    }
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Example 4 with AuthorizationExpiredException

use of org.neo4j.graphdb.security.AuthorizationExpiredException in project neo4j by neo4j.

the class KernelTransactionsTest method shouldNotLeakTransactionOnSecurityContextFreezeFailure.

@Test
void shouldNotLeakTransactionOnSecurityContextFreezeFailure() throws Throwable {
    KernelTransactions kernelTransactions = newKernelTransactions();
    LoginContext loginContext = mock(LoginContext.class);
    when(loginContext.authorize(any(), any(), any())).thenThrow(new AuthorizationExpiredException("Freeze failed."));
    assertThatThrownBy(() -> kernelTransactions.newInstance(EXPLICIT, loginContext, EMBEDDED_CONNECTION, 0L)).isInstanceOf(AuthorizationExpiredException.class).hasMessage("Freeze failed.");
    assertThat(kernelTransactions.activeTransactions()).as("We should not have any transaction").isEmpty();
}
Also used : LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) Test(org.junit.jupiter.api.Test)

Example 5 with AuthorizationExpiredException

use of org.neo4j.graphdb.security.AuthorizationExpiredException in project neo4j by neo4j.

the class BoltStateMachineTest method shouldTerminateOnAuthExpiryDuringREADYRun.

@SuppressWarnings("unchecked")
@Test
public void shouldTerminateOnAuthExpiryDuringREADYRun() throws Throwable {
    // Given
    TransactionStateMachine.SPI transactionSPI = mock(TransactionStateMachine.SPI.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(transactionSPI).beginTransaction(any());
    BoltStateMachine machine = newMachineWithTransactionSPI(transactionSPI);
    machine.state = READY;
    // When & Then
    assertException(() -> machine.run("THIS WILL BE IGNORED", Collections.emptyMap(), nullResponseHandler()), BoltConnectionAuthFatality.class, "Auth expired!");
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) Test(org.junit.Test)

Aggregations

AuthorizationExpiredException (org.neo4j.graphdb.security.AuthorizationExpiredException)7 Test (org.junit.jupiter.api.Test)4 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)3 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)3 Test (org.junit.Test)2 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)2 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)2 InitialLdapContext (javax.naming.ldap.InitialLdapContext)1 LdapContext (javax.naming.ldap.LdapContext)1 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1 TransactionStateMachineSPI (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)1 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)1