Qpid
  1. Qpid
  2. QPID-3373

Java client: connectionFactory.createConnection method should not rewrite stored credentials

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.10
    • Fix Version/s: 0.14
    • Component/s: Java Client
    • Labels:
      None

      Description

      Method connectionFactory.createConnection("foo", "bar") causes than Java client caches the credentials and overwrites default ones provided in connection URL. Thus subsequent calling of connectionFactory.createConnection() method (without a parameter) results in using the credentials "foo" / "bar" despite default ones should be used.

      How reproducible:
      100%

      Steps to Reproduce:
      1. Setup a broker with PLAIN authentication
      2. Compile attached JUnit test
      3. Run it (java org.junit.runner.JUnitCore authNoCredentialsInSecondConnection)

      Actual results:
      In try .. catch block, connectionFactory2.createConnection(); does not raise an exception that authentication failed. (and thus fail command below raises java.lang.AssertionError exception). In fact, connectionFactory2.createConnection(); uses "guest" / "guest" credentials set for connectionFactory1.

      Expected results:
      Authentication fails for connectionFactory2.createConnection(); as it uses default credentials from URL (what is "dummy" / "dummy").

        Activity

        Hide
        Rajith Attapattu added a comment -

        Alex, I applied your patch and tested.
        The tests should be ok now.

        Show
        Rajith Attapattu added a comment - Alex, I applied your patch and tested. The tests should be ok now.
        Hide
        Alex Rudyy added a comment -

        Rajith,

        when test from ConnectionFactoryTest is run as part of any existing test profile it fails because broker port is not 5672.

        I would suggest to add the following change into ConnectionFactoryTest

        diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java b/qpid/java/systests/src/main/java/org/a
        index 0b9ef8c..d128c5d 100644
        --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java
        +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java
        @@ -13,7 +13,8 @@ public class ConnectionFactoryTest extends QpidBrokerTestCase
              */
             public void testCreateConnectionWithUsernamePassword() throws Exception
             {
        -        String URL = "amqp://guest:guest@clientID/test?brokerlist='tcp://localhost:5672'";
        +        String brokerUrl = getBroker().toString();
        +        String URL = "amqp://guest:guest@clientID/test?brokerlist='" + brokerUrl + "'";
                 AMQConnectionFactory factory = new AMQConnectionFactory(URL);
                 
                 AMQConnection con = (AMQConnection)factory.createConnection();
        
        

        With this change the test will pass on existing java profiles

        Alternatively, it can be excluded from all java test profiles.

        What do you think about it?

        Show
        Alex Rudyy added a comment - Rajith, when test from ConnectionFactoryTest is run as part of any existing test profile it fails because broker port is not 5672. I would suggest to add the following change into ConnectionFactoryTest diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java b/qpid/java/systests/src/main/java/org/a index 0b9ef8c..d128c5d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionFactoryTest.java @@ -13,7 +13,8 @@ public class ConnectionFactoryTest extends QpidBrokerTestCase */ public void testCreateConnectionWithUsernamePassword() throws Exception { - String URL = "amqp: //guest:guest@clientID/test?brokerlist='tcp://localhost:5672'" ; + String brokerUrl = getBroker().toString(); + String URL = "amqp: //guest:guest@clientID/test?brokerlist='" + brokerUrl + "'" ; AMQConnectionFactory factory = new AMQConnectionFactory(URL); AMQConnection con = (AMQConnection)factory.createConnection(); With this change the test will pass on existing java profiles Alternatively, it can be excluded from all java test profiles. What do you think about it?
        Hide
        Rajith Attapattu added a comment -

        Fixed with an automated test case.

        Show
        Rajith Attapattu added a comment - Fixed with an automated test case.
        Hide
        Pavel Moravec added a comment -

        patch proposal:
        1) have auxiliary connectionDetails interface derived from _connectionDetails and with the provided credentials
        2)call AMQConnection method with this interface instead.

        Show
        Pavel Moravec added a comment - patch proposal: 1) have auxiliary connectionDetails interface derived from _connectionDetails and with the provided credentials 2)call AMQConnection method with this interface instead.
        Hide
        Pavel Moravec added a comment -

        JUnit test case for reproduction

        Show
        Pavel Moravec added a comment - JUnit test case for reproduction

          People

          • Assignee:
            Rajith Attapattu
            Reporter:
            Pavel Moravec
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 2h
              2h
              Remaining:
              Remaining Estimate - 2h
              2h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development