Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 33F53F4AA for ; Fri, 10 May 2013 13:43:54 +0000 (UTC) Received: (qmail 86525 invoked by uid 500); 10 May 2013 13:43:54 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 86469 invoked by uid 500); 10 May 2013 13:43:54 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 86459 invoked by uid 99); 10 May 2013 13:43:53 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 May 2013 13:43:53 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 73CF288B3DF; Fri, 10 May 2013 13:43:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Fri, 10 May 2013 13:43:53 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: CAMEL-6348: Fixed getting and restoring JAAS Configuration if non existed. Thanks to David Arthur for the patch. Updated Branches: refs/heads/camel-2.10.x f7697b6ef -> 69dac4300 refs/heads/camel-2.11.x fa7dd10f3 -> 9e709b24c CAMEL-6348: Fixed getting and restoring JAAS Configuration if non existed. Thanks to David Arthur for the patch. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9e709b24 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9e709b24 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9e709b24 Branch: refs/heads/camel-2.11.x Commit: 9e709b24cb8a4d75cfa0b16f5b2fe59b24187ad5 Parents: fa7dd10 Author: Claus Ibsen Authored: Fri May 10 15:42:51 2013 +0200 Committer: Claus Ibsen Committed: Fri May 10 15:43:16 2013 +0200 ---------------------------------------------------------------------- .../apache/camel/component/hdfs/HdfsComponent.java | 25 +++++++++++++++ .../apache/camel/component/hdfs/HdfsConsumer.java | 8 +--- .../camel/component/hdfs/HdfsInfoFactory.java | 8 +--- .../apache/camel/component/hdfs/HdfsProducer.java | 16 ++------- 4 files changed, 33 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9e709b24/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsComponent.java ---------------------------------------------------------------------- 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 76baa99..1920e1c 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 @@ -18,6 +18,7 @@ package org.apache.camel.component.hdfs; import java.net.URL; import java.util.Map; +import javax.security.auth.login.Configuration; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; @@ -54,4 +55,28 @@ public class HdfsComponent extends DefaultComponent { } } + static Configuration getJAASConfiguration() { + Configuration auth = null; + try { + auth = Configuration.getConfiguration(); + LOG.trace("Existing JAAS Configuration {}", auth); + } catch (SecurityException e) { + LOG.trace("Cannot load existing JAAS configuration", e); + } + return auth; + } + + static void setJAASConfiguration(Configuration auth) { + if (auth != null) { + LOG.trace("Restoring existing JAAS Configuration {}", auth); + try { + Configuration.setConfiguration(auth); + } catch (SecurityException e) { + LOG.trace("Cannot restore JAAS Configuration. This exception is ignored.", e); + } + } else { + LOG.trace("No JAAS Configuration to restore"); + } + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/9e709b24/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsConsumer.java b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsConsumer.java index 8a6e0ba..b24a9ea 100644 --- a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsConsumer.java +++ b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsConsumer.java @@ -93,15 +93,11 @@ public final class HdfsConsumer extends ScheduledPollConsumer { @Override protected int poll() throws Exception { // need to remember auth as Hadoop will override that, which otherwise means the Auth is broken afterwards - Configuration auth = Configuration.getConfiguration(); - log.trace("Existing JAAS Configuration {}", auth); + Configuration auth = HdfsComponent.getJAASConfiguration(); try { return doPoll(); } finally { - if (auth != null) { - log.trace("Restoring existing JAAS Configuration {}", auth); - Configuration.setConfiguration(auth); - } + HdfsComponent.setJAASConfiguration(auth); } } http://git-wip-us.apache.org/repos/asf/camel/blob/9e709b24/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsInfoFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsInfoFactory.java b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsInfoFactory.java index 0766ea3..9511c64 100644 --- a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsInfoFactory.java +++ b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsInfoFactory.java @@ -31,15 +31,11 @@ public final class HdfsInfoFactory { public static HdfsInfo newHdfsInfo(String hdfsPath) throws IOException { // need to remember auth as Hadoop will override that, which otherwise means the Auth is broken afterwards - Configuration auth = Configuration.getConfiguration(); - LOG.trace("Existing JAAS Configuration {}", auth); + Configuration auth = HdfsComponent.getJAASConfiguration(); try { return new HdfsInfo(hdfsPath); } finally { - if (auth != null) { - LOG.trace("Restoring existing JAAS Configuration {}", auth); - Configuration.setConfiguration(auth); - } + HdfsComponent.setJAASConfiguration(auth); } } http://git-wip-us.apache.org/repos/asf/camel/blob/9e709b24/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsProducer.java b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsProducer.java index 7e7d195..2c3c0f5 100644 --- a/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsProducer.java +++ b/components/camel-hdfs/src/main/java/org/apache/camel/component/hdfs/HdfsProducer.java @@ -94,8 +94,7 @@ public class HdfsProducer extends DefaultProducer { @Override protected void doStart() throws Exception { // need to remember auth as Hadoop will override that, which otherwise means the Auth is broken afterwards - Configuration auth = Configuration.getConfiguration(); - log.trace("Existing JAAS Configuration {}", auth); + Configuration auth = HdfsComponent.getJAASConfiguration(); try { super.doStart(); @@ -117,10 +116,7 @@ public class HdfsProducer extends DefaultProducer { scheduler.scheduleAtFixedRate(new IdleCheck(idleStrategy), config.getCheckIdleInterval(), config.getCheckIdleInterval(), TimeUnit.MILLISECONDS); } } finally { - if (auth != null) { - log.trace("Restoring existing JAAS Configuration {}", auth); - Configuration.setConfiguration(auth); - } + HdfsComponent.setJAASConfiguration(auth); } } @@ -172,15 +168,11 @@ public class HdfsProducer extends DefaultProducer { @Override public void process(Exchange exchange) throws Exception { // need to remember auth as Hadoop will override that, which otherwise means the Auth is broken afterwards - Configuration auth = Configuration.getConfiguration(); - log.trace("Existing JAAS Configuration {}", auth); + Configuration auth = HdfsComponent.getJAASConfiguration(); try { doProcess(exchange); } finally { - if (auth != null) { - log.trace("Restoring existing JAAS Configuration {}", auth); - Configuration.setConfiguration(auth); - } + HdfsComponent.setJAASConfiguration(auth); } }