You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2015/05/29 18:05:23 UTC
qpid-proton git commit: PROTON-518: add setter and getter for using
the sasl hostname field
Repository: qpid-proton
Updated Branches:
refs/heads/master 8c86c6f36 -> 485b23d50
PROTON-518: add setter and getter for using the sasl hostname field
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/485b23d5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/485b23d5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/485b23d5
Branch: refs/heads/master
Commit: 485b23d5009302a35988f9d5fc55ca0217db0bf0
Parents: 8c86c6f
Author: Robert Gemmell <ro...@apache.org>
Authored: Fri May 29 17:02:08 2015 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Fri May 29 17:02:45 2015 +0100
----------------------------------------------------------------------
.../org/apache/qpid/proton/engine/Sasl.java | 13 +++
.../qpid/proton/engine/impl/SaslImpl.java | 22 ++++
.../qpid/proton/systemtests/SaslTest.java | 100 +++++++++++++++++++
3 files changed, 135 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/485b23d5/proton-j/src/main/java/org/apache/qpid/proton/engine/Sasl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/Sasl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/Sasl.java
index dd63321..16043b9 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/Sasl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/Sasl.java
@@ -97,6 +97,19 @@ public interface Sasl
String[] getRemoteMechanisms();
/**
+ * Set the remote hostname to indicate the host being connected to when
+ * sending a SaslInit to the server.
+ */
+ void setRemoteHostname(String hostname);
+
+ /**
+ * Retrieve the hostname indicated by the client when sending its SaslInit.
+ *
+ * @return the hostname indicated by the remote client, or null if none specified.
+ */
+ String getHostname();
+
+ /**
* Determine the size of the bytes available via recv().
*
* Returns the size in bytes available via recv().
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/485b23d5/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SaslImpl.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SaslImpl.java b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SaslImpl.java
index ed8891e..053c21f 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SaslImpl.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/SaslImpl.java
@@ -704,4 +704,26 @@ public class SaslImpl implements Sasl, SaslFrameBody.SaslFrameBodyHandler<Void>,
_underlyingOutput.close_head();
}
}
+
+ @Override
+ public String getHostname()
+ {
+ if(_role != null)
+ {
+ checkRole(Role.SERVER);
+ }
+
+ return _hostname;
+ }
+
+ @Override
+ public void setRemoteHostname(String hostname)
+ {
+ if(_role != null)
+ {
+ checkRole(Role.CLIENT);
+ }
+
+ _hostname = hostname;
+ }
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/485b23d5/proton-j/src/test/java/org/apache/qpid/proton/systemtests/SaslTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/systemtests/SaslTest.java b/proton-j/src/test/java/org/apache/qpid/proton/systemtests/SaslTest.java
new file mode 100644
index 0000000..2980565
--- /dev/null
+++ b/proton-j/src/test/java/org/apache/qpid/proton/systemtests/SaslTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.systemtests;
+
+import static org.apache.qpid.proton.systemtests.TestLoggingHelper.bold;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.logging.Logger;
+
+import org.apache.qpid.proton.Proton;
+import org.apache.qpid.proton.engine.Sasl;
+import org.junit.Test;
+
+public class SaslTest extends EngineTestBase
+{
+ private static final Logger LOGGER = Logger.getLogger(SaslTest.class.getName());
+
+ @Test
+ public void testSaslHostnamePropagationAndRetrieval() throws Exception
+ {
+ LOGGER.fine(bold("======== About to create transports"));
+
+ getClient().transport = Proton.transport();
+ ProtocolTracerEnabler.setProtocolTracer(getClient().transport, TestLoggingHelper.CLIENT_PREFIX);
+
+ Sasl clientSasl = getClient().transport.sasl();
+ clientSasl.client();
+
+ // Set the server hostname we are connecting to from the client
+ String hostname = "my-remote-host-123";
+ clientSasl.setRemoteHostname(hostname);
+
+ // Verify we can't get the hostname on the client
+ try
+ {
+ clientSasl.getHostname();
+ fail("should have throw IllegalStateException");
+ }
+ catch (IllegalStateException ise)
+ {
+ // expected
+ }
+
+ getServer().transport = Proton.transport();
+ ProtocolTracerEnabler.setProtocolTracer(getServer().transport, " " + TestLoggingHelper.SERVER_PREFIX);
+
+ // Configure the server to do ANONYMOUS
+ Sasl serverSasl = getServer().transport.sasl();
+ serverSasl.server();
+ serverSasl.setMechanisms("ANONYMOUS");
+
+ // Verify we can't set the hostname on the server
+ try
+ {
+ serverSasl.setRemoteHostname("some-other-host");
+ fail("should have throw IllegalStateException");
+ }
+ catch (IllegalStateException ise)
+ {
+ // expected
+ }
+
+ assertNull(serverSasl.getHostname());
+ assertArrayEquals(new String[0], clientSasl.getRemoteMechanisms());
+
+ pumpClientToServer();
+ pumpServerToClient();
+
+ // Verify we got the mechs, set the chosen mech, and verify the
+ // server still doesnt know the hostname set/requested by the client
+ assertArrayEquals(new String[] {"ANONYMOUS"} , clientSasl.getRemoteMechanisms());
+ clientSasl.setMechanisms("ANONYMOUS");
+ assertNull(serverSasl.getHostname());
+
+ pumpClientToServer();
+
+ // Verify the server now knows that the client set the hostname field
+ assertEquals(hostname, serverSasl.getHostname());
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org