You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by kr...@apache.org on 2019/02/25 17:31:06 UTC

[knox] branch master updated: KNOX-1791 - MasterService should be a field on GatewayServices - replace "Master Service" with (new) constant, reordered constants in GatewayServices (#58)

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new ac53ac4  KNOX-1791 - MasterService should be a field on GatewayServices - replace "Master Service" with (new) constant, reordered constants in GatewayServices (#58)
ac53ac4 is described below

commit ac53ac4288c04ff639e32e1cff6f2efbb791c4f3
Author: Robert Levas <rl...@users.noreply.github.com>
AuthorDate: Mon Feb 25 12:31:01 2019 -0500

    KNOX-1791 - MasterService should be a field on GatewayServices - replace "Master Service" with (new) constant, reordered constants in GatewayServices (#58)
---
 .../pac4j/filter/Pac4jDispatcherFilter.java        |  2 +-
 .../org/apache/knox/gateway/GatewayServer.java     |  2 +-
 .../knox/gateway/services/CLIGatewayServices.java  |  2 +-
 .../gateway/services/DefaultGatewayServices.java   |  2 +-
 .../topology/simple/SimpleDescriptorHandler.java   |  2 +-
 .../java/org/apache/knox/gateway/util/KnoxCLI.java |  2 +-
 .../org/apache/knox/gateway/util/KnoxCLITest.java  | 12 +++++------
 .../gateway/dispatch/DefaultHttpClientFactory.java |  2 +-
 .../knox/gateway/services/GatewayServices.java     | 24 ++++++++++++----------
 .../gateway/SimpleDescriptorHandlerFuncTest.java   |  2 +-
 10 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java b/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java
index b220718..a78e38b 100644
--- a/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java
+++ b/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java
@@ -112,7 +112,7 @@ public class Pac4jDispatcherFilter implements Filter {
         keystoreService = services.getService(GatewayServices.KEYSTORE_SERVICE);
         cryptoService = services.getService(GatewayServices.CRYPTO_SERVICE);
         aliasService = services.getService(GatewayServices.ALIAS_SERVICE);
-        masterService = services.getService("MasterService");
+        masterService = services.getService(GatewayServices.MASTER_SERVICE);
       }
     }
     // crypto service, alias service and cluster name are mandatory
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
index b5f6aa6..6539c68 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
@@ -369,7 +369,7 @@ public class GatewayServer {
       httpsConfig.setSecureScheme( "https" );
       httpsConfig.setSecurePort( connectorPort );
       httpsConfig.addCustomizer( new SecureRequestCustomizer() );
-      SSLService ssl = services.getService("SSLService");
+      SSLService ssl = services.getService(GatewayServices.SSL_SERVICE);
       SslContextFactory sslContextFactory = (SslContextFactory)ssl.buildSslContextFactory( config.getIdentityKeystorePath(), config.getIdentityKeystoreType(), config.getIdentityKeyAlias() );
       connector = new ServerConnector( server, sslContextFactory, new HttpConnectionFactory( httpsConfig ) );
     } else {
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/CLIGatewayServices.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/CLIGatewayServices.java
index 954ef93..f889760 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/CLIGatewayServices.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/CLIGatewayServices.java
@@ -59,7 +59,7 @@ public class CLIGatewayServices implements GatewayServices {
 
     ms = new CLIMasterService();
     ms.init(config, options);
-    services.put("MasterService", ms);
+    services.put(MASTER_SERVICE, ms);
 
     ks = new DefaultKeystoreService();
     ks.setMasterService(ms);
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/DefaultGatewayServices.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/DefaultGatewayServices.java
index d9c5a73..171de72 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/DefaultGatewayServices.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/DefaultGatewayServices.java
@@ -63,7 +63,7 @@ public class DefaultGatewayServices implements GatewayServices {
   public void init(GatewayConfig config, Map<String,String> options) throws ServiceLifecycleException {
     ms = new DefaultMasterService();
     ms.init(config, options);
-    services.put("MasterService", ms);
+    services.put(MASTER_SERVICE, ms);
 
     ks = new DefaultKeystoreService();
     ks.setMasterService(ms);
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
index da198c7..ac407aa 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
@@ -253,7 +253,7 @@ public class SimpleDescriptorHandler {
         try {
             GatewayServices services = GatewayServer.getGatewayServices();
             if (services != null) {
-                MasterService ms = services.getService("MasterService");
+                MasterService ms = services.getService(GatewayServices.MASTER_SERVICE);
                 if (ms != null) {
                     KeystoreService ks = services.getService(GatewayServices.KEYSTORE_SERVICE);
                     if (ks != null) {
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java b/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
index 33e6dbd..2856851 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
@@ -684,7 +684,7 @@ public class KnoxCLI extends Configured implements Tool {
          if ( !isForceRequired(config, ks) || force) {
            char[] passphrase = as.getGatewayIdentityPassphrase();
            if (passphrase == null) {
-             MasterService ms = services.getService("MasterService");
+             MasterService ms = services.getService(GatewayServices.MASTER_SERVICE);
              passphrase = ms.getMasterSecret();
            }
            ks.addSelfSignedCertForGateway(config.getIdentityKeyAlias(), passphrase, hostname);
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java b/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java
index f0cbe07..6b6a7ae 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java
@@ -670,7 +670,7 @@ public class KnoxCLITest {
     KnoxCLI cli = new KnoxCLI();
     int rc = cli.run(args);
     assertThat( rc, is( 0 ) );
-    MasterService ms = cli.getGatewayServices().getService("MasterService");
+    MasterService ms = cli.getGatewayServices().getService(GatewayServices.MASTER_SERVICE);
     String master = String.copyValueOf( ms.getMasterSecret() );
     assertThat( master, is( "master" ) );
     assertThat( outContent.toString(StandardCharsets.UTF_8.name()), containsString( "Master secret has been persisted to disk." ) );
@@ -770,7 +770,7 @@ public class KnoxCLITest {
     cli.setConf( config );
     rc = cli.run(args);
     assertEquals(0, rc);
-    MasterService ms = cli.getGatewayServices().getService("MasterService");
+    MasterService ms = cli.getGatewayServices().getService(GatewayServices.MASTER_SERVICE);
     // assertTrue(ms.getClass().getName(), ms.getClass().getName().equals("kjdfhgjkhfdgjkh"));
     assertEquals(new String(ms.getMasterSecret()), "master", new String(ms.getMasterSecret()));
     assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("Master secret has been persisted to disk."));
@@ -792,7 +792,7 @@ public class KnoxCLITest {
     cli.setConf(config);
     rc = cli.run(args);
     assertThat( rc, is( 0 ) );
-    MasterService ms = cli.getGatewayServices().getService("MasterService");
+    MasterService ms = cli.getGatewayServices().getService(GatewayServices.MASTER_SERVICE);
     String master = String.copyValueOf( ms.getMasterSecret() );
     assertThat( master.length(), is( 36 ) );
     assertThat( master.indexOf( '-' ), is( 8 ) );
@@ -809,7 +809,7 @@ public class KnoxCLITest {
     outContent.reset();
     cli = new KnoxCLI();
     rc = cli.run(args);
-    ms = cli.getGatewayServices().getService("MasterService");
+    ms = cli.getGatewayServices().getService(GatewayServices.MASTER_SERVICE);
     String master2 = String.copyValueOf( ms.getMasterSecret() );
     assertThat( master2.length(), is( 36 ) );
     assertThat( UUID.fromString( master2 ), notNullValue() );
@@ -838,7 +838,7 @@ public class KnoxCLITest {
 
     rc = cli.run(args);
     assertThat( rc, is( 0 ) );
-    ms = cli.getGatewayServices().getService("MasterService");
+    ms = cli.getGatewayServices().getService(GatewayServices.MASTER_SERVICE);
     String master = String.copyValueOf( ms.getMasterSecret() );
     assertThat( master, is( "test-master-1" ) );
     assertThat( outContent.toString(StandardCharsets.UTF_8.name()), containsString( "Master secret has been persisted to disk." ) );
@@ -852,7 +852,7 @@ public class KnoxCLITest {
     args = new String[]{ "create-master", "--master", "test-master-2", "--force" };
     rc = cli.run(args);
     assertThat( rc, is( 0 ) );
-    ms = cli.getGatewayServices().getService("MasterService");
+    ms = cli.getGatewayServices().getService(GatewayServices.MASTER_SERVICE);
     master = String.copyValueOf( ms.getMasterSecret() );
     assertThat( master, is( "test-master-2" ) );
     assertThat( outContent.toString(StandardCharsets.UTF_8.name()), containsString( "Master secret has been persisted to disk." ) );
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/DefaultHttpClientFactory.java b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/DefaultHttpClientFactory.java
index 2b38171..da03850 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/DefaultHttpClientFactory.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/DefaultHttpClientFactory.java
@@ -80,7 +80,7 @@ public class DefaultHttpClientFactory implements HttpClientFactory {
     }
     if (Boolean.parseBoolean(filterConfig.getInitParameter("useTwoWaySsl"))) {
       char[] keypass = null;
-      MasterService ms = services.getService("MasterService");
+      MasterService ms = services.getService(GatewayServices.MASTER_SERVICE);
       AliasService as = services.getService(GatewayServices.ALIAS_SERVICE);
       try {
         keypass = as.getGatewayIdentityPassphrase();
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/GatewayServices.java b/gateway-spi/src/main/java/org/apache/knox/gateway/services/GatewayServices.java
index db512a0..b059a81 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/GatewayServices.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/GatewayServices.java
@@ -27,21 +27,23 @@ public interface GatewayServices extends Service,
   String GATEWAY_CLUSTER_ATTRIBUTE = "org.apache.knox.gateway.gateway.cluster";
   String GATEWAY_SERVICES_ATTRIBUTE = "org.apache.knox.gateway.gateway.services";
 
-  String SSL_SERVICE = "SSLService";
-  String CRYPTO_SERVICE = "CryptoService";
+  /* ************************************************************************************
+   * Service Name Constants
+   * ************************************************************************************ */
   String ALIAS_SERVICE = "AliasService";
-  String KEYSTORE_SERVICE = "KeystoreService";
-  String TOKEN_SERVICE = "TokenService";
-  String SERVICE_REGISTRY_SERVICE = "ServiceRegistryService";
+  String CLUSTER_CONFIGURATION_MONITOR_SERVICE = "ClusterConfigurationMonitorService";
+  String CRYPTO_SERVICE = "CryptoService";
   String HOST_MAPPING_SERVICE = "HostMappingService";
-  String SERVER_INFO_SERVICE = "ServerInfoService";
-  String TOPOLOGY_SERVICE = "TopologyService";
-  String SERVICE_DEFINITION_REGISTRY = "ServiceDefinitionRegistry";
+  String KEYSTORE_SERVICE = "KeystoreService";
+  String MASTER_SERVICE = "MasterService";
   String METRICS_SERVICE = "MetricsService";
-
   String REMOTE_REGISTRY_CLIENT_SERVICE = "RemoteConfigRegistryClientService";
-
-  String CLUSTER_CONFIGURATION_MONITOR_SERVICE = "ClusterConfigurationMonitorService";
+  String SERVER_INFO_SERVICE = "ServerInfoService";
+  String SERVICE_DEFINITION_REGISTRY = "ServiceDefinitionRegistry";
+  String SERVICE_REGISTRY_SERVICE = "ServiceRegistryService";
+  String SSL_SERVICE = "SSLService";
+  String TOKEN_SERVICE = "TokenService";
+  String TOPOLOGY_SERVICE = "TopologyService";
 
   Collection<String> getServiceNames();
 
diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java b/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java
index 9e766a2..c3e9cc2 100644
--- a/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java
@@ -174,7 +174,7 @@ public class SimpleDescriptorHandlerFuncTest {
       MasterService ms = EasyMock.createNiceMock(MasterService.class);
       EasyMock.expect(ms.getMasterSecret()).andReturn(testMasterSecret.toCharArray()).anyTimes();
       EasyMock.replay(ms);
-      EasyMock.expect(gatewayServices.getService("MasterService")).andReturn(ms).anyTimes();
+      EasyMock.expect(gatewayServices.getService(GatewayServices.MASTER_SERVICE)).andReturn(ms).anyTimes();
 
       // Keystore Service
       KeystoreService ks = EasyMock.createNiceMock(KeystoreService.class);