This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 599
/
AuthorizationFailure.cs
46 lines (39 loc) · 1.91 KB
/
AuthorizationFailure.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Security.Claims;
namespace Microsoft.AspNetCore.Authorization
{
/// <summary>
/// Encapsulates a failure result of <see cref="IAuthorizationService.AuthorizeAsync(ClaimsPrincipal, object, IEnumerable{IAuthorizationRequirement})"/>.
/// </summary>
public class AuthorizationFailure
{
private AuthorizationFailure() { }
/// <summary>
/// Failure was due to <see cref="AuthorizationHandlerContext.Fail"/> being called.
/// </summary>
public bool FailCalled { get; private set; }
/// <summary>
/// Failure was due to these requirements not being met via <see cref="AuthorizationHandlerContext.Succeed(IAuthorizationRequirement)"/>.
/// </summary>
public IEnumerable<IAuthorizationRequirement> FailedRequirements { get; private set; }
/// <summary>
/// Return a failure due to <see cref="AuthorizationHandlerContext.Fail"/> being called.
/// </summary>
/// <returns>The failure.</returns>
public static AuthorizationFailure ExplicitFail()
=> new AuthorizationFailure
{
FailCalled = true,
FailedRequirements = new IAuthorizationRequirement[0]
};
/// <summary>
/// Return a failure due to some requirements not being met via <see cref="AuthorizationHandlerContext.Succeed(IAuthorizationRequirement)"/>.
/// </summary>
/// <param name="failed">The requirements that were not met.</param>
/// <returns>The failure.</returns>
public static AuthorizationFailure Failed(IEnumerable<IAuthorizationRequirement> failed)
=> new AuthorizationFailure { FailedRequirements = failed };
}
}