use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class AuthProcedures method listUsers.
@SystemProcedure
@Deprecated
@Description("List all native users.")
@Procedure(name = "dbms.security.listUsers", mode = READ, deprecatedBy = "Administration command: SHOW USERS")
public Stream<UserResult> listUsers() throws ProcedureException {
var query = "SHOW USERS";
List<UserResult> result = new ArrayList<>();
try {
Result execute = transaction.execute(query);
execute.accept(row -> {
var username = row.getString("user");
var changeRequired = row.getBoolean("passwordChangeRequired");
result.add(new UserResult(username, changeRequired));
return true;
});
} catch (Exception e) {
translateException(e, "dbms.security.listUsers");
}
if (result.isEmpty()) {
return showCurrentUser();
}
return result.stream();
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class BuiltInProceduresIT method listAllLabels.
@Test
void listAllLabels() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
long nodeId = transaction.dataWrite().nodeCreate();
int labelId = transaction.tokenWrite().labelGetOrCreateForName("MyLabel");
transaction.dataWrite().nodeAddLabel(nodeId, labelId);
commit();
// When
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "labels")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
assertThat(asList(stream)).containsExactly(new AnyValue[] { stringValue("MyLabel") });
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class BuiltInProceduresIT method listRelationshipTypes.
@Test
void listRelationshipTypes() throws Throwable {
// Given
KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
int relType = transaction.tokenWrite().relationshipTypeGetOrCreateForName("MyRelType");
long startNodeId = transaction.dataWrite().nodeCreate();
long endNodeId = transaction.dataWrite().nodeCreate();
transaction.dataWrite().relationshipCreate(startNodeId, relType, endNodeId);
commit();
// When
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "relationshipTypes")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
assertThat(asList(stream)).containsExactly(new AnyValue[] { stringValue("MyRelType") });
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class AllStoreHolder method callProcedure.
private RawIterator<AnyValue[], ProcedureException> callProcedure(int id, AnyValue[] input, final AccessMode.Static procedureMode, ProcedureCallContext procedureCallContext) throws ProcedureException {
ktx.assertOpen();
AccessMode mode = ktx.securityContext().mode();
if (!mode.allowsExecuteProcedure(id)) {
String message = format("Executing procedure is not allowed for %s.", ktx.securityContext().description());
throw ktx.securityAuthorizationHandler().logAndGetAuthorizationException(ktx.securityContext(), message);
}
final SecurityContext procedureSecurityContext = mode.shouldBoostProcedure(id) ? ktx.securityContext().withMode(new OverriddenAccessMode(mode, procedureMode)).withMode(AdminAccessMode.FULL) : ktx.securityContext().withMode(new RestrictedAccessMode(mode, procedureMode));
final RawIterator<AnyValue[], ProcedureException> procedureCall;
try (KernelTransaction.Revertable ignore = ktx.overrideWith(procedureSecurityContext);
Statement statement = ktx.acquireStatement()) {
procedureCall = globalProcedures.callProcedure(prepareContext(procedureSecurityContext, procedureCallContext), id, input, statement);
}
return createIterator(procedureSecurityContext, procedureCall);
}
use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ProcedureOutputSignatureCompilerTest method shouldGiveHelpfulErrorOnMapWithNonStringKeyMap.
@Test
void shouldGiveHelpfulErrorOnMapWithNonStringKeyMap() {
ProcedureException exception = assertThrows(ProcedureException.class, () -> signatures(RecordWithNonStringKeyMap.class));
assertThat(exception.getMessage()).isEqualTo("Field `wat` in record `RecordWithNonStringKeyMap` cannot be converted " + "to a Neo4j type: Maps are required to have `String` keys - but this map " + "has `org.neo4j.procedure.impl.ProcedureOutputSignatureCompilerTest$RecordWithNonStringKeyMap` keys.");
}
Aggregations