Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit e2a8efb

Browse files
committed
Cleanup
Switch to logging interfaces reference Tweak DenyAnonymous logic Fixes #181 Fixes #169
1 parent 7abccd8 commit e2a8efb

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

src/Microsoft.AspNet.Authentication/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Microsoft.AspNet.RequestContainer": "1.0.0-*",
77
"Microsoft.AspNet.Http.Interfaces": "1.0.0-*",
88
"Microsoft.AspNet.Http.Core": "1.0.0-*",
9-
"Microsoft.Framework.Logging": "1.0.0-*",
9+
"Microsoft.Framework.Logging.Interfaces": "1.0.0-*",
1010
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }
1111
},
1212
"frameworks": {

src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ public DefaultAuthorizationService(IOptions<AuthorizationOptions> options, IEnum
2323
public bool Authorize(ClaimsPrincipal user, object resource, string policyName)
2424
{
2525
var policy = _options.GetPolicy(policyName);
26-
if (policy == null)
27-
{
28-
return false;
29-
}
30-
return this.Authorize(user, resource, policy);
26+
return (policy == null)
27+
? false
28+
: this.Authorize(user, resource, policy);
3129
}
3230

3331
public bool Authorize(ClaimsPrincipal user, object resource, params IAuthorizationRequirement[] requirements)
@@ -53,11 +51,9 @@ public async Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, pa
5351
public Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, string policyName)
5452
{
5553
var policy = _options.GetPolicy(policyName);
56-
if (policy == null)
57-
{
58-
return Task.FromResult(false);
59-
}
60-
return this.AuthorizeAsync(user, resource, policy);
54+
return (policy == null)
55+
? Task.FromResult(false)
56+
: this.AuthorizeAsync(user, resource, policy);
6157
}
6258
}
6359
}

src/Microsoft.AspNet.Authorization/DenyAnonymousAuthorizationHandler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System.Threading.Tasks;
4+
using System.Linq;
55

66
namespace Microsoft.AspNet.Authorization
77
{
@@ -11,9 +11,8 @@ public override void Handle(AuthorizationContext context, DenyAnonymousAuthoriza
1111
{
1212
var user = context.User;
1313
var userIsAnonymous =
14-
user == null ||
15-
user.Identity == null ||
16-
!user.Identity.IsAuthenticated;
14+
user?.Identity == null ||
15+
!user.Identities.Any(i => i.IsAuthenticated);
1716
if (!userIsAnonymous)
1817
{
1918
context.Succeed(requirement);

src/Microsoft.AspNet.Authorization/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "ASP.NET 5 authorization classes.",
44
"dependencies": {
55
"Microsoft.AspNet.Http.Interfaces": "1.0.0-*",
6-
"Microsoft.Framework.Logging": "1.0.0-*",
6+
"Microsoft.Framework.Logging.Interfaces": "1.0.0-*",
77
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" },
88
"Microsoft.Framework.OptionsModel": "1.0.0-*"
99
},

test/Microsoft.AspNet.Authorization.Test/DefaultAuthorizationServiceTests.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,12 @@ public async Task CanApproveAnyAuthenticatedUser()
549549
options.AddPolicy("Any", policy => policy.RequireAuthenticatedUser());
550550
});
551551
});
552-
var user = new ClaimsPrincipal(
553-
new ClaimsIdentity(
554-
new Claim[] {
555-
new Claim(ClaimTypes.Name, "Name"),
556-
},
557-
"AuthType")
558-
);
552+
var user = new ClaimsPrincipal(new ClaimsIdentity());
553+
user.AddIdentity(new ClaimsIdentity(
554+
new Claim[] {
555+
new Claim(ClaimTypes.Name, "Name"),
556+
},
557+
"AuthType"));
559558

560559
// Act
561560
var allowed = await authorizationService.AuthorizeAsync(user, null, "Any");

0 commit comments

Comments
 (0)