camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject svn commit: r790952 - in /camel/trunk/components/camel-irc/src/main: java/org/apache/camel/component/irc/ resources/META-INF/services/org/apache/camel/component/
Date Fri, 03 Jul 2009 15:54:27 GMT
Author: janstey
Date: Fri Jul  3 15:54:27 2009
New Revision: 790952

URL: http://svn.apache.org/viewvc?rev=790952&view=rev
Log:
CAMEL-1787 - Add SSL support to camel-irc. Thanks to Stan Lewis for this.

Added:
    camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/ircs
Modified:
    camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
    camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
    camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java

Modified: camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java?rev=790952&r1=790951&r2=790952&view=diff
==============================================================================
--- camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
(original)
+++ camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
Fri Jul  3 15:54:27 2009
@@ -27,6 +27,9 @@
 import org.apache.commons.logging.LogFactory;
 import org.schwering.irc.lib.IRCConnection;
 
+import org.schwering.irc.lib.ssl.SSLIRCConnection;
+import org.schwering.irc.lib.ssl.SSLTrustManager;
+
 /**
  * Defines the <a href="http://camel.apache.org/irc.html">IRC Component</a>
  *
@@ -75,13 +78,35 @@
     }
 
     protected IRCConnection createConnection(IrcConfiguration configuration) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Creating Connection to " + configuration.getHostname() + " destination:
" + configuration.getTarget()
-                    + " nick: " + configuration.getNickname() + " user: " + configuration.getUsername());
-        }
+        IRCConnection conn = null;
+
+        if ( configuration.getUsingSSL() ) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Creating SSL Connection to " + configuration.getHostname() + "
destination: " + configuration.getTarget()
+                        + " nick: " + configuration.getNickname() + " user: " + configuration.getUsername());
+            }
+            SSLIRCConnection sconn = new SSLIRCConnection(configuration.getHostname(), configuration.getPorts(),
configuration.getPassword(),
+                                                         configuration.getNickname(), configuration.getUsername(),
configuration.getRealname());
+            try {
+                configuration.setTrustManager((SSLTrustManager)Class.forName(configuration.getTrustManagerClass()).newInstance());
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Using trust manager: " + configuration.getTrustManager().getClass().getName());
+                }
+            } catch (Exception e) {
+                LOG.warn("Using default trust manager: " + configuration.getTrustManager().getClass().getName());
+            }
+            sconn.addTrustManager(configuration.getTrustManager());
+            conn = sconn;
 
-        final IRCConnection conn = new IRCConnection(configuration.getHostname(), configuration.getPorts(),
configuration.getPassword(),
-                                                     configuration.getNickname(), configuration.getUsername(),
configuration.getRealname());
+        } else {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Creating Connection to " + configuration.getHostname() + " destination:
" + configuration.getTarget()
+                        + " nick: " + configuration.getNickname() + " user: " + configuration.getUsername());
+            }
+
+            conn = new IRCConnection(configuration.getHostname(), configuration.getPorts(),
configuration.getPassword(),
+                                                         configuration.getNickname(), configuration.getUsername(),
configuration.getRealname());
+        }
         conn.setEncoding("UTF-8");
         conn.setColors(configuration.isColors());
         conn.setPong(true);

Modified: camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java?rev=790952&r1=790951&r2=790952&view=diff
==============================================================================
--- camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
(original)
+++ camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
Fri Jul  3 15:54:27 2009
@@ -22,6 +22,9 @@
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.ObjectHelper;
 
+import org.schwering.irc.lib.ssl.SSLTrustManager;
+import org.schwering.irc.lib.ssl.SSLDefaultTrustManager;
+
 public class IrcConfiguration implements Cloneable {
     private String target;
     private String hostname;
@@ -29,6 +32,9 @@
     private String nickname;
     private String realname;
     private String username;
+    private String trustManagerClass;
+    private SSLTrustManager trustManager;
+    private boolean usingSSL = false;
     private boolean persistent = true;
     private boolean colors = true;
     private boolean onNick = true;
@@ -77,11 +83,17 @@
         // fix provided URI and handle that we can use # to indicate the IRC room
 
         String fixedUri = uri.toString();
-        if (!fixedUri.startsWith("irc://")) {
+
+        if (fixedUri.startsWith("ircs://")) {
+            setUsingSSL(true);
+            setTrustManager(new SSLDefaultTrustManager());
+            setTrustManagerClass(getTrustManager().getClass().getName());
+        } else if (!fixedUri.startsWith("irc://")) {
             fixedUri = fixedUri.replace("irc:", "irc://");
-            uri = uri.resolve(fixedUri);
         }
 
+        uri = uri.resolve(fixedUri);
+
         setNickname(uri.getUserInfo());
         setUsername(uri.getUserInfo());
         setRealname(uri.getUserInfo());
@@ -99,7 +111,35 @@
         }
 
         setTarget("#" + channel);
-}
+    }
+
+    public void setTrustManagerClass(String trustManagerClass)
+    {
+        this.trustManagerClass = trustManagerClass;
+    }
+
+    public String getTrustManagerClass()
+    {
+        return trustManagerClass;
+    }
+
+    public void setTrustManager(SSLTrustManager trustManager)
+    {
+        this.trustManager = trustManager;
+    }
+
+    public SSLTrustManager getTrustManager()
+    {
+        return trustManager;
+    }
+
+    public boolean getUsingSSL() {
+        return usingSSL;
+    }
+
+    private void setUsingSSL(boolean usingSSL) {
+        this.usingSSL = usingSSL;
+    }
 
     public String getHostname() {
         return hostname;

Modified: camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java?rev=790952&r1=790951&r2=790952&view=diff
==============================================================================
--- camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
(original)
+++ camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
Fri Jul  3 15:54:27 2009
@@ -28,7 +28,7 @@
 
 public class IrcConsumer extends DefaultConsumer {
     private static final transient Log LOG = LogFactory.getLog(IrcConsumer.class);
-    
+
     private final IrcConfiguration configuration;
     private final IrcEndpoint endpoint;
     private final IRCConnection connection;
@@ -60,7 +60,7 @@
         connection.addIRCEventListener(listener);
 
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Joining: " + target);
+            LOG.debug("Joining: " + target + " using " + connection.getClass().getName());
         }
         connection.doJoin(target);
     }

Added: camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/ircs
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/ircs?rev=790952&view=auto
==============================================================================
--- camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/ircs
(added)
+++ camel/trunk/components/camel-irc/src/main/resources/META-INF/services/org/apache/camel/component/ircs
Fri Jul  3 15:54:27 2009
@@ -0,0 +1,17 @@
+# 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.
+#
+
+class=org.apache.camel.component.irc.IrcComponent



Mime
View raw message