Moving interface members to extension methods
This commit is contained in:
parent
cf7ffe1a75
commit
d9502923f8
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Security
|
|||
/// <param name="claim">The claim to check against a specific user.</param>
|
||||
/// <param name="user">The user to check claims against.</param>
|
||||
/// <returns><value>true</value> when the user fulfills one of the claims, <value>false</value> otherwise.</returns>
|
||||
public static Task<bool> AuthorizeAsync(this IAuthorizationService service, Claim claim, ClaimsPrincipal user)
|
||||
public static Task<bool> AuthorizeAsync([NotNull] this IAuthorizationService service, Claim claim, ClaimsPrincipal user)
|
||||
{
|
||||
return service.AuthorizeAsync(new Claim[] { claim }, user);
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Security
|
|||
/// <param name="claim">The claim to check against a specific user.</param>
|
||||
/// <param name="user">The user to check claims against.</param>
|
||||
/// <returns><value>true</value> when the user fulfills one of the claims, <value>false</value> otherwise.</returns>
|
||||
public static bool Authorize(this IAuthorizationService service, Claim claim, ClaimsPrincipal user)
|
||||
public static bool Authorize([NotNull] this IAuthorizationService service, Claim claim, ClaimsPrincipal user)
|
||||
{
|
||||
return service.Authorize(new Claim[] { claim }, user);
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Security
|
|||
/// <param name="user">The user to check claims against.</param>
|
||||
/// <param name="resource">The resource the claims should be check with.</param>
|
||||
/// <returns><value>true</value> when the user fulfills one of the claims, <value>false</value> otherwise.</returns>
|
||||
public static Task<bool> AuthorizeAsync(this IAuthorizationService service, Claim claim, ClaimsPrincipal user, object resource)
|
||||
public static Task<bool> AuthorizeAsync([NotNull] this IAuthorizationService service, Claim claim, ClaimsPrincipal user, object resource)
|
||||
{
|
||||
return service.AuthorizeAsync(new Claim[] { claim }, user, resource);
|
||||
}
|
||||
|
|
@ -52,9 +52,31 @@ namespace Microsoft.AspNet.Security
|
|||
/// <param name="user">The user to check claims against.</param>
|
||||
/// <param name="resource">The resource the claims should be check with.</param>
|
||||
/// <returns><value>true</value> when the user fulfills one of the claims, <value>false</value> otherwise.</returns>
|
||||
public static bool Authorize(this IAuthorizationService service, Claim claim, ClaimsPrincipal user, object resource)
|
||||
public static bool Authorize([NotNull] this IAuthorizationService service, Claim claim, ClaimsPrincipal user, object resource)
|
||||
{
|
||||
return service.Authorize(new Claim[] { claim }, user, resource);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user has specific claims.
|
||||
/// </summary>
|
||||
/// <param name="claims">The claims to check against a specific user.</param>
|
||||
/// <param name="user">The user to check claims against.</param>
|
||||
/// <returns><value>true</value> when the user fulfills one of the claims, <value>false</value> otherwise.</returns>
|
||||
public static Task<bool> AuthorizeAsync([NotNull] this IAuthorizationService service, IEnumerable<Claim> claims, ClaimsPrincipal user)
|
||||
{
|
||||
return service.AuthorizeAsync(claims, user, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user has specific claims.
|
||||
/// </summary>
|
||||
/// <param name="claims">The claims to check against a specific user.</param>
|
||||
/// <param name="user">The user to check claims against.</param>
|
||||
/// <returns><value>true</value> when the user fulfills one of the claims, <value>false</value> otherwise.</returns>
|
||||
public static bool Authorize([NotNull] this IAuthorizationService service, IEnumerable<Claim> claims, ClaimsPrincipal user)
|
||||
{
|
||||
return service.Authorize(claims, user, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,16 +26,6 @@ namespace Microsoft.AspNet.Security
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<bool> AuthorizeAsync(IEnumerable<Claim> claims, ClaimsPrincipal user)
|
||||
{
|
||||
return await AuthorizeAsync(claims, user, null);
|
||||
}
|
||||
|
||||
public bool Authorize(IEnumerable<Claim> claims, ClaimsPrincipal user)
|
||||
{
|
||||
return AuthorizeAsync(claims, user, null).Result;
|
||||
}
|
||||
|
||||
public async Task<bool> AuthorizeAsync(IEnumerable<Claim> claims, ClaimsPrincipal user, object resource)
|
||||
{
|
||||
var context = new AuthorizationPolicyContext(claims, user, resource);
|
||||
|
|
|
|||
|
|
@ -12,22 +12,6 @@ namespace Microsoft.AspNet.Security
|
|||
/// </summary>
|
||||
public interface IAuthorizationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if a user has specific claims.
|
||||
/// </summary>
|
||||
/// <param name="claims">The claims to check against a specific user.</param>
|
||||
/// <param name="user">The user to check claims against.</param>
|
||||
/// <returns><value>true</value> when the user fulfills one of the claims, <value>false</value> otherwise.</returns>
|
||||
Task<bool> AuthorizeAsync(IEnumerable<Claim> claims, ClaimsPrincipal user);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user has specific claims.
|
||||
/// </summary>
|
||||
/// <param name="claims">The claims to check against a specific user.</param>
|
||||
/// <param name="user">The user to check claims against.</param>
|
||||
/// <returns><value>true</value> when the user fulfills one of the claims, <value>false</value> otherwise.</returns>
|
||||
bool Authorize(IEnumerable<Claim> claims, ClaimsPrincipal user);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a user has specific claims for a specific context obj.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ namespace Microsoft.AspNet.Security.Test
|
|||
var authorizationService = new DefaultAuthorizationService(policies);
|
||||
|
||||
// Act
|
||||
var allowed = authorizationService.Authorize(null, null);
|
||||
var allowed = authorizationService.Authorize(Enumerable.Empty<Claim>(), null);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("-12030", result);
|
||||
|
|
@ -200,7 +200,7 @@ namespace Microsoft.AspNet.Security.Test
|
|||
var authorizationService = new DefaultAuthorizationService(policies);
|
||||
|
||||
// Act
|
||||
var allowed = authorizationService.Authorize(null, null);
|
||||
var allowed = authorizationService.Authorize(Enumerable.Empty<Claim>(), null);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Applying-1Applying20Applying30Apply-1Apply20Apply30Applied-1Applied20Applied30", result);
|
||||
|
|
@ -221,7 +221,7 @@ namespace Microsoft.AspNet.Security.Test
|
|||
var authorizationService = new DefaultAuthorizationService(policies);
|
||||
|
||||
// Act
|
||||
var allowed = authorizationService.Authorize(null, null);
|
||||
var allowed = authorizationService.Authorize(Enumerable.Empty<Claim>(), null);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(claims);
|
||||
|
|
@ -242,7 +242,7 @@ namespace Microsoft.AspNet.Security.Test
|
|||
|
||||
// Act
|
||||
// Assert
|
||||
Exception ex = Assert.Throws<AggregateException>(() => authorizationService.Authorize(null, null));
|
||||
Exception ex = Assert.Throws<AggregateException>(() => authorizationService.Authorize(Enumerable.Empty<Claim>(), null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in New Issue