diff --git a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java index 9a87e332f..0cf60da82 100644 --- a/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java +++ b/gateway-util-launcher/src/main/java/org/apache/knox/gateway/launcher/Extender.java @@ -41,6 +41,7 @@ public class Extender { private final File base; private final Properties properties; + private final Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); public Extender(File base, Properties properties) { this.base = base; @@ -56,8 +57,7 @@ public void extendClassPathProperty() throws IOException { } protected void extractExtensionPathIntoProperty(String configContent) { - Pattern pattern = Pattern.compile(CLASSPATH_PROPERTY_PATTERN, Pattern.DOTALL); - Matcher matcher = pattern.matcher(configContent); + final Matcher matcher = pattern.matcher(configContent); if (matcher.find()) { StringBuilder newClassPath = new StringBuilder(matcher.group(1).trim()); diff --git a/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ExtenderTest.java b/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ExtenderTest.java index f5adc7378..e288a5012 100644 --- a/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ExtenderTest.java +++ b/gateway-util-launcher/src/test/java/org/apache/knox/gateway/launcher/ExtenderTest.java @@ -18,8 +18,11 @@ package org.apache.knox.gateway.launcher; +import org.junit.After; +import org.junit.Before; import org.junit.Test; +import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -34,9 +37,22 @@ public class ExtenderTest { private Path confDir; private Path configFilePath; + @Before + public void setupDirs() throws IOException { + tempDir = Files.createTempDirectory("cp_extender_test"); + confDir = Files.createDirectory(tempDir.resolve("conf")); + configFilePath = confDir.resolve("gateway-site.xml"); + } + + @After + public void cleanUpDirs() throws IOException { + Files.deleteIfExists(configFilePath); + Files.deleteIfExists(confDir); + Files.deleteIfExists(tempDir); + } + @Test public void extendClassPathPropertyTest() throws IOException { - this.setupDirs(); Properties properties = new Properties(); properties.setProperty("class.path", "classpath"); properties.setProperty("main.class", "org.apache.knox.gateway.GatewayServer"); @@ -47,12 +63,10 @@ public void extendClassPathPropertyTest() throws IOException { extender.extendClassPathProperty(); assertEquals("/new/classp/*;classpath", properties.getProperty("class.path")); - this.cleanUpDirs(); } @Test public void extendClassPathPropertyDifferentMainClassTest() throws IOException { - this.setupDirs(); Properties properties = new Properties(); properties.setProperty("class.path", "classpath"); properties.setProperty("main.class", "org.apache.knox.gateway.KnoxCLI"); @@ -63,7 +77,6 @@ public void extendClassPathPropertyDifferentMainClassTest() throws IOException { extender.extendClassPathProperty(); assertEquals("classpath", properties.getProperty("class.path")); - this.cleanUpDirs(); } @Test @@ -139,35 +152,15 @@ public void extractExtensionPathIntoPropertyEmptyWhitespaceTest() { } @Test - public void extractExtensionPathIntoPropertyNoConfigTest() { + public void extractExtensionPathIntoPropertyNoConfigTest() throws IOException { Properties properties = new Properties(); properties.setProperty("class.path", "classpath"); Extender extender = new Extender(null, properties); - String configContent = - "\n" + - " \n" + - " gateway.webshell.read.buffer.size\n" + - " 1024\n" + - " Web Shell buffer size for reading\n" + - " \n" + - "\n" + - " \n" + - " \n" + - " gateway.websocket.JWT.validation.feature.enabled\n" + - " true\n" + - " Enable/Disable websocket JWT validation at websocket layer.\n" + - " \n" + - "\n" + - " \n" + - " \n" + - " knox.homepage.logout.enabled\n" + - " true\n" + - " Enable/disable logout from the Knox Homepage.\n" + - " \n" + - ""; + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("gateway-site-test.xml").getFile()); - extender.extractExtensionPathIntoProperty(configContent); + extender.extractExtensionPathIntoProperty(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8)); assertEquals("classpath", properties.getProperty("class.path")); } @@ -180,16 +173,4 @@ private String getConfigContent(String extensionValue) { " \n" + ""; } - - private void setupDirs() throws IOException { - tempDir = Files.createTempDirectory("cp_extender_test"); - confDir = Files.createDirectory(tempDir.resolve("conf")); - configFilePath = confDir.resolve("gateway-site.xml"); - } - - private void cleanUpDirs() throws IOException { - Files.deleteIfExists(configFilePath); - Files.deleteIfExists(confDir); - Files.deleteIfExists(tempDir); - } } diff --git a/gateway-util-launcher/src/test/resources/gateway-site-test.xml b/gateway-util-launcher/src/test/resources/gateway-site-test.xml new file mode 100644 index 000000000..b442e1998 --- /dev/null +++ b/gateway-util-launcher/src/test/resources/gateway-site-test.xml @@ -0,0 +1,210 @@ + + + + + + gateway.service.alias.impl + org.apache.knox.gateway.services.security.impl.RemoteAliasService + + + gateway.port + 8443 + The HTTP port for the Gateway. + + + + gateway.path + gateway + The default context path for the gateway. + + + + gateway.gateway.conf.dir + deployments + The directory within GATEWAY_HOME that contains gateway topology files and deployments. + + + + gateway.hadoop.kerberos.secured + false + Boolean flag indicating whether the Hadoop cluster protected by Gateway is secured with Kerberos + + + + java.security.krb5.conf + /etc/knox/conf/krb5.conf + Absolute path to krb5.conf file + + + + java.security.auth.login.config + /etc/knox/conf/krb5JAASLogin.conf + Absolute path to JAAS login config file + + + + sun.security.krb5.debug + false + Boolean flag indicating whether to enable debug messages for krb5 authentication + + + + + gateway.websocket.feature.enabled + false + Enable/Disable websocket feature. + + + + gateway.scope.cookies.feature.enabled + false + Enable/Disable cookie scoping feature. + + + + gateway.cluster.config.monitor.ambari.enabled + false + Enable/disable Ambari cluster configuration monitoring. + + + + gateway.cluster.config.monitor.ambari.interval + 60 + The interval (in seconds) for polling Ambari for cluster configuration changes. + + + + + gateway.webshell.feature.enabled + false + Enable/Disable webshell feature. + + + gateway.webshell.max.concurrent.sessions + 20 + Maximum number of total concurrent webshell sessions + + + gateway.webshell.audit.logging.enabled + false + [Experimental Feature] Enable/Disable webshell command audit logging. + NOTE: Turning this on might log secrets that might be part of + command line arguments, please consider this before turning this on. + + + gateway.webshell.read.buffer.size + 1024 + Web Shell buffer size for reading + + + + + gateway.websocket.JWT.validation.feature.enabled + true + Enable/Disable websocket JWT validation at websocket layer. + + + + + knox.homepage.logout.enabled + true + Enable/disable logout from the Knox Homepage. + + + + + gateway.knox.token.management.users.can.see.all.tokens + admin + A comma separated list of user names who can see all tokens on the Token Management page + + + + + gateway.knox.token.eviction.grace.period + 0 + A duration (in seconds) beyond a token’s expiration to wait before evicting its state. This configuration only applies when server-managed token state is enabled either in gateway-site or at the topology level. + + + + + gateway.application.path.alias.token-generation + tokengen + + + + + + gateway.knox.admin.groups + admin + + + + + gateway.group.config.hadoop.security.group.mapping + org.apache.hadoop.security.LdapGroupsMapping + + + gateway.group.config.hadoop.security.group.mapping.ldap.bind.user + uid=guest,ou=people,dc=hadoop,dc=apache,dc=org + + + gateway.group.config.hadoop.security.group.mapping.ldap.bind.password + guest-password + + + gateway.group.config.hadoop.security.group.mapping.ldap.url + ldap://localhost:33389 + + + gateway.group.config.hadoop.security.group.mapping.ldap.base + + + + gateway.group.config.hadoop.security.group.mapping.ldap.search.filter.user + (&(|(objectclass=person)(objectclass=applicationProcess))(cn={0})) + + + gateway.group.config.hadoop.security.group.mapping.ldap.search.filter.group + (objectclass=groupOfNames) + + + gateway.group.config.hadoop.security.group.mapping.ldap.search.attr.member + member + + + gateway.group.config.hadoop.security.group.mapping.ldap.search.attr.group.name + cn + + + gateway.dispatch.whitelist.services + DATANODE,HBASEUI,HDFSUI,JOBHISTORYUI,NODEUI,YARNUI,knoxauth + The comma-delimited list of service roles for which the gateway.dispatch.whitelist should be applied. + + + gateway.dispatch.whitelist + ^https?:\/\/(localhost|127\.0\.0\.1|0:0:0:0:0:0:0:1|::1):[0-9].*$ + The whitelist to be applied for dispatches associated with the service roles specified by gateway.dispatch.whitelist.services. + If the value is DEFAULT, a domain-based whitelist will be derived from the Knox host. + + + gateway.xforwarded.header.context.append.servicename + LIVYSERVER + Add service name to x-forward-context header for the list of services defined above. + +