Skip to content

Commit e831f34

Browse files
author
Emile Joubert
committed
Make auth failure an IO exception to avoid incompatibility
1 parent b58b828 commit e831f34

24 files changed

+58
-110
lines changed

src/com/rabbitmq/client/AuthenticationFailureException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Thrown when the broker refuses access due to an authentication failure.
2121
*/
2222

23-
public class AuthenticationFailureException extends Exception
23+
public class AuthenticationFailureException extends PossibleAuthenticationFailureException
2424
{
2525
public AuthenticationFailureException(String reason) {
2626
super(reason);

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ protected void configureSocket(Socket socket) throws IOException{
484484
* @return an interface to the connection
485485
* @throws IOException if it encounters a problem
486486
*/
487-
public Connection newConnection(Address[] addrs) throws IOException, AuthenticationFailureException {
487+
public Connection newConnection(Address[] addrs) throws IOException {
488488
return newConnection(null, addrs);
489489
}
490490

@@ -494,10 +494,10 @@ public Connection newConnection(Address[] addrs) throws IOException, Authenticat
494494
* @param addrs an array of known broker addresses (hostname/port pairs) to try in order
495495
* @return an interface to the connection
496496
* @throws IOException if it encounters a problem
497-
* @throws AuthenticationFailureException if the login fails
498497
*/
499498
public Connection newConnection(ExecutorService executor, Address[] addrs)
500-
throws IOException, AuthenticationFailureException {
499+
throws IOException
500+
{
501501
IOException lastException = null;
502502
for (Address addr : addrs) {
503503
try {
@@ -528,9 +528,8 @@ public Connection newConnection(ExecutorService executor, Address[] addrs)
528528
* Create a new broker connection
529529
* @return an interface to the connection
530530
* @throws IOException if it encounters a problem
531-
* @throws AuthenticationFailureException if the login fails
532531
*/
533-
public Connection newConnection() throws IOException, AuthenticationFailureException {
532+
public Connection newConnection() throws IOException {
534533
return newConnection(null,
535534
new Address[] {new Address(getHost(), getPort())}
536535
);
@@ -541,9 +540,8 @@ public Connection newConnection() throws IOException, AuthenticationFailureExcep
541540
* @param executor thread execution service for consumers on the connection
542541
* @return an interface to the connection
543542
* @throws IOException if it encounters a problem
544-
* @throws AuthenticationFailureException if the login fails
545543
*/
546-
public Connection newConnection(ExecutorService executor) throws IOException, AuthenticationFailureException {
544+
public Connection newConnection(ExecutorService executor) throws IOException {
547545
return newConnection(executor,
548546
new Address[] {new Address(getHost(), getPort())}
549547
);

src/com/rabbitmq/client/PossibleAuthenticationFailureException.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import java.io.IOException;
2020

2121
/**
22-
* Thrown when the likely cause is an authentication failure and the broker
23-
* communicates this by closing the connection.
22+
* Thrown when the likely cause is an authentication failure.
2423
*/
2524
public class PossibleAuthenticationFailureException extends IOException
2625
{
@@ -32,4 +31,9 @@ public PossibleAuthenticationFailureException(Throwable cause)
3231
super("Possibly caused by authentication failure");
3332
super.initCause(cause);
3433
}
34+
35+
public PossibleAuthenticationFailureException(String reason)
36+
{
37+
super(reason);
38+
}
3539
}

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,16 @@ public AMQConnection(String username,
279279
* and frame max values after tuning has taken place.
280280
* @throws IOException if an error is encountered
281281
* either before, or during, protocol negotiation;
282-
* @throws AuthenticationFailureException if the broker closes the
283-
* connection with ACCESS_REFUSED.
284282
* sub-classes {@link ProtocolVersionMismatchException} and
285283
* {@link PossibleAuthenticationFailureException} will be thrown in the
286-
* corresponding circumstances. If an exception is thrown, connection
287-
* resources allocated can all be garbage collected when the connection
288-
* object is no longer referenced.
284+
* corresponding circumstances. {@link AuthenticationFailureException}
285+
* will be thrown if the broker closes the connection with ACCESS_REFUSED.
286+
* If an exception is thrown, connection resources allocated can all be
287+
* garbage collected when the connection object is no longer referenced.
289288
*/
290289
public void start()
291-
throws IOException, AuthenticationFailureException {
290+
throws IOException
291+
{
292292
this._running = true;
293293
// Make sure that the first thing we do is to send the header,
294294
// which should cause any socket errors to show up for us, rather

test/src/com/rabbitmq/client/test/AMQConnectionTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import junit.framework.TestCase;
2929
import junit.framework.TestSuite;
3030

31-
import com.rabbitmq.client.AuthenticationFailureException;
3231
import com.rabbitmq.client.Channel;
3332
import com.rabbitmq.client.Connection;
3433
import com.rabbitmq.client.ConnectionFactory;
@@ -82,7 +81,7 @@ public static TestSuite suite() {
8281
/** Check the AMQConnection does send exactly 1 initial header, and deal correctly with
8382
* the frame handler throwing an exception when we try to read data
8483
*/
85-
public void testConnectionSendsSingleHeaderAndTimesOut() throws AuthenticationFailureException {
84+
public void testConnectionSendsSingleHeaderAndTimesOut() {
8685
IOException exception = new SocketTimeoutException();
8786
_mockFrameHandler.setExceptionOnReadingFrames(exception);
8887
MyExceptionHandler handler = new MyExceptionHandler();
@@ -125,7 +124,7 @@ public void testConnectionSendsSingleHeaderAndTimesOut() throws AuthenticationFa
125124
/**
126125
* Test that we catch timeout between connect and negotiation of the connection being finished.
127126
*/
128-
public void testConnectionHangInNegotiation() throws AuthenticationFailureException {
127+
public void testConnectionHangInNegotiation() {
129128
this._mockFrameHandler.setTimeoutCount(10); // to limit hang
130129
MyExceptionHandler handler = new MyExceptionHandler();
131130
assertEquals(0, this._mockFrameHandler.countHeadersSent());

test/src/com/rabbitmq/client/test/BrokerTestCase.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.rabbitmq.client.Method;
3131
import com.rabbitmq.client.ShutdownSignalException;
3232
import com.rabbitmq.client.AlreadyClosedException;
33-
import com.rabbitmq.client.AuthenticationFailureException;
3433
import com.rabbitmq.client.impl.ShutdownNotifierComponent;
3534
import com.rabbitmq.client.AMQP;
3635
import com.rabbitmq.tools.Host;
@@ -82,7 +81,7 @@ protected void releaseResources()
8281
}
8382

8483
protected void restart()
85-
throws IOException, AuthenticationFailureException {
84+
throws IOException {
8685
tearDown();
8786
bareRestart();
8887
setUp();
@@ -96,11 +95,7 @@ protected void bareRestart()
9695
public void openConnection()
9796
throws IOException {
9897
if (connection == null) {
99-
try {
100-
connection = connectionFactory.newConnection();
101-
} catch (AuthenticationFailureException afe) {
102-
fail("Unexpected authentication failure");
103-
}
98+
connection = connectionFactory.newConnection();
10499
}
105100
}
106101

test/src/com/rabbitmq/client/test/functional/ClusteredTestBase.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.rabbitmq.client.test.functional;
1818

1919
import com.rabbitmq.client.AMQP;
20-
import com.rabbitmq.client.AuthenticationFailureException;
2120
import com.rabbitmq.client.Channel;
2221
import com.rabbitmq.client.Connection;
2322
import com.rabbitmq.client.ConnectionFactory;
@@ -64,9 +63,6 @@ public void openConnection() throws IOException {
6463
catch (IOException e) {
6564
// Must be no secondary node
6665
}
67-
catch (AuthenticationFailureException afe) {
68-
fail("Unexpected authentication failure");
69-
}
7066
}
7167

7268
if (clusteredConnection != null &&

test/src/com/rabbitmq/client/test/functional/ConnectionOpen.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.net.Socket;
2323

2424
import com.rabbitmq.client.AMQP;
25-
import com.rabbitmq.client.AuthenticationFailureException;
2625
import com.rabbitmq.client.MalformedFrameException;
2726
import com.rabbitmq.client.Method;
2827
import com.rabbitmq.client.impl.SocketFrameHandler;
@@ -86,7 +85,7 @@ public void testCrazyProtocolHeader() throws IOException {
8685
}
8786
}
8887

89-
public void testFrameMaxLessThanFrameMinSize() throws IOException, AuthenticationFailureException {
88+
public void testFrameMaxLessThanFrameMinSize() throws IOException {
9089
ConnectionFactory factory = new ConnectionFactory();
9190
factory.setRequestedFrameMax(100);
9291
try {

test/src/com/rabbitmq/client/test/functional/FrameMax.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.concurrent.ExecutorService;
2525

2626
import com.rabbitmq.client.Address;
27-
import com.rabbitmq.client.AuthenticationFailureException;
2827
import com.rabbitmq.client.AMQP;
2928
import com.rabbitmq.client.Connection;
3029
import com.rabbitmq.client.ConnectionFactory;
@@ -72,7 +71,7 @@ public void testFrameSizes()
7271
/* server should reject frames larger than AMQP.FRAME_MIN_SIZE
7372
* during connection negotiation */
7473
public void testRejectLargeFramesDuringConnectionNegotiation()
75-
throws IOException, AuthenticationFailureException
74+
throws IOException
7675
{
7776
ConnectionFactory cf = new ConnectionFactory();
7877
cf.getClientProperties().put("too_long", LongStringHelper.asLongString(new byte[AMQP.FRAME_MIN_SIZE]));
@@ -86,7 +85,7 @@ public void testRejectLargeFramesDuringConnectionNegotiation()
8685
/* server should reject frames larger than the negotiated frame
8786
* size */
8887
public void testRejectExceedingFrameMax()
89-
throws IOException, AuthenticationFailureException
88+
throws IOException
9089
{
9190
closeChannel();
9291
closeConnection();
@@ -162,7 +161,7 @@ public GenerousAMQConnection(ConnectionFactory factory,
162161
private static class GenerousConnectionFactory extends ConnectionFactory {
163162

164163
@Override public Connection newConnection(ExecutorService executor, Address[] addrs)
165-
throws IOException, AuthenticationFailureException
164+
throws IOException
166165
{
167166
IOException lastException = null;
168167
for (Address addr : addrs) {

test/src/com/rabbitmq/client/test/functional/QueueExclusivity.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.HashMap;
2222

2323
import com.rabbitmq.client.AMQP;
24-
import com.rabbitmq.client.AuthenticationFailureException;
2524
import com.rabbitmq.client.Channel;
2625
import com.rabbitmq.client.Connection;
2726
import com.rabbitmq.client.QueueingConsumer;
@@ -37,11 +36,7 @@ public class QueueExclusivity extends BrokerTestCase {
3736
String q = "exclusiveQ";
3837

3938
protected void createResources() throws IOException {
40-
try {
41-
altConnection = connectionFactory.newConnection();
42-
} catch (AuthenticationFailureException afe) {
43-
fail("Unexpected authentication failure");
44-
}
39+
altConnection = connectionFactory.newConnection();
4540
altChannel = altConnection.createChannel();
4641
altChannel.queueDeclare(q,
4742
// not durable, exclusive, not auto-delete

0 commit comments

Comments
 (0)