knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject [knox] branch master updated: KNOX-1848 - Default to 'zookeeper' as remote alias configuration type in case it is not set in gateway-site.xml (#93)
Date Wed, 22 May 2019 19:13:37 GMT
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 4d7ccad  KNOX-1848 - Default to 'zookeeper' as remote alias configuration type in
case it is not set in gateway-site.xml (#93)
4d7ccad is described below

commit 4d7ccad55aaf03245153ef68f620ed14d9ad127a
Author: Sandor Molnar <smolnar@apache.org>
AuthorDate: Wed May 22 20:22:20 2019 +0200

    KNOX-1848 - Default to 'zookeeper' as remote alias configuration type in case it is not
set in gateway-site.xml (#93)
---
 .../knox/gateway/config/impl/GatewayConfigImpl.java  | 11 ++++++++++-
 .../gateway/config/impl/GatewayConfigImplTest.java   | 20 +++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
index e7e9124..2bb77cb 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
@@ -24,10 +24,13 @@ import org.apache.hadoop.fs.Path;
 import org.apache.knox.gateway.GatewayMessages;
 import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.i18n.messages.MessagesFactory;
+import org.apache.knox.gateway.services.security.impl.ZookeeperRemoteAliasService;
 import org.joda.time.Period;
 import org.joda.time.format.PeriodFormatter;
 import org.joda.time.format.PeriodFormatterBuilder;
 
+import static org.apache.knox.gateway.services.security.impl.RemoteAliasService.REMOTE_ALIAS_SERVICE_TYPE;
+
 import java.io.File;
 import java.net.InetSocketAddress;
 import java.net.MalformedURLException;
@@ -989,7 +992,13 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
 
   @Override
   public Map<String, String> getRemoteAliasServiceConfiguration() {
-    return getPropsWithPrefix(getRemoteAliasServiceConfigurationPrefix());
+    final Map<String, String> remoteAliasServiceConfiguration = getPropsWithPrefix(getRemoteAliasServiceConfigurationPrefix());
+
+    //in case the remote alias service configuration type is not set we default to zookeeper
+    if (!remoteAliasServiceConfiguration.containsKey(REMOTE_ALIAS_SERVICE_TYPE)) {
+      remoteAliasServiceConfiguration.put(REMOTE_ALIAS_SERVICE_TYPE, ZookeeperRemoteAliasService.TYPE);
+    }
+    return remoteAliasServiceConfiguration;
   }
 
   @Override
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
index 65a9b17..2958cb5 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/config/impl/GatewayConfigImplTest.java
@@ -17,14 +17,17 @@
 package org.apache.knox.gateway.config.impl;
 
 import org.apache.knox.gateway.config.GatewayConfig;
+import org.apache.knox.gateway.services.security.impl.ZookeeperRemoteAliasService;
 import org.apache.knox.test.TestUtils;
 import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 
 import java.nio.file.Paths;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
+import static org.apache.knox.gateway.services.security.impl.RemoteAliasService.REMOTE_ALIAS_SERVICE_TYPE;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -37,7 +40,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-
 public class GatewayConfigImplTest {
 
   @Test( timeout = TestUtils.SHORT_TIMEOUT )
@@ -386,5 +388,21 @@ public class GatewayConfigImplTest {
     assertEquals("custom_type", config.getTruststoreType());
   }
 
+  @Test
+  public void shouldReturnUserConfiguredRemoteAliasConfigType() throws Exception {
+    final String remoteAliasServiceType = "testServiceType";
+    GatewayConfigImpl config = new GatewayConfigImpl();
+    config.set(config.getRemoteAliasServiceConfigurationPrefix() + REMOTE_ALIAS_SERVICE_TYPE,
"testServiceType");
+    final Map<String, String> remoteAliasServiceConfiguration = config.getRemoteAliasServiceConfiguration();
+    assertTrue(remoteAliasServiceConfiguration.containsKey(REMOTE_ALIAS_SERVICE_TYPE));
+    assertEquals(remoteAliasServiceType, remoteAliasServiceConfiguration.get(REMOTE_ALIAS_SERVICE_TYPE));
+  }
+
+  @Test
+  public void shouldReturnZookeeperAsRemoteAliasConfigTypeIfItIsUnset() throws Exception
{
+    final Map<String, String> remoteAliasServiceConfiguration = new GatewayConfigImpl().getRemoteAliasServiceConfiguration();
+    assertTrue(remoteAliasServiceConfiguration.containsKey(REMOTE_ALIAS_SERVICE_TYPE));
+    assertEquals(ZookeeperRemoteAliasService.TYPE, remoteAliasServiceConfiguration.get(REMOTE_ALIAS_SERVICE_TYPE));
+  }
 
 }


Mime
View raw message