use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class AllStoreHolder method callFunction.
private AnyValue callFunction(int id, AnyValue[] input) throws ProcedureException {
ktx.assertOpen();
AccessMode mode = ktx.securityContext().mode();
if (!globalProcedures.isBuiltInFunction(id) && !mode.allowsExecuteFunction(id)) {
String message = format("Executing a user defined function is not allowed for %s.", ktx.securityContext().description());
throw ktx.securityAuthorizationHandler().logAndGetAuthorizationException(ktx.securityContext(), message);
}
final SecurityContext securityContext = mode.shouldBoostFunction(id) ? ktx.securityContext().withMode(new OverriddenAccessMode(mode, AccessMode.Static.READ)) : ktx.securityContext().withMode(new RestrictedAccessMode(mode, AccessMode.Static.READ));
try (KernelTransaction.Revertable ignore = ktx.overrideWith(securityContext)) {
return globalProcedures.callFunction(prepareContext(securityContext, ProcedureCallContext.EMPTY), id, input);
}
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class OperationsTest method runForSecurityLevel.
protected String runForSecurityLevel(Executable executable, AccessMode mode, boolean shoudldBeAuthorized) throws Exception {
SecurityContext securityContext = SecurityContext.authDisabled(mode, ClientConnectionInfo.EMBEDDED_CONNECTION, DB_NAME);
when(transaction.securityContext()).thenReturn(securityContext);
when(transaction.securityAuthorizationHandler()).thenReturn(new SecurityAuthorizationHandler(securityLog));
when(nodeCursor.next()).thenReturn(true);
when(nodeCursor.hasLabel(2)).thenReturn(false);
when(nodeCursor.hasLabel(3)).thenReturn(true);
when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 2));
if (shoudldBeAuthorized) {
assertAuthorized(executable);
return null;
} else {
AuthorizationViolationException exception = assertThrows(AuthorizationViolationException.class, executable);
return exception.getMessage();
}
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class KernelTransactionImplementation method overrideWith.
@Override
public Revertable overrideWith(SecurityContext context) {
SecurityContext oldContext = this.securityContext;
this.securityContext = context;
return () -> this.securityContext = oldContext;
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class SecurityContextDescriptionTest method shouldMakeNiceDescriptionWithMode.
@Test
void shouldMakeNiceDescriptionWithMode() {
SecurityContext modified = context.withMode(AccessMode.Static.WRITE);
assertThat(modified.description()).isEqualTo("user 'johan' with WRITE");
}
use of org.neo4j.internal.kernel.api.security.SecurityContext in project neo4j by neo4j.
the class SecurityContextDescriptionTest method shouldMakeNiceDescriptionRestricted.
@Test
void shouldMakeNiceDescriptionRestricted() {
SecurityContext restricted = context.withMode(new RestrictedAccessMode(context.mode(), AccessMode.Static.READ));
assertThat(restricted.description()).isEqualTo("user 'johan' with FULL restricted to READ");
}
Aggregations