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/69dac430
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/69dac430
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/69dac430

Branch: refs/heads/camel-2.10.x
Commit: 69dac43004c3bf4871f83863fadaf8987f21d432
Parents: f7697b6
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri May 10 15:42:51 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri May 10 15:43:36 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/69dac430/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/69dac430/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/69dac430/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/69dac430/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 19f6306..14b1d96 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);
         }
     }
 

Reply via email to