/** * Extends config with defaults for server, i.e. auth and connector settings. */ @Nonnull public Builder withServerDefaults() { // Add server defaults HttpConnector http = new HttpConnector( "http", NONE ); HttpConnector https = new HttpConnector( "https", TLS ); BoltConnector bolt = new BoltConnector( "bolt" ); overriddenDefaults.put( GraphDatabaseSettings.auth_enabled.name(), TRUE ); overriddenDefaults.put( http.enabled.name(), TRUE ); overriddenDefaults.put( https.enabled.name(), TRUE ); overriddenDefaults.put( bolt.enabled.name(), TRUE ); return this; }
private static HttpConnector findConnector( Config config, Encryption encryption ) { return config.enabledHttpConnectors() .stream() .filter( connector -> connector.encryptionLevel() == encryption ) .findFirst() .orElse( null ); }
private void registerHttpAddressAfterStartup() { if ( httpConnector != null ) { InetSocketAddress localHttpAddress = webServer.getLocalHttpAddress(); connectorPortRegister.register( httpConnector.key(), localHttpAddress ); if ( httpAdvertisedAddress.getPort() == 0 ) { httpAdvertisedAddress = new AdvertisedSocketAddress( localHttpAddress.getHostString(), localHttpAddress.getPort() ); } } }
/** * @return stream of all configured http connectors */ @Nonnull private Stream<HttpConnector> httpConnectors( @Nonnull Map<String,String> params ) { return allConnectorIdentifiers( params ).stream() .map( Connector::new ) .filter( c -> c.group.groupKey.equalsIgnoreCase( "http" ) || c.group.groupKey.equalsIgnoreCase( "https" ) || HTTP == c.type.apply( params::get ) ) .map( c -> { final String name = c.group.groupKey; final Encryption defaultEncryption; switch ( name ) { case "https": defaultEncryption = TLS; break; case "http": default: defaultEncryption = NONE; break; } return new HttpConnector( name, HttpConnectorValidator.encryptionSetting( name, defaultEncryption ).apply( params::get ) ); } ); }
private Optional<URI> httpConnectorUri( String scheme, Encryption encryption ) { return server.getConfig() .enabledHttpConnectors() .stream() .filter( connector -> connector.encryptionLevel() == encryption ) .findFirst() .map( connector -> connectorUri( scheme, connector ) ); }
private void registerHttpsAddressAfterStartup() { if ( httpsConnector != null ) { InetSocketAddress localHttpsAddress = webServer.getLocalHttpsAddress(); connectorPortRegister.register( httpsConnector.key(), localHttpsAddress ); if ( httpsAdvertisedAddress.getPort() == 0 ) { httpsAdvertisedAddress = new AdvertisedSocketAddress( localHttpsAddress.getHostString(), localHttpsAddress.getPort() ); } } }
@Test public void connectorSettingHasItsOwnValues() { Config config = Config.builder().withServerDefaults() .withSetting( new HttpConnector( "http" ).address, "localhost:123" ).build(); ConfigValue address = config.getConfigValues().entrySet().stream() .filter( c -> c.getKey().equals( "dbms.connector.http.address" ) ) .map( Entry::getValue ) .findAny() .orElseThrow( () -> new RuntimeException( "Setting not present!" ) ); assertTrue( address.deprecated() ); assertEquals( Optional.of( "dbms.connector.http.listen_address" ), address.replacement() ); } }
.filter( c -> Encryption.NONE.equals( c.encryptionLevel() ) ) .findFirst() .map( connector -> config.get( connector.listen_address ).toString() )
@Test void shouldDeriveListenAddressFromDefaultListenAddressAndSpecifiedPorts() { // given Config config = Config.defaults( stringMap( "dbms.connector.https.enabled", "true", "dbms.connector.http.enabled", "true", "dbms.connectors.default_listen_address", "0.0.0.0", "dbms.connector.http.listen_address", ":8000", "dbms.connector.https.listen_address", ":9000" ) ); // then assertEquals( 2, config.enabledHttpConnectors().size() ); config.enabledHttpConnectors().forEach( c -> { if ( c.key().equals( "https" ) ) { assertEquals( new ListenSocketAddress( "0.0.0.0", 9000 ), config.get( c.listen_address ) ); } else { assertEquals( new ListenSocketAddress( "0.0.0.0", 8000 ), config.get( c.listen_address ) ); } } ); }
@Test public void shouldAdvertiseServicesWhenAsked() throws Exception { UriInfo uriInfo = mock( UriInfo.class ); URI uri = new URI( "http://example.org:7474/" ); when( uriInfo.getBaseUri() ).thenReturn( uri ); RootService svc = new RootService( new CommunityNeoServer( Config.defaults( stringMap( new HttpConnector( "http", Encryption.NONE ).type.name(), "HTTP", new HttpConnector( "http", Encryption.NONE ).enabled.name(), "true" ) ), GraphDatabaseDependencies.newDependencies().userLogProvider( NullLogProvider.getInstance() ) .monitors( new Monitors() ) ) ); EntityOutputFormat output = new EntityOutputFormat( new JsonFormat(), null, null ); Response serviceDefinition = svc.getServiceDefinition( uriInfo, output ); assertEquals( 200, serviceDefinition.getStatus() ); Map<String, Object> result = (Map<String, Object>) output.getResultAsMap().get( "services" ); assertThat( result.get( "console" ) .toString(), containsString( String.format( "%sserver/console", uri.toString() ) ) ); assertThat( result.get( "jmx" ) .toString(), containsString( String.format( "%sserver/jmx", uri.toString() ) ) ); } }
@Test void testServerDefaultSettings() { // given Config config = Config.builder().withServerDefaults().build(); // when List<HttpConnector> connectors = config.httpConnectors(); // then assertEquals( 2, connectors.size() ); if ( connectors.get( 0 ).encryptionLevel().equals( TLS ) ) { assertEquals( new ListenSocketAddress( "localhost", 7474 ), config.get( connectors.get( 1 ).listen_address ) ); assertEquals( new ListenSocketAddress( "localhost", 7473 ), config.get( connectors.get( 0 ).listen_address ) ); } else { assertEquals( new ListenSocketAddress( "127.0.0.1", 7474 ), config.get( connectors.get( 0 ).listen_address ) ); assertEquals( new ListenSocketAddress( "127.0.0.1", 7473 ), config.get( connectors.get( 1 ).listen_address ) ); } }
private void registerHttpsAddressAfterStartup() { if ( httpsConnector != null ) { InetSocketAddress localHttpsAddress = webServer.getLocalHttpsAddress(); connectorPortRegister.register( httpsConnector.key(), localHttpsAddress ); if ( httpsAdvertisedAddress.getPort() == 0 ) { httpsAdvertisedAddress = new AdvertisedSocketAddress( localHttpsAddress.getHostString(), localHttpsAddress.getPort() ); } } }
private Map<String,String> getPropertyPairs() { Map<String,String> properties = new HashMap<>(); properties.put( GraphDatabaseSettings.data_directory.name(), testDir.databaseDir().toString() ); properties.put( GraphDatabaseSettings.logs_directory.name(), testDir.databaseDir().toString() ); properties.put( LegacySslPolicyConfig.certificates_directory.name(), testDir.databaseDir().toString() ); properties.put( GraphDatabaseSettings.allow_upgrade.name(), Settings.TRUE ); HttpConnector http = new HttpConnector( "http", Encryption.NONE ); properties.put( http.type.name(), "HTTP" ); properties.put( http.listen_address.name(), "localhost:0" ); properties.put( http.enabled.name(), Settings.TRUE ); HttpConnector https = new HttpConnector( "https", Encryption.TLS ); properties.put( https.type.name(), "HTTP" ); properties.put( https.listen_address.name(), "localhost:0" ); properties.put( https.enabled.name(), Settings.TRUE ); BoltConnector bolt = new BoltConnector( DEFAULT_CONNECTOR_KEY ); properties.put( bolt.type.name(), "BOLT" ); properties.put( bolt.enabled.name(), "true" ); properties.put( bolt.listen_address.name(), "localhost:0" ); properties.put( GraphDatabaseSettings.database_path.name(), testDir.absolutePath().getAbsolutePath() ); return properties; }
private static HttpConnector findConnector( Config config, Encryption encryption ) { return config.enabledHttpConnectors() .stream() .filter( connector -> connector.encryptionLevel() == encryption ) .findFirst() .orElse( null ); }
private void registerHttpAddressAfterStartup() { if ( httpConnector != null ) { InetSocketAddress localHttpAddress = webServer.getLocalHttpAddress(); connectorPortRegister.register( httpConnector.key(), localHttpAddress ); if ( httpAdvertisedAddress.getPort() == 0 ) { httpAdvertisedAddress = new AdvertisedSocketAddress( localHttpAddress.getHostString(), localHttpAddress.getPort() ); } } }
HttpConnector httpConnector = new HttpConnector( "http", Encryption.NONE ); HttpConnector httpsConnector = new HttpConnector( "https", Encryption.TLS );
private Optional<URI> httpConnectorUri( String scheme, Encryption encryption ) { return server.getConfig() .enabledHttpConnectors() .stream() .filter( connector -> connector.encryptionLevel() == encryption ) .findFirst() .map( connector -> connectorUri( scheme, connector ) ); }
private void init( File workingDir ) { setDirectory( workingDir ); withConfig( auth_enabled, "false" ); withConfig( pagecache_memory, "8m" ); BoltConnector bolt0 = new BoltConnector( "bolt" ); HttpConnector http1 = new HttpConnector( "http", Encryption.NONE ); HttpConnector http2 = new HttpConnector( "https", Encryption.TLS ); withConfig( http1.type, "HTTP" ); withConfig( http1.encryption, Encryption.NONE.name() ); withConfig( http1.enabled, "true" ); withConfig( http1.address, "localhost:0" ); withConfig( http2.type, "HTTP" ); withConfig( http2.encryption, Encryption.TLS.name() ); withConfig( http2.enabled, "false" ); withConfig( http2.address, "localhost:0" ); withConfig( bolt0.type, "BOLT" ); withConfig( bolt0.enabled, "true" ); withConfig( bolt0.address, "localhost:0" ); }
static ClientConnectorAddresses extractFromConfig( Config config ) { List<ConnectorUri> connectorUris = new ArrayList<>(); List<BoltConnector> boltConnectors = config.enabledBoltConnectors(); if ( boltConnectors.isEmpty() ) { throw new IllegalArgumentException( "A Bolt connector must be configured to run a cluster" ); } boltConnectors .forEach( c -> connectorUris.add( new ConnectorUri( bolt, config.get( c.advertised_address ) ) ) ); config.enabledHttpConnectors() .forEach( c -> connectorUris.add( new ConnectorUri( Encryption.NONE.equals(c.encryptionLevel() ) ? http : https, config.get( c.advertised_address ) ) ) ); return new ClientConnectorAddresses( connectorUris ); }
HttpConnector httpConnector = new HttpConnector( "0", Encryption.NONE ); HttpConnector httpsConnector = new HttpConnector( "1", Encryption.TLS ); try ( ServerControls server = getTestServerBuilder( testDir.directory() ) .withConfig( httpConnector.type, "HTTP" )