Skip to content

Commit 3bb84f3

Browse files
author
Emile Joubert
committed
Report authentication failures as returned by the broker
1 parent 308c195 commit 3bb84f3

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 1.1.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (C) 2007-2013 GoPivotal, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// http://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v1.1:
23+
//
24+
//---------------------------------------------------------------------------
25+
// The contents of this file are subject to the Mozilla Public License
26+
// Version 1.1 (the "License"); you may not use this file except in
27+
// compliance with the License. You may obtain a copy of the License
28+
// at http://www.mozilla.org/MPL/
29+
//
30+
// Software distributed under the License is distributed on an "AS IS"
31+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32+
// the License for the specific language governing rights and
33+
// limitations under the License.
34+
//
35+
// The Original Code is RabbitMQ.
36+
//
37+
// The Initial Developer of the Original Code is GoPivotal, Inc.
38+
// Copyright (c) 2013-2013 GoPivotal, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
using System;
42+
43+
namespace RabbitMQ.Client.Exceptions
44+
{
45+
/// <summary> Thrown when the cause is an
46+
/// authentication failure. </summary>
47+
public class AuthenticationFailureException : Exception
48+
{
49+
public AuthenticationFailureException(String msg)
50+
: base(msg)
51+
{
52+
}
53+
}
54+
}

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,10 @@ protected void StartAndTune()
11141114
}
11151115
catch (OperationInterruptedException e)
11161116
{
1117+
if (e.ShutdownReason != null && e.ShutdownReason.ReplyCode == CommonFraming.Constants.AccessRefused)
1118+
{
1119+
throw new AuthenticationFailureException(e.ShutdownReason.ReplyText);
1120+
}
11171121
throw new PossibleAuthenticationFailureException(
11181122
"Possibly caused by authentication failure", e);
11191123
}

projects/client/RabbitMQ.Client/src/client/impl/v0_9_1/ProtocolBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public ProtocolBase() {
5151
Capabilities["basic.nack"] = true;
5252
Capabilities["consumer_cancel_notify"] = true;
5353
Capabilities["connection.blocked"] = true;
54+
Capabilities["authentication_failure_close"] = true;
5455
}
5556

5657
public override IFrameHandler CreateFrameHandler(AmqpTcpEndpoint endpoint,

projects/client/Unit/src/unit/TestAuth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void TestAuthFailure()
7272
{
7373
foreach (Object failureReason in bue.ConnectionErrors.Values)
7474
{
75-
Assert.IsInstanceOf<PossibleAuthenticationFailureException>(
75+
Assert.IsInstanceOf<AuthenticationFailureException>(
7676
failureReason);
7777
}
7878
}

0 commit comments

Comments
 (0)