You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by to...@apache.org on 2007/05/14 01:08:41 UTC
svn commit: r537676 - in /incubator/qpid/trunk/qpid: ./
dotnet/Qpid.Client.Tests/Security/ dotnet/Qpid.Client.Tests/connection/
dotnet/Qpid.Client/Client/ dotnet/Qpid.Client/Client/Configuration/
dotnet/Qpid.Client/Client/Handler/ dotnet/Qpid.Client/Cl...
Author: tomasr
Date: Sun May 13 16:08:40 2007
New Revision: 537676
URL: http://svn.apache.org/viewvc?view=rev&rev=537676
Log:
Merged revisions 537673 via svnmerge from
https://svn.apache.org/repos/asf/incubator/qpid/branches/M2
........
r537673 | tomasr | 2007-05-13 18:03:30 -0500 (Sun, 13 May 2007) | 3 lines
* QPID-486 Choose strongest SASL Mechanism first
* Remove unnecessary wrapping of AMQExceptions on connection failure
........
Modified:
incubator/qpid/trunk/qpid/ (props changed)
incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs
incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/AMQConnection.cs
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Configuration/AuthenticationConfigurationSectionHandler.cs
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Handler/ConnectionStartMethodHandler.cs
incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs
incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl.Tests/SaslTests.cs
incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs
Propchange: incubator/qpid/trunk/qpid/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs?view=diff&rev=537676&r1=537675&r2=537676
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs Sun May 13 16:08:40 2007
@@ -39,6 +39,17 @@
Assert.IsNotNull(handlerType);
Assert.AreEqual(typeof(TestCallbackHandler), handlerType);
}
+
+ [Test]
+ public void MechanimsInOrder()
+ {
+ CallbackHandlerRegistry registry = CallbackHandlerRegistry.Instance;
+ Assert.AreEqual(4, registry.Mechanisms.Length);
+ Assert.AreEqual("TEST", registry.Mechanisms[0]);
+ Assert.AreEqual("EXTERNAL", registry.Mechanisms[1]);
+ Assert.AreEqual("CRAM-MD5", registry.Mechanisms[2]);
+ Assert.AreEqual("PLAIN", registry.Mechanisms[3]);
+ }
} // class CallbackRegistryHandlerTests
public class TestCallbackHandler : IAMQCallbackHandler
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs?view=diff&rev=537676&r1=537675&r2=537676
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Client.Tests/connection/ConnectionTest.cs Sun May 13 16:08:40 2007
@@ -28,12 +28,15 @@
[TestFixture]
public class ConnectionTest
{
+ private AmqBrokerInfo _broker =
+ new AmqBrokerInfo("amqp", "localhost", 5672, false);
+
[Test]
public void SimpleConnection()
{
IConnectionInfo connectionInfo = new QpidConnectionInfo();
connectionInfo.VirtualHost = "test";
- connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 5672, false));
+ connectionInfo.AddBrokerInfo(_broker);
using (IConnection connection = new AMQConnection(connectionInfo))
{
Console.WriteLine("connection = " + connection);
@@ -41,62 +44,29 @@
}
[Test]
+ [ExpectedException(typeof(AMQAuthenticationException))]
public void PasswordFailureConnection()
{
IConnectionInfo connectionInfo = new QpidConnectionInfo();
connectionInfo.VirtualHost = "test";
connectionInfo.Password = "rubbish";
- connectionInfo.AddBrokerInfo(new AmqBrokerInfo());
- try
- {
- using (IConnection connection = new AMQConnection(connectionInfo))
- {
- Console.WriteLine("connection = " + connection);
- // wrong
- Assert.Fail("Authentication succeeded but should've failed");
- }
- }
- catch (AMQException e)
+ connectionInfo.AddBrokerInfo(_broker);
+
+ using (IConnection connection = new AMQConnection(connectionInfo))
{
- if (!(e.InnerException is AMQAuthenticationException))
- {
- Assert.Fail("Expected AMQAuthenticationException!");
- }
- }
+ Console.WriteLine("connection = " + connection);
+ // wrong
+ Assert.Fail("Authentication succeeded but should've failed");
+ }
+ }
+
+ [Test]
+ [ExpectedException(typeof(AMQConnectionException))]
+ public void connectionFailure()
+ {
+ string url = "amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5673?retries='0''";
+ new AMQConnection(QpidConnectionInfo.FromUrl(url));
+ Assert.Fail("Connection should not be established");
}
-//
-// [Test]
-// public void connectionFailure()
-// {
-// try
-// {
-// new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5673?retries='0''");
-// Assert.fail("Connection should not be established");
-// }
-// catch (AMQException amqe)
-// {
-// if (!(amqe instanceof AMQConnectionException))
-// {
-// Assert.fail("Correct exception not thrown");
-// }
-// }
-// }
-//
-// [Test]
-// public void unresolvedHostFailure()
-// {
-// try
-// {
-// new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://rubbishhost:5672?retries='0''");
-// Assert.fail("Connection should not be established");
-// }
-// catch (AMQException amqe)
-// {
-// if (!(amqe instanceof AMQUnresolvedAddressException))
-// {
-// Assert.fail("Correct exception not thrown");
-// }
-// }
-// }
}
}
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/AMQConnection.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/AMQConnection.cs?view=diff&rev=537676&r1=537675&r2=537676
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/AMQConnection.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/AMQConnection.cs Sun May 13 16:08:40 2007
@@ -157,7 +157,10 @@
if (!_failoverPolicy.FailoverAllowed())
{
- throw new AMQConnectionException("Unable to connect", lastException);
+ if ( lastException is AMQException )
+ throw lastException;
+ else
+ throw new AMQConnectionException("Unable to connect", lastException);
}
// TODO: this needs to be redone so that we are not spinning.
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Configuration/AuthenticationConfigurationSectionHandler.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Configuration/AuthenticationConfigurationSectionHandler.cs?view=diff&rev=537676&r1=537675&r2=537676
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Configuration/AuthenticationConfigurationSectionHandler.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Configuration/AuthenticationConfigurationSectionHandler.cs Sun May 13 16:08:40 2007
@@ -37,7 +37,7 @@
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
NameValueSectionHandler handler = new NameValueSectionHandler();
- IDictionary schemes = new Hashtable();
+ OrderedHashTable schemes = new OrderedHashTable();
NameValueCollection options = (NameValueCollection)
handler.Create(parent, configContext, section);
@@ -52,7 +52,7 @@
if ( !typeof(IAMQCallbackHandler).IsAssignableFrom(type) )
throw new ConfigurationException(string.Format("Type '{0}' does not implement IAMQCallbackHandler", key));
- schemes[key] = type;
+ schemes.Add(key, type);
}
}
@@ -61,4 +61,24 @@
} // class AuthenticationConfigurationSectionHandler
+ public class OrderedHashTable : Hashtable
+ {
+ private ArrayList _keys = new ArrayList();
+
+ public IList OrderedKeys
+ {
+ get { return _keys; }
+ }
+
+ public override void Add(object key, object value)
+ {
+ base.Add(key, value);
+ _keys.Add(key);
+ }
+ public override void Remove(object key)
+ {
+ base.Remove(key);
+ _keys.Remove(key);
+ }
+ }
} // namespace Qpid.Client.Configuration
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Handler/ConnectionStartMethodHandler.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Handler/ConnectionStartMethodHandler.cs?view=diff&rev=537676&r1=537675&r2=537676
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Handler/ConnectionStartMethodHandler.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Handler/ConnectionStartMethodHandler.cs Sun May 13 16:08:40 2007
@@ -103,14 +103,7 @@
private string ChooseMechanism(string mechanisms)
{
- foreach ( string mech in mechanisms.Split(' ') )
- {
- if ( CallbackHandlerRegistry.Instance.IsSupportedMechanism(mech) )
- {
- return mech;
- }
- }
- return null;
+ return CallbackHandlerRegistry.Instance.ChooseMechanism(mechanisms);
}
private byte[] DoAuthentication(string selectedMechanism, AMQProtocolSession ps)
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs?view=diff&rev=537676&r1=537675&r2=537676
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Client/Client/Security/CallbackHandlerRegistry.cs Sun May 13 16:08:40 2007
@@ -70,7 +70,7 @@
{
private static CallbackHandlerRegistry _instance =
new CallbackHandlerRegistry();
- private IDictionary _mechanism2HandlerMap;
+ private OrderedHashTable _mechanism2HandlerMap;
private string[] _mechanisms;
public static CallbackHandlerRegistry Instance
@@ -85,12 +85,12 @@
private CallbackHandlerRegistry()
{
- _mechanism2HandlerMap = (IDictionary)
+ _mechanism2HandlerMap = (OrderedHashTable)
ConfigurationSettings.GetConfig("qpid.client/authentication");
// configure default options if not available
if ( _mechanism2HandlerMap == null )
- _mechanism2HandlerMap = new Hashtable();
+ _mechanism2HandlerMap = new OrderedHashTable();
if ( !_mechanism2HandlerMap.Contains(ExternalSaslClient.Mechanism) )
_mechanism2HandlerMap.Add(ExternalSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler));
@@ -99,13 +99,24 @@
if ( !_mechanism2HandlerMap.Contains(PlainSaslClient.Mechanism) )
_mechanism2HandlerMap.Add(PlainSaslClient.Mechanism, typeof(UsernamePasswordCallbackHandler));
- _mechanisms = new string[_mechanism2HandlerMap.Keys.Count];
- _mechanism2HandlerMap.Keys.CopyTo(_mechanisms, 0);
+ _mechanisms = new string[_mechanism2HandlerMap.Count];
+ _mechanism2HandlerMap.OrderedKeys.CopyTo(_mechanisms, 0);
}
public bool IsSupportedMechanism(string mechanism)
{
return _mechanism2HandlerMap.Contains(mechanism);
+ }
+
+ public string ChooseMechanism(string mechanisms)
+ {
+ IList mechs = mechanisms.Split(' ');
+ foreach ( string supportedMech in _mechanisms )
+ {
+ if ( mechs.Contains(supportedMech) )
+ return supportedMech;
+ }
+ return null;
}
public Type GetCallbackHandler(string mechanism)
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl.Tests/SaslTests.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl.Tests/SaslTests.cs?view=diff&rev=537676&r1=537675&r2=537676
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl.Tests/SaslTests.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl.Tests/SaslTests.cs Sun May 13 16:08:40 2007
@@ -112,6 +112,17 @@
Assert.IsInstanceOfType(typeof(TestSaslClient), client);
}
+ [Test]
+ public void ChoosesStrongerMechanism()
+ {
+ Hashtable props = new Hashtable();
+ string[] mechanisms = new string[] { "PLAIN", "OTHER", "CRAM-MD5" };
+ ISaslClient client = Sasl.CreateClient(mechanisms, "", "", "", props, this);
+
+ Assert.IsNotNull(client);
+ Assert.IsInstanceOfType(typeof(CramMD5SaslClient), client);
+ }
+
void ISaslCallbackHandler.Handle(ISaslCallback[] callbacks)
{
Modified: incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs?view=diff&rev=537676&r1=537675&r2=537676
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/Qpid.Sasl/DefaultClientFactory.cs Sun May 13 16:08:40 2007
@@ -74,22 +74,17 @@
IDictionary props, ISaslCallbackHandler handler
)
{
- foreach ( string mech in mechanisms )
- {
- switch ( mech )
- {
- case PlainSaslClient.Mechanism:
- return new PlainSaslClient(authorizationId, props, handler);
- case CramMD5SaslClient.Mechanism:
- return new CramMD5SaslClient(authorizationId, props, handler);
- case AnonymousSaslClient.Mechanism:
- return new AnonymousSaslClient(authorizationId, props, handler);
- case DigestSaslClient.Mechanism:
- return new DigestSaslClient(authorizationId, serverName, protocol, props, handler);
- case ExternalSaslClient.Mechanism:
- return new ExternalSaslClient(authorizationId, props, handler);
- }
- }
+ IList mechs = mechanisms;
+ if ( mechs.Contains(ExternalSaslClient.Mechanism) )
+ return new ExternalSaslClient(authorizationId, props, handler);
+ if ( mechs.Contains(DigestSaslClient.Mechanism) )
+ return new DigestSaslClient(authorizationId, serverName, protocol, props, handler);
+ if ( mechs.Contains(CramMD5SaslClient.Mechanism) )
+ return new CramMD5SaslClient(authorizationId, props, handler);
+ if ( mechs.Contains(PlainSaslClient.Mechanism) )
+ return new PlainSaslClient(authorizationId, props, handler);
+ if ( mechs.Contains(AnonymousSaslClient.Mechanism) )
+ return new AnonymousSaslClient(authorizationId, props, handler);
// unknown mechanism
return null;
}