Remove sync AuthZ APIs

This commit is contained in:
Hao Kung 2015-07-20 16:36:25 -07:00
parent 5a2499eb22
commit 5bb5662e74
6 changed files with 2 additions and 98 deletions

View File

@ -58,55 +58,5 @@ namespace Microsoft.AspNet.Authorization
{
return service.AuthorizeAsync(user, resource: null, policyName: policyName);
}
/// <summary>
/// Checks if a user meets a specific requirement for the specified resource
/// </summary>
/// <param name="user"></param>
/// <param name="resource"></param>
/// <param name="requirement"></param>
/// <returns></returns>
public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, object resource, [NotNull] IAuthorizationRequirement requirement)
{
return service.Authorize(user, resource, new IAuthorizationRequirement[] { requirement });
}
/// <summary>
/// Checks if a user meets a specific authorization policy
/// </summary>
/// <param name="service">The authorization service.</param>
/// <param name="user">The user to check the policy against.</param>
/// <param name="resource">The resource the policy should be checked with.</param>
/// <param name="policy">The policy to check against a specific context.</param>
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, object resource, [NotNull] AuthorizationPolicy policy)
{
return service.Authorize(user, resource, policy.Requirements.ToArray());
}
/// <summary>
/// Checks if a user meets a specific authorization policy
/// </summary>
/// <param name="service">The authorization service.</param>
/// <param name="user">The user to check the policy against.</param>
/// <param name="policy">The policy to check against a specific context.</param>
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, [NotNull] AuthorizationPolicy policy)
{
return service.Authorize(user, resource: null, requirements: policy.Requirements.ToArray());
}
/// <summary>
/// Checks if a user meets a specific authorization policy
/// </summary>
/// <param name="service">The authorization service.</param>
/// <param name="user">The user to check the policy against.</param>
/// <param name="policyName">The name of the policy to check against a specific context.</param>
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
public static bool Authorize([NotNull] this IAuthorizationService service, ClaimsPrincipal user, [NotNull] string policyName)
{
return service.Authorize(user, resource: null, policyName: policyName);
}
}
}

View File

@ -21,25 +21,6 @@ namespace Microsoft.AspNet.Authorization
_options = options.Options;
}
public bool Authorize(ClaimsPrincipal user, object resource, string policyName)
{
var policy = _options.GetPolicy(policyName);
return (policy == null)
? false
: this.Authorize(user, resource, policy);
}
public bool Authorize(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements)
{
var authContext = new AuthorizationContext(requirements, user, resource);
foreach (var handler in _handlers)
{
handler.Handle(authContext);
//REVIEW: Do we want to consider short circuiting on failure
}
return authContext.HasSucceeded;
}
public async Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements)
{
var authContext = new AuthorizationContext(requirements, user, resource);

View File

@ -8,6 +8,5 @@ namespace Microsoft.AspNet.Authorization
public interface IAuthorizationHandler
{
Task HandleAsync(AuthorizationContext context);
void Handle(AuthorizationContext context);
}
}

View File

@ -22,15 +22,6 @@ namespace Microsoft.AspNet.Authorization
/// <returns></returns>
Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements);
/// <summary>
/// Checks if a user meets a specific set of requirements for the specified resource
/// </summary>
/// <param name="user"></param>
/// <param name="resource"></param>
/// <param name="requirements"></param>
/// <returns></returns>
bool Authorize(ClaimsPrincipal user, object resource, [NotNull] IEnumerable<IAuthorizationRequirement> requirements);
/// <summary>
/// Checks if a user meets a specific authorization policy
/// </summary>
@ -39,14 +30,5 @@ namespace Microsoft.AspNet.Authorization
/// <param name="policyName">The name of the policy to check against a specific context.</param>
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
Task<bool> AuthorizeAsync(ClaimsPrincipal user, object resource, [NotNull] string policyName);
/// <summary>
/// Checks if a user meets a specific authorization policy
/// </summary>
/// <param name="user">The user to check the policy against.</param>
/// <param name="resource">The resource the policy should be checked with.</param>
/// <param name="policyName">The name of the policy to check against a specific context.</param>
/// <returns><value>true</value> when the user fulfills the policy, <value>false</value> otherwise.</returns>
bool Authorize(ClaimsPrincipal user, object resource, [NotNull] string policyName);
}
}

View File

@ -15,13 +15,5 @@ namespace Microsoft.AspNet.Authorization
await handler.HandleAsync(context);
}
}
public void Handle(AuthorizationContext context)
{
foreach (var handler in context.Requirements.OfType<IAuthorizationHandler>())
{
handler.Handle(context);
}
}
}
}

View File

@ -831,7 +831,7 @@ namespace Microsoft.AspNet.Authorization.Test
}
[Fact]
public void CanAuthorizeWithDelegateRequirement()
public async Task CanAuthorizeWithDelegateRequirement()
{
var authorizationService = BuildAuthorizationService(services =>
{
@ -843,7 +843,7 @@ namespace Microsoft.AspNet.Authorization.Test
var user = new ClaimsPrincipal();
// Act
var allowed = authorizationService.Authorize(user, "Basic");
var allowed = await authorizationService.AuthorizeAsync(user, "Basic");
// Assert
Assert.True(allowed);