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;
}
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!");
}
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());
}
}
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();
}
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!");
}
Aggregations