-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from dylanbeattie/master
Fixed bug whereby the presence of the Basic authorizer contributor wo…
- Loading branch information
Showing
10 changed files
with
143 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,5 @@ public void execution_is_allowed() | |
.ShouldBeTrue(); | ||
} | ||
} | ||
} | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
src/OpenRasta.Tests.Unit/Security/RequiresBasicAuthenticationInterceptor_Specification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Security.Principal; | ||
using Moq; | ||
using NUnit.Framework; | ||
using OpenRasta.Hosting.InMemory; | ||
using OpenRasta.OperationModel; | ||
using OpenRasta.Security; | ||
using OpenRasta.Testing; | ||
using OpenRasta.Web; | ||
|
||
namespace RequiresBasicAuthenticationInterceptor_Specification | ||
{ | ||
public class when_the_user_is_not_authenticated : context | ||
{ | ||
[Test] | ||
public void execution_is_denied() | ||
{ | ||
var context = new InMemoryCommunicationContext(); | ||
const string REALM = "Test Realm"; | ||
var authenticationInterceptor = new RequiresBasicAuthenticationInterceptor(context, REALM); | ||
authenticationInterceptor.BeforeExecute(new Mock<IOperation>().Object).ShouldBeFalse(); | ||
context.OperationResult.ShouldBeOfType<OperationResult.Unauthorized>(); | ||
var expectedHeader = String.Format("Basic realm=\"{0}\"", REALM); | ||
context.Response.Headers["WWW-Authenticate"].ShouldBe(expectedHeader); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/OpenRasta/Security/RequiresBasicAuthenticationAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#region License | ||
/* Authors: | ||
* Sebastien Lambla (seb@serialseb.com) | ||
* Copyright: | ||
* (C) 2007-2009 Caffeine IT & naughtyProd Ltd (http://www.caffeine-it.com) | ||
* License: | ||
* This file is distributed under the terms of the MIT License found at the end of this file. | ||
*/ | ||
#endregion | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using OpenRasta.DI; | ||
using OpenRasta.OperationModel; | ||
using OpenRasta.OperationModel.Interceptors; | ||
using OpenRasta.Web; | ||
|
||
namespace OpenRasta.Security | ||
{ | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)] | ||
public class RequiresBasicAuthenticationAttribute : InterceptorProviderAttribute | ||
{ | ||
private readonly string realm; | ||
|
||
public RequiresBasicAuthenticationAttribute(string realm) | ||
{ | ||
this.realm = realm; | ||
} | ||
|
||
public override IEnumerable<IOperationInterceptor> GetInterceptors(IOperation operation) | ||
{ | ||
return new[] | ||
{ | ||
new RequiresBasicAuthenticationInterceptor(DependencyManager.GetService<ICommunicationContext>(),realm) | ||
}; | ||
} | ||
} | ||
} | ||
|
||
#region Full license | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
#endregion |
25 changes: 25 additions & 0 deletions
25
src/OpenRasta/Security/RequiresBasicAuthenticationInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using OpenRasta.OperationModel; | ||
using OpenRasta.OperationModel.Interceptors; | ||
using OpenRasta.Pipeline; | ||
using OpenRasta.Web; | ||
|
||
namespace OpenRasta.Security | ||
{ | ||
public class RequiresBasicAuthenticationInterceptor : RequiresAuthenticationInterceptor | ||
{ | ||
private readonly string realm; | ||
|
||
public RequiresBasicAuthenticationInterceptor(ICommunicationContext context, string realm) | ||
: base(context) | ||
{ | ||
this.realm = realm; | ||
} | ||
|
||
protected override void DenyAuthorization(ICommunicationContext context) | ||
{ | ||
base.DenyAuthorization(context); | ||
var header = new BasicAuthenticationRequiredHeader(realm).ServerResponseHeader; | ||
context.Response.Headers["WWW-Authenticate"] = header; | ||
} | ||
} | ||
} |