use of org.hyperledger.besu.ethereum.api.jsonrpc.execution.AuthenticatedJsonRpcProcessor in project besu by hyperledger.
the class JsonRpcHttpService method buildRouter.
private Router buildRouter() {
// Handle json rpc requests
final Router router = Router.router(vertx);
router.route().handler(this::createSpan);
// Verify Host header to avoid rebind attack.
router.route().handler(checkAllowlistHostHeader());
router.route().handler(CorsHandler.create(buildCorsRegexFromConfig()).allowedHeader("*").allowedHeader("content-type"));
router.route().handler(BodyHandler.create().setUploadsDirectory(dataDir.resolve("uploads").toString()).setDeleteUploadedFilesOnEnd(true));
router.route("/").method(HttpMethod.GET).handler(this::handleEmptyRequest);
router.route(HealthService.LIVENESS_PATH).method(HttpMethod.GET).handler(livenessService::handleRequest);
router.route(HealthService.READINESS_PATH).method(HttpMethod.GET).handler(readinessService::handleRequest);
Route mainRoute = router.route("/").method(HttpMethod.POST).produces(APPLICATION_JSON);
if (authenticationService.isPresent()) {
mainRoute.handler(HandlerFactory.authentication(authenticationService.get(), config.getNoAuthRpcApis()));
}
mainRoute.handler(HandlerFactory.jsonRpcParser()).handler(HandlerFactory.timeout(new TimeoutOptions(config.getHttpTimeoutSec()), rpcMethods));
if (authenticationService.isPresent()) {
mainRoute.blockingHandler(HandlerFactory.jsonRpcExecutor(new JsonRpcExecutor(new AuthenticatedJsonRpcProcessor(new TimedJsonRpcProcessor(new TracedJsonRpcProcessor(new BaseJsonRpcProcessor()), requestTimer), authenticationService.get(), config.getNoAuthRpcApis()), rpcMethods), tracer));
} else {
mainRoute.blockingHandler(HandlerFactory.jsonRpcExecutor(new JsonRpcExecutor(new TimedJsonRpcProcessor(new TracedJsonRpcProcessor(new BaseJsonRpcProcessor()), requestTimer), rpcMethods), tracer));
}
if (authenticationService.isPresent()) {
router.route("/login").method(HttpMethod.POST).produces(APPLICATION_JSON).handler(authenticationService.get()::handleLogin);
} else {
router.route("/login").method(HttpMethod.POST).produces(APPLICATION_JSON).handler(DefaultAuthenticationService::handleDisabledLogin);
}
return router;
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.execution.AuthenticatedJsonRpcProcessor in project besu by hyperledger.
the class WebSocketServiceLoginTest method before.
@Before
public void before() throws URISyntaxException {
vertx = Vertx.vertx();
final String authTomlPath = Paths.get(ClassLoader.getSystemResource("JsonRpcHttpService/auth.toml").toURI()).toAbsolutePath().toString();
websocketConfiguration = WebSocketConfiguration.createDefault();
websocketConfiguration.setPort(0);
websocketConfiguration.setAuthenticationEnabled(true);
websocketConfiguration.setAuthenticationCredentialsFile(authTomlPath);
websocketConfiguration.setHostsAllowlist(Collections.singletonList("*"));
websocketConfiguration.setRpcApisNoAuth(new ArrayList<>(NO_AUTH_METHODS));
peerDiscoveryMock = mock(P2PNetwork.class);
blockchainQueries = mock(BlockchainQueries.class);
synchronizer = mock(Synchronizer.class);
final Set<Capability> supportedCapabilities = new HashSet<>();
supportedCapabilities.add(EthProtocol.ETH62);
supportedCapabilities.add(EthProtocol.ETH63);
final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions().constantinopleBlock(0).chainId(CHAIN_ID);
final Map<String, JsonRpcMethod> websocketMethods = new WebSocketMethodsFactory(new SubscriptionManager(new NoOpMetricsSystem()), new HashMap<>()).methods();
rpcMethods = spy(new JsonRpcMethodsFactory().methods(CLIENT_VERSION, CHAIN_ID, genesisConfigOptions, peerDiscoveryMock, blockchainQueries, synchronizer, MainnetProtocolSchedule.fromConfig(genesisConfigOptions), mock(ProtocolContext.class), mock(FilterManager.class), mock(TransactionPool.class), mock(PoWMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, Optional.empty(), Optional.empty(), JSON_RPC_APIS, mock(PrivacyParameters.class), mock(JsonRpcConfiguration.class), mock(WebSocketConfiguration.class), mock(MetricsConfiguration.class), natService, new HashMap<>(), folder.getRoot().toPath(), mock(EthPeers.class)));
websocketMethods.putAll(rpcMethods);
webSocketMessageHandlerSpy = spy(new WebSocketMessageHandler(vertx, new JsonRpcExecutor(new AuthenticatedJsonRpcProcessor(new BaseJsonRpcProcessor(), DefaultAuthenticationService.create(vertx, websocketConfiguration).get(), websocketConfiguration.getRpcApisNoAuth()), websocketMethods), mock(EthScheduler.class), TimeoutOptions.defaultOptions().getTimeoutSeconds()));
websocketService = new WebSocketService(vertx, websocketConfiguration, webSocketMessageHandlerSpy, new NoOpMetricsSystem());
websocketService.start().join();
jwtAuth = websocketService.authenticationService.get().getJwtAuthProvider();
websocketConfiguration.setPort(websocketService.socketAddress().getPort());
final HttpClientOptions httpClientOptions = new HttpClientOptions().setDefaultHost(websocketConfiguration.getHost()).setDefaultPort(websocketConfiguration.getPort());
httpClient = vertx.createHttpClient(httpClientOptions);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.execution.AuthenticatedJsonRpcProcessor in project besu by hyperledger.
the class RunnerBuilder method createWebsocketService.
private WebSocketService createWebsocketService(final Vertx vertx, final WebSocketConfiguration configuration, final SubscriptionManager subscriptionManager, final Map<String, JsonRpcMethod> jsonRpcMethods, final PrivacyParameters privacyParameters, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries, final Optional<AuthenticationService> authenticationService, final ObservableMetricsSystem metricsSystem) {
final WebSocketMethodsFactory websocketMethodsFactory = new WebSocketMethodsFactory(subscriptionManager, jsonRpcMethods);
if (privacyParameters.isEnabled()) {
final PrivateWebSocketMethodsFactory privateWebSocketMethodsFactory = new PrivateWebSocketMethodsFactory(privacyParameters, subscriptionManager, protocolSchedule, blockchainQueries);
privateWebSocketMethodsFactory.methods().forEach(websocketMethodsFactory::addMethods);
}
rpcEndpointServiceImpl.getPluginMethods(configuration.getRpcApis()).values().forEach(websocketMethodsFactory::addMethods);
final JsonRpcProcessor jsonRpcProcessor;
if (authenticationService.isPresent()) {
jsonRpcProcessor = new AuthenticatedJsonRpcProcessor(new BaseJsonRpcProcessor(), authenticationService.get(), configuration.getRpcApisNoAuth());
} else {
jsonRpcProcessor = new BaseJsonRpcProcessor();
}
final JsonRpcExecutor jsonRpcExecutor = new JsonRpcExecutor(jsonRpcProcessor, websocketMethodsFactory.methods());
final WebSocketMessageHandler websocketMessageHandler = new WebSocketMessageHandler(vertx, jsonRpcExecutor, besuController.getProtocolManager().ethContext().getScheduler(), webSocketConfiguration.getTimeoutSec());
return new WebSocketService(vertx, configuration, websocketMessageHandler, authenticationService, metricsSystem);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.execution.AuthenticatedJsonRpcProcessor in project besu by hyperledger.
the class JsonRpcService method buildRouter.
private Router buildRouter() {
// Handle json rpc requests
final Router router = Router.router(vertx);
router.route().handler(this::createSpan);
// Verify Host header to avoid rebind attack.
router.route().handler(denyRouteToBlockedHost());
router.route().handler(CorsHandler.create(buildCorsRegexFromConfig()).allowedHeader("*").allowedHeader("content-type"));
router.route().handler(BodyHandler.create().setUploadsDirectory(dataDir.resolve("uploads").toString()).setDeleteUploadedFilesOnEnd(true));
router.route("/").method(HttpMethod.GET).handler(this::handleEmptyRequest);
router.route(HealthService.LIVENESS_PATH).method(HttpMethod.GET).handler(livenessService::handleRequest);
router.route(HealthService.READINESS_PATH).method(HttpMethod.GET).handler(readinessService::handleRequest);
Route mainRoute = router.route("/").method(HttpMethod.POST).produces(APPLICATION_JSON);
if (authenticationService.isPresent()) {
mainRoute.handler(HandlerFactory.authentication(authenticationService.get(), config.getNoAuthRpcApis()));
}
mainRoute.handler(HandlerFactory.jsonRpcParser()).handler(HandlerFactory.timeout(new TimeoutOptions(config.getHttpTimeoutSec()), rpcMethods));
if (authenticationService.isPresent()) {
mainRoute.blockingHandler(HandlerFactory.jsonRpcExecutor(new JsonRpcExecutor(new AuthenticatedJsonRpcProcessor(new TimedJsonRpcProcessor(new TracedJsonRpcProcessor(new BaseJsonRpcProcessor()), requestTimer), authenticationService.get(), config.getNoAuthRpcApis()), rpcMethods), tracer));
} else {
mainRoute.blockingHandler(HandlerFactory.jsonRpcExecutor(new JsonRpcExecutor(new TimedJsonRpcProcessor(new TracedJsonRpcProcessor(new BaseJsonRpcProcessor()), requestTimer), rpcMethods), tracer));
}
if (authenticationService.isPresent()) {
router.route("/login").method(HttpMethod.POST).produces(APPLICATION_JSON).handler(authenticationService.get()::handleLogin);
} else {
router.route("/login").method(HttpMethod.POST).produces(APPLICATION_JSON).handler(DefaultAuthenticationService::handleDisabledLogin);
}
return router;
}
Aggregations