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

Commit 5bb5662

Browse files
committed
Remove sync AuthZ APIs
1 parent 5a2499e commit 5bb5662

File tree

6 files changed

+2
-98
lines changed

6 files changed

+2
-98
lines changed

src/Microsoft.AspNet.Authorization/AuthorizationServiceExtensions.cs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -58,55 +58,5 @@ public static Task<bool> AuthorizeAsync([NotNull] this IAuthorizationService ser
5858
{
5959
return service.AuthorizeAsync(user, resource: null, policyName: policyName);
6060
}
61-
62-
/// <summary>
63-
/// Checks if a user meets a specific requirement for the specified resource
64-
/// </summary>
65-
/// <param name="user"></param>
66-
/// <param name="resource"></param>
67-
/// <param name="requirement"></param>
68-
/// <returns></returns>
69-
public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, object resource, [NotNull] IAuthorizationRequirement requirement)
70-
{
71-
return service.Authorize(user, resource, new IAuthorizationRequirement[] { requirement });
72-
}
73-
74-
/// <summary>
75-
/// Checks if a user meets a specific authorization policy
76-
/// </summary>
77-
/// <param name="service">The authorization service.</param>
78-
/// <param name="user">The user to check the policy against.</param>
79-
/// <param name="resource">The resource the policy should be checked with.</param>
80-
/// <param name="policy">The policy to check against a specific context.</param>
81-
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
82-
public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, object resource, [NotNull] AuthorizationPolicy policy)
83-
{
84-
return service.Authorize(user, resource, policy.Requirements.ToArray());
85-
}
86-
87-
/// <summary>
88-
/// Checks if a user meets a specific authorization policy
89-
/// </summary>
90-
/// <param name="service">The authorization service.</param>
91-
/// <param name="user">The user to check the policy against.</param>
92-
/// <param name="policy">The policy to check against a specific context.</param>
93-
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
94-
public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, [NotNull] AuthorizationPolicy policy)
95-
{
96-
return service.Authorize(user, resource: null, requirements: policy.Requirements.ToArray());
97-
}
98-
99-
/// <summary>
100-
/// Checks if a user meets a specific authorization policy
101-
/// </summary>
102-
/// <param name="service">The authorization service.</param>
103-
/// <param name="user">The user to check the policy against.</param>
104-
/// <param name="policyName">The name of the policy to check against a specific context.</param>
105-
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
106-
public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, [NotNull] string policyName)
107-
{
108-
return service.Authorize(user, resource: null, policyName: policyName);
109-
}
110-
11161
}
11262
}

src/Microsoft.AspNet.Authorization/DefaultAuthorizationService.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@ public DefaultAuthorizationService(IOptions<AuthorizationOptions> options, IEnum
2121
_options = options.Options;
2222
}
2323

24-
public bool Authorize(ClaimsPrincipal user, object resource, string policyName)
25-
{
26-
var policy = _options.GetPolicy(policyName);
27-
return (policy == null)
28-
? false
29-
: this.Authorize(user, resource, policy);
30-
}
31-
32-
public bool Authorize(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements)
33-
{
34-
var authContext = new AuthorizationContext(requirements, user, resource);
35-
foreach (var handler in _handlers)
36-
{
37-
handler.Handle(authContext);
38-
//REVIEW: Do we want to consider short circuiting on failure
39-
}
40-
return authContext.HasSucceeded;
41-
}
42-
4324
public async Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements)
4425
{
4526
var authContext = new AuthorizationContext(requirements, user, resource);

src/Microsoft.AspNet.Authorization/IAuthorizationHandler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ namespace Microsoft.AspNet.Authorization
88
public interface IAuthorizationHandler
99
{
1010
Task HandleAsync(AuthorizationContext context);
11-
void Handle(AuthorizationContext context);
1211
}
1312
}

src/Microsoft.AspNet.Authorization/IAuthorizationService.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ public interface IAuthorizationService
2222
/// <returns></returns>
2323
Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements);
2424

25-
/// <summary>
26-
/// Checks if a user meets a specific set of requirements for the specified resource
27-
/// </summary>
28-
/// <param name="user"></param>
29-
/// <param name="resource"></param>
30-
/// <param name="requirements"></param>
31-
/// <returns></returns>
32-
bool Authorize(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements);
33-
3425
/// <summary>
3526
/// Checks if a user meets a specific authorization policy
3627
/// </summary>
@@ -39,14 +30,5 @@ public interface IAuthorizationService
3930
/// <param name="policyName">The name of the policy to check against a specific context.</param>
4031
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
4132
Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, [NotNull] string policyName);
42-
43-
/// <summary>
44-
/// Checks if a user meets a specific authorization policy
45-
/// </summary>
46-
/// <param name="user">The user to check the policy against.</param>
47-
/// <param name="resource">The resource the policy should be checked with.</param>
48-
/// <param name="policyName">The name of the policy to check against a specific context.</param>
49-
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
50-
bool Authorize(ClaimsPrincipal user, object resource, [NotNull] string policyName);
5133
}
5234
}

src/Microsoft.AspNet.Authorization/PassThroughAuthorizationHandler.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,5 @@ public async Task HandleAsync(AuthorizationContext context)
1515
await handler.HandleAsync(context);
1616
}
1717
}
18-
19-
public void Handle(AuthorizationContext context)
20-
{
21-
foreach (var handler in context.Requirements.OfType<IAuthorizationHandler>())
22-
{
23-
handler.Handle(context);
24-
}
25-
}
2618
}
2719
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ public async Task CanAuthorizeOnlyAllowedOperations()
831831
}
832832

833833
[Fact]
834-
public void CanAuthorizeWithDelegateRequirement()
834+
public async Task CanAuthorizeWithDelegateRequirement()
835835
{
836836
var authorizationService = BuildAuthorizationService(services =>
837837
{
@@ -843,7 +843,7 @@ public void CanAuthorizeWithDelegateRequirement()
843843
var user = new ClaimsPrincipal();
844844

845845
// Act
846-
var allowed = authorizationService.Authorize(user, "Basic");
846+
var allowed = await authorizationService.AuthorizeAsync(user, "Basic");
847847

848848
// Assert
849849
Assert.True(allowed);

0 commit comments

Comments
 (0)