Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client connector config improvements.
* Move HTTP config from neo4j-server to neo4j-dbms. * Better defaults for dbms.connector. * bolt, http and https connectors all enabled by default. * Add tests cover old behaviour, and show that new behaviour is unsurprising. * Remove unnecessary lines from neo4j.conf.
- Loading branch information
Showing
36 changed files
with
620 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
community/dbms/src/main/java/org/neo4j/server/configuration/ClientConnectorSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package org.neo4j.server.configuration; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.neo4j.graphdb.config.Setting; | ||
import org.neo4j.graphdb.factory.Description; | ||
import org.neo4j.graphdb.factory.GraphDatabaseSettings; | ||
import org.neo4j.helpers.AdvertisedSocketAddress; | ||
import org.neo4j.helpers.ListenSocketAddress; | ||
import org.neo4j.kernel.configuration.Config; | ||
|
||
import static java.util.Collections.singletonList; | ||
|
||
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.Connector.ConnectorType.HTTP; | ||
import static org.neo4j.kernel.configuration.GroupSettingSupport.enumerate; | ||
import static org.neo4j.kernel.configuration.Settings.NO_DEFAULT; | ||
import static org.neo4j.kernel.configuration.Settings.advertisedAddress; | ||
import static org.neo4j.kernel.configuration.Settings.legacyFallback; | ||
import static org.neo4j.kernel.configuration.Settings.listenAddress; | ||
import static org.neo4j.kernel.configuration.Settings.options; | ||
import static org.neo4j.kernel.configuration.Settings.setting; | ||
|
||
public class ClientConnectorSettings | ||
{ | ||
public static HttpConnector httpConnector( String key ) | ||
{ | ||
return new HttpConnector( key, HttpConnector.Encryption.NONE ); | ||
} | ||
|
||
public static Optional<HttpConnector> httpConnector( Config config, HttpConnector.Encryption encryption ) | ||
{ | ||
List<HttpConnector> httpConnectors = config | ||
.view( enumerate( GraphDatabaseSettings.Connector.class ) ) | ||
.map( ( key ) -> new HttpConnector( key, encryption ) ) | ||
.filter( ( connConfig ) -> connConfig.group.groupKey.equals( encryption.uriScheme ) || | ||
(config.get( connConfig.type ) == HTTP && config.get( connConfig.encryption ) == encryption) ) | ||
.collect( Collectors.toList() ); | ||
if ( httpConnectors.isEmpty() ) | ||
{ | ||
httpConnectors = singletonList( new HttpConnector( encryption ) ); | ||
} | ||
|
||
return httpConnectors.stream() | ||
.filter( ( connConfig ) -> config.get( connConfig.enabled ) ) | ||
.findFirst(); | ||
} | ||
|
||
@Description("Configuration options for HTTP connectors. " + | ||
"\"(http-connector-key)\" is a placeholder for a unique name for the connector, for instance " + | ||
"\"http-public\" or some other name that describes what the connector is for.") | ||
public static class HttpConnector extends GraphDatabaseSettings.Connector | ||
{ | ||
@Description("Enable TLS for this connector") | ||
public final Setting<Encryption> encryption; | ||
|
||
@Description( "Address the connector should bind to. " + | ||
"This setting is deprecated and will be replaced by `+listen_address+`" ) | ||
public final Setting<ListenSocketAddress> address; | ||
|
||
@Description( "Address the connector should bind to" ) | ||
public final Setting<ListenSocketAddress> listen_address; | ||
|
||
@Description( "Advertised address for this connector" ) | ||
public final Setting<AdvertisedSocketAddress> advertised_address; | ||
|
||
public HttpConnector() | ||
{ | ||
this( Encryption.NONE ); | ||
} | ||
|
||
public HttpConnector( Encryption encryptionLevel ) | ||
{ | ||
this( "(http-connector-key)", encryptionLevel ); | ||
} | ||
|
||
public HttpConnector( String key, Encryption encryptionLevel ) | ||
{ | ||
super( key, null ); | ||
encryption = group.scope( setting( "encryption", options( HttpConnector.Encryption.class ), NO_DEFAULT ) ); | ||
Setting<ListenSocketAddress> legacyAddressSetting = listenAddress( "address", encryptionLevel.defaultPort ); | ||
Setting<ListenSocketAddress> listenAddressSetting = legacyFallback( legacyAddressSetting, | ||
listenAddress( "listen_address", encryptionLevel.defaultPort ) ); | ||
|
||
this.address = group.scope( legacyAddressSetting ); | ||
this.listen_address = group.scope( listenAddressSetting ); | ||
this.advertised_address = group.scope( advertisedAddress( "advertised_address", listenAddressSetting ) ); | ||
} | ||
|
||
public enum Encryption | ||
{ | ||
NONE( "http", 7474 ), TLS( "https", 7473 ); | ||
|
||
final String uriScheme; | ||
final int defaultPort; | ||
|
||
Encryption( String uriScheme, int defaultPort ) | ||
{ | ||
this.uriScheme = uriScheme; | ||
this.defaultPort = defaultPort; | ||
} | ||
} | ||
} | ||
} |
165 changes: 165 additions & 0 deletions
165
community/dbms/src/test/java/org/neo4j/server/configuration/ClientConnectorSettingsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* Copyright (c) 2002-2016 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.server.configuration; | ||
|
||
import org.junit.Test; | ||
|
||
import org.neo4j.helpers.ListenSocketAddress; | ||
import org.neo4j.kernel.configuration.Config; | ||
import org.neo4j.server.configuration.ClientConnectorSettings.HttpConnector.Encryption; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
import static org.neo4j.helpers.collection.MapUtil.stringMap; | ||
import static org.neo4j.server.configuration.ClientConnectorSettings.httpConnector; | ||
|
||
@SuppressWarnings("OptionalGetWithoutIsPresent") | ||
public class ClientConnectorSettingsTest | ||
{ | ||
@Test | ||
public void shouldHaveHttpAndHttpsEnabledByDefault() throws Exception | ||
{ | ||
// given | ||
Config config = Config.defaults(); | ||
|
||
// when | ||
ClientConnectorSettings.HttpConnector httpConnector = httpConnector( config, Encryption.NONE ).get(); | ||
ClientConnectorSettings.HttpConnector httpsConnector = httpConnector( config, Encryption.TLS ).get(); | ||
|
||
// then | ||
assertEquals( new ListenSocketAddress( "localhost", 7474 ), config.get( httpConnector.listen_address ) ); | ||
assertEquals( new ListenSocketAddress( "localhost", 7473 ), config.get( httpsConnector.listen_address ) ); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToDisableHttpConnectorWithJustOneParameter() throws Exception | ||
{ | ||
// given | ||
Config disableHttpConfig = Config.defaults(); | ||
disableHttpConfig.augment( stringMap( "dbms.connector.http.enabled", "false" ) ); | ||
|
||
// then | ||
assertFalse( httpConnector( disableHttpConfig, Encryption.NONE ).isPresent() ); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToDisableHttpsConnectorWithJustOneParameter() throws Exception | ||
{ | ||
// given | ||
Config disableHttpsConfig = Config.defaults(); | ||
disableHttpsConfig.augment( stringMap( "dbms.connector.https.enabled", "false" ) ); | ||
|
||
// then | ||
assertFalse( httpConnector( disableHttpsConfig, Encryption.TLS ).isPresent() ); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToOverrideHttpListenAddressWithJustOneParameter() throws Exception | ||
{ | ||
// given | ||
Config config = Config.defaults(); | ||
config.augment( stringMap( "dbms.connector.http.listen_address", ":8000" ) ); | ||
|
||
ClientConnectorSettings.HttpConnector httpConnector = httpConnector( config, Encryption.NONE ).get(); | ||
|
||
// then | ||
assertEquals( new ListenSocketAddress( "localhost", 8000 ), config.get( httpConnector.listen_address ) ); | ||
} | ||
|
||
@Test | ||
public void shouldBeAbleToOverrideHttpsListenAddressWithJustOneParameter() throws Exception | ||
{ | ||
// given | ||
Config config = Config.defaults(); | ||
config.augment( stringMap( "dbms.connector.https.listen_address", ":9000" ) ); | ||
|
||
ClientConnectorSettings.HttpConnector httpsConnector = httpConnector( config, Encryption.TLS ).get(); | ||
|
||
// then | ||
assertEquals( new ListenSocketAddress( "localhost", 9000 ), config.get( httpsConnector.listen_address ) ); | ||
} | ||
|
||
@Test | ||
public void shouldDeriveListenAddressFromDefaultListenAddress() throws Exception | ||
{ | ||
// given | ||
Config config = Config.defaults(); | ||
config.augment( stringMap( "dbms.connectors.default_listen_address", "0.0.0.0" ) ); | ||
|
||
// when | ||
ClientConnectorSettings.HttpConnector httpConnector = httpConnector( config, Encryption.NONE ).get(); | ||
ClientConnectorSettings.HttpConnector httpsConnector = httpConnector( config, Encryption.TLS ).get(); | ||
|
||
// then | ||
assertEquals( new ListenSocketAddress( "0.0.0.0", 7474 ), config.get( httpConnector.listen_address ) ); | ||
assertEquals( new ListenSocketAddress( "0.0.0.0", 7473 ), config.get( httpsConnector.listen_address ) ); | ||
} | ||
|
||
@Test | ||
public void shouldDeriveListenAddressFromDefaultListenAddressAndSpecifiedPorts() throws Exception | ||
{ | ||
// given | ||
Config config = Config.defaults(); | ||
config.augment( stringMap( "dbms.connectors.default_listen_address", "0.0.0.0" ) ); | ||
config.augment( stringMap( "dbms.connector.http.listen_address", ":8000" ) ); | ||
config.augment( stringMap( "dbms.connector.https.listen_address", ":9000" ) ); | ||
|
||
// when | ||
ClientConnectorSettings.HttpConnector httpConnector = httpConnector( config, Encryption.NONE ).get(); | ||
ClientConnectorSettings.HttpConnector httpsConnector = httpConnector( config, Encryption.TLS ).get(); | ||
|
||
// then | ||
assertEquals( new ListenSocketAddress( "0.0.0.0", 8000 ), config.get( httpConnector.listen_address ) ); | ||
assertEquals( new ListenSocketAddress( "0.0.0.0", 9000 ), config.get( httpsConnector.listen_address ) ); | ||
} | ||
|
||
@Test | ||
public void shouldStillSupportCustomNameForHttpConnector() throws Exception | ||
{ | ||
Config config = Config.defaults(); | ||
config.augment( stringMap( "dbms.connector.random_name_that_will_be_unsupported.type", "HTTP" ) ); | ||
config.augment( stringMap( "dbms.connector.random_name_that_will_be_unsupported.encryption", "NONE" ) ); | ||
config.augment( stringMap( "dbms.connector.random_name_that_will_be_unsupported.enabled", "true" ) ); | ||
config.augment( stringMap( "dbms.connector.random_name_that_will_be_unsupported.listen_address", ":8000" ) ); | ||
|
||
// when | ||
ClientConnectorSettings.HttpConnector httpConnector = httpConnector( config, Encryption.NONE ).get(); | ||
|
||
// then | ||
assertEquals( new ListenSocketAddress( "localhost", 8000 ), config.get( httpConnector.listen_address ) ); | ||
} | ||
|
||
@Test | ||
public void shouldStillSupportCustomNameForHttpsConnector() throws Exception | ||
{ | ||
Config config = Config.defaults(); | ||
config.augment( stringMap( "dbms.connector.random_name_that_will_be_unsupported.type", "HTTP" ) ); | ||
config.augment( stringMap( "dbms.connector.random_name_that_will_be_unsupported.encryption", "TLS" ) ); | ||
config.augment( stringMap( "dbms.connector.random_name_that_will_be_unsupported.enabled", "true" ) ); | ||
config.augment( stringMap( "dbms.connector.random_name_that_will_be_unsupported.listen_address", ":9000" ) ); | ||
|
||
// when | ||
ClientConnectorSettings.HttpConnector httpsConnector = httpConnector( config, Encryption.TLS ).get(); | ||
|
||
// then | ||
assertEquals( new ListenSocketAddress( "localhost", 9000 ), config.get( httpsConnector.listen_address ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.