qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject [1/2] qpid-proton-j git commit: PROTON-1606: Added ability to make SASL communication optional for CLIENT role
Date Fri, 06 Oct 2017 12:07:00 GMT
Repository: qpid-proton-j
Updated Branches:
  refs/heads/master 55a51e91a -> 1b858d4fc


PROTON-1606: Added ability to make SASL communication optional for CLIENT role

Previously, the IOhandler created to be the global handler automatically created the SASL
layer whether a user of the library wanted it or not. This commit exposes an option when creating
the reactor to disable creating the SASL layer at all.

https://issues.apache.org/jira/browse/PROTON-1606


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/commit/819e4c3a
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/tree/819e4c3a
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton-j/diff/819e4c3a

Branch: refs/heads/master
Commit: 819e4c3a468f5b0cd65625f86edca82f448468aa
Parents: 55a51e9
Author: timtay-microsoft <timtay@microsoft.com>
Authored: Thu Oct 5 11:40:28 2017 -0700
Committer: timtay-microsoft <timtay@microsoft.com>
Committed: Thu Oct 5 11:52:37 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/qpid/proton/Proton.java     | 15 ++++++
 .../org/apache/qpid/proton/ReactorOptions.java  | 52 ++++++++++++++++++++
 .../org/apache/qpid/proton/reactor/Reactor.java |  5 ++
 .../qpid/proton/reactor/impl/IOHandler.java     | 21 ++++++--
 .../qpid/proton/reactor/impl/ReactorImpl.java   | 12 ++++-
 5 files changed, 101 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/819e4c3a/proton-j/src/main/java/org/apache/qpid/proton/Proton.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/Proton.java b/proton-j/src/main/java/org/apache/qpid/proton/Proton.java
index b428736..f80cfee 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/Proton.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/Proton.java
@@ -106,4 +106,19 @@ public final class Proton
         }
         return reactor;
     }
+
+
+    public static Reactor reactor(ReactorOptions options) throws IOException
+    {
+        return Reactor.Factory.create(options);
+    }
+
+    public static Reactor reactor(ReactorOptions options, Handler... handlers) throws IOException
+    {
+        Reactor reactor = Reactor.Factory.create(options);
+        for (Handler handler : handlers) {
+            reactor.getHandler().add(handler);
+        }
+        return reactor;
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/819e4c3a/proton-j/src/main/java/org/apache/qpid/proton/ReactorOptions.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/ReactorOptions.java b/proton-j/src/main/java/org/apache/qpid/proton/ReactorOptions.java
new file mode 100644
index 0000000..bfe368d
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/ReactorOptions.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.qpid.proton;
+
+public class ReactorOptions {
+    private boolean isSaslCreatedByDefault;
+
+    public ReactorOptions() {
+        //Default case creates SASL
+        isSaslCreatedByDefault = true;
+    }
+
+    /**
+     * The default handlers will not create the SASL layer by default. They can still be
created by user later
+     */
+    public void disableSaslByDefault() {
+        this.isSaslCreatedByDefault = false;
+    }
+
+    /**
+     * The default handlers will create the SASL layer by default.
+     */
+    public void enableSaslByDefault() {
+        this.isSaslCreatedByDefault = true;
+    }
+
+    /**
+     * Returns If the SASL is created by default
+     * @return True if SASL will be created by default. False otherwise
+     */
+    public boolean isSaslCreatedByDefault() {
+        return this.isSaslCreatedByDefault;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/819e4c3a/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java b/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java
index f687bb3..86aeed5 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/reactor/Reactor.java
@@ -24,6 +24,7 @@ package org.apache.qpid.proton.reactor;
 import java.io.IOException;
 import java.util.Set;
 
+import org.apache.qpid.proton.ReactorOptions;
 import org.apache.qpid.proton.engine.BaseHandler;
 import org.apache.qpid.proton.engine.Collector;
 import org.apache.qpid.proton.engine.Connection;
@@ -51,6 +52,10 @@ public interface Reactor {
         public static Reactor create() throws IOException {
             return new ReactorImpl();
         }
+
+        public static Reactor create(ReactorOptions options) throws IOException {
+            return new ReactorImpl(options);
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/819e4c3a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java
index 1282083..d4373c8 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java
@@ -29,6 +29,7 @@ import java.nio.channels.SocketChannel;
 import java.util.Iterator;
 
 import org.apache.qpid.proton.Proton;
+import org.apache.qpid.proton.ReactorOptions;
 import org.apache.qpid.proton.amqp.Symbol;
 import org.apache.qpid.proton.amqp.transport.ErrorCondition;
 import org.apache.qpid.proton.engine.BaseHandler;
@@ -49,6 +50,16 @@ import org.apache.qpid.proton.reactor.impl.AcceptorImpl;
 @SuppressWarnings("deprecation")
 public class IOHandler extends BaseHandler {
 
+    private ReactorOptions options;
+
+    public IOHandler() {
+        this.options = new ReactorOptions();
+    }
+
+    public IOHandler(ReactorOptions options) {
+        this.options = options;
+    }
+
     // pni_handle_quiesced from connection.c
     private void handleQuiesced(Reactor reactor, Selector selector) throws IOException {
         // check if we are still quiesced, other handlers of
@@ -101,9 +112,13 @@ public class IOHandler extends BaseHandler {
             // setHostname set by application - use it.
         }
         Transport transport = Proton.transport();
-        Sasl sasl = transport.sasl();
-        sasl.client();
-        sasl.setMechanisms("ANONYMOUS");
+
+        if (this.options.isSaslCreatedByDefault()) {
+            Sasl sasl = transport.sasl();
+            sasl.client();
+            sasl.setMechanisms("ANONYMOUS");
+        }
+
         transport.bind(connection);
     }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/819e4c3a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java
index 9d38b85..b629dab 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/ReactorImpl.java
@@ -29,6 +29,7 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.qpid.proton.Proton;
+import org.apache.qpid.proton.ReactorOptions;
 import org.apache.qpid.proton.engine.BaseHandler;
 import org.apache.qpid.proton.engine.Collector;
 import org.apache.qpid.proton.engine.Connection;
@@ -98,8 +99,17 @@ public class ReactorImpl implements Reactor, Extendable {
         attachments = new RecordImpl();
     }
 
+    protected ReactorImpl(IO io, ReactorOptions options) throws IOException {
+        this(io);
+        global = new IOHandler(options);
+    }
+
     public ReactorImpl() throws IOException {
-        this(new IOImpl());
+        this(new IOImpl(), new ReactorOptions());
+    }
+
+    public ReactorImpl(ReactorOptions options) throws IOException {
+        this(new IOImpl(), options);
     }
 
     @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message