This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit b494c590260632f001ec328a89388b77fa50350e Author: marius cornescu <marius_corne...@yahoo.com> AuthorDate: Mon Sep 23 15:20:08 2019 +0200 CAMEL-13998 - code review (mistake in documentation) --- .../camel-hdfs/src/main/docs/hdfs-component.adoc | 3 +- .../apache/camel/component/hdfs/HdfsComponent.java | 23 ++++++++++ .../kerberos/HdfsKerberosConfigurationFactory.java | 50 ---------------------- .../hdfs/kerberos/KerberosConfiguration.java | 3 +- .../HdfsKerberosConfigurationFactoryTest.java | 40 ----------------- 5 files changed, 27 insertions(+), 92 deletions(-) diff --git a/components/camel-hdfs/src/main/docs/hdfs-component.adoc b/components/camel-hdfs/src/main/docs/hdfs-component.adoc index 3e8268b..8c2f73b 100644 --- a/components/camel-hdfs/src/main/docs/hdfs-component.adoc +++ b/components/camel-hdfs/src/main/docs/hdfs-component.adoc @@ -54,7 +54,7 @@ fileMode=Append to append each of the chunks together. // component options: START -The HDFS component supports 2 options, which are listed below. +The HDFS component supports 3 options, which are listed below. @@ -62,6 +62,7 @@ The HDFS component supports 2 options, which are listed below. |=== | Name | Description | Default | Type | *jAASConfiguration* (common) | To use the given configuration for security with JAAS. | | Configuration +| *kerberosConfigFile* (common) | To use kerberos authentication, set the value of the 'java.security.krb5.conf' environment variable to an existing file. If the environment variable is already set, warn if different than the specified parameter | | String | *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean |=== // component options: END diff --git a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsComponent.java b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsComponent.java index 1586ce7..07fe6b6 100644 --- a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsComponent.java +++ b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsComponent.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.hdfs; +import java.io.File; import java.net.URL; import java.util.Map; @@ -33,6 +34,8 @@ public class HdfsComponent extends DefaultComponent { private static final Logger LOG = LoggerFactory.getLogger(HdfsComponent.class); + private static final String KERBEROS_5_SYS_ENV = "java.security.krb5.conf"; + public HdfsComponent() { initHdfs(); } @@ -80,4 +83,24 @@ public class HdfsComponent extends DefaultComponent { } } + /** + * To use kerberos authentication, set the value of the 'java.security.krb5.conf' environment variable to an existing file. + * If the environment variable is already set, warn if different than the specified parameter + * + * @param kerberosConfigFileLocation - kerb5.conf file (https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html) + */ + public static void setKerberosConfigFile(String kerberosConfigFileLocation) { + if (!new File(kerberosConfigFileLocation).exists()) { + LOG.warn("Kerberos configuration file [{}}] could not be found.", kerberosConfigFileLocation); + return; + } + + String krb5Conf = System.getProperty(KERBEROS_5_SYS_ENV); + if (krb5Conf == null || !krb5Conf.isEmpty()) { + System.setProperty(KERBEROS_5_SYS_ENV, kerberosConfigFileLocation); + } else if (!krb5Conf.equalsIgnoreCase(kerberosConfigFileLocation)) { + LOG.warn("[{}] was already configured with: [{}] config file", KERBEROS_5_SYS_ENV, krb5Conf); + } + } + } diff --git a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/kerberos/HdfsKerberosConfigurationFactory.java b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/kerberos/HdfsKerberosConfigurationFactory.java deleted file mode 100644 index 00c9526..0000000 --- a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/kerberos/HdfsKerberosConfigurationFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.hdfs.kerberos; - -import java.io.File; -import java.io.FileNotFoundException; - -import static java.lang.String.format; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class HdfsKerberosConfigurationFactory { - - private static final Logger LOGGER = LoggerFactory.getLogger(HdfsKerberosConfigurationFactory.class); - - private static final String KERBEROS_5_SYS_ENV = "java.security.krb5.conf"; - - private HdfsKerberosConfigurationFactory() { - // factory class - } - - public static void setKerberosConfigFile(String kerberosConfigFileLocation) throws FileNotFoundException { - if (!new File(kerberosConfigFileLocation).exists()) { - throw new FileNotFoundException(format("KeyTab file [%s] could not be found.", kerberosConfigFileLocation)); - } - - String krb5Conf = System.getProperty(KERBEROS_5_SYS_ENV); - if (krb5Conf == null || !krb5Conf.isEmpty()) { - System.setProperty(KERBEROS_5_SYS_ENV, kerberosConfigFileLocation); - } else if (!krb5Conf.equalsIgnoreCase(kerberosConfigFileLocation)) { - LOGGER.warn("[{}] was already configured with: [{}] config file", KERBEROS_5_SYS_ENV, krb5Conf); - } - } - -} diff --git a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/kerberos/KerberosConfiguration.java b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/kerberos/KerberosConfiguration.java index 77982e1..209edb5 100644 --- a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/kerberos/KerberosConfiguration.java +++ b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/kerberos/KerberosConfiguration.java @@ -24,6 +24,7 @@ import java.util.stream.Collectors; import static java.lang.String.format; +import org.apache.camel.component.hdfs.HdfsComponent; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSUtil; @@ -62,7 +63,7 @@ public class KerberosConfiguration extends Configuration { String kerberosConfigFileLocation, int replicationFactor) throws IOException { - HdfsKerberosConfigurationFactory.setKerberosConfigFile(kerberosConfigFileLocation); + HdfsComponent.setKerberosConfigFile(kerberosConfigFileLocation); setupHdfsConfiguration(namedNodes, replicationFactor); } diff --git a/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/kerberos/HdfsKerberosConfigurationFactoryTest.java b/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/kerberos/HdfsKerberosConfigurationFactoryTest.java deleted file mode 100644 index ba65149..0000000 --- a/components/camel-hdfs/src/test/java/org/apache/camel/component/hdfs/kerberos/HdfsKerberosConfigurationFactoryTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.hdfs.kerberos; - -import java.io.FileNotFoundException; -import java.io.IOException; - -import org.junit.Test; - -public class HdfsKerberosConfigurationFactoryTest { - - @Test(expected = FileNotFoundException.class) - public void setupExistingKerberosConfigFileWithMissingConfigFile() throws IOException { - // given - String kerberosConfigFileLocation = "missing.conf"; - - // when - HdfsKerberosConfigurationFactory.setKerberosConfigFile(kerberosConfigFileLocation); - - // then - /* exception was thrown */ - } - - - -} \ No newline at end of file