From a0a4fd7f3dafadcfd635c725de914367529fd7b3 Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Wed, 6 Mar 2013 21:04:39 +0000 Subject: QPID-3396 Modified the URLParser to not throw an exception if the username and password is empty. Instead once a SASL mechanism is selected we check if that mechanism needs user/pass and then throw an exception at that point. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1453558 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/client/security/CallbackHandlerRegistry.java | 7 +++++++ .../apache/qpid/client/transport/ClientConnectionDelegate.java | 8 ++++++++ .../src/main/java/org/apache/qpid/client/url/URLParser.java | 6 +----- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to 'qpid/java/client') diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java b/qpid/java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java index 6b2448e385..ce6d9bdc50 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/security/CallbackHandlerRegistry.java @@ -27,6 +27,7 @@ import org.apache.qpid.util.FileUtils; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; @@ -80,6 +81,8 @@ public class CallbackHandlerRegistry /** Ordered collection of mechanisms for which callback handlers exist. */ private Collection _mechanisms; + private static final Collection MECHS_THAT_NEED_USERPASS = Arrays.asList(new String [] {"PLAIN", "AMQPLAIN", "CRAM-MD5","CRAM-MD5-HASHED"}); + static { // Register any configured SASL client factories. @@ -311,4 +314,8 @@ public class CallbackHandlerRegistry return Collections.unmodifiableSet(mechanismSet); } + public boolean isUserPassRequired(String selectedMech) + { + return MECHS_THAT_NEED_USERPASS.contains(selectedMech); + } } diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java b/qpid/java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java index 4789dd0ed7..2775354acf 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/transport/ClientConnectionDelegate.java @@ -98,6 +98,14 @@ public class ClientConnectionDelegate extends ClientDelegate " Client restricted itself to : " + (restrictionList != null ? restrictionList : "no restriction")); } + if (CallbackHandlerRegistry.getInstance().isUserPassRequired(selectedMech)) + { + throw new ConnectionException("Username and Password is required for the selected mechanism : " + selectedMech + + " Broker allows : " + brokerMechanisms + + " Client has : " + CallbackHandlerRegistry.getInstance().getMechanisms() + + " Client restricted itself to : " + (restrictionList != null ? restrictionList : "no restriction")); + } + Map saslProps = new HashMap(); if (getConnectionSettings().isUseSASLEncryption()) { diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java b/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java index 516ee8cf37..754b5ff6a7 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/url/URLParser.java @@ -106,11 +106,7 @@ public class URLParser } - if (userInfo == null) - { - throw URLHelper.parseError(AMQConnectionURL.AMQ_PROTOCOL.length() + 3, "User information not found on url", fullURL); - } - else + if (userInfo != null) { parseUserInfo(userInfo); } -- cgit v1.2.1