mirror of https://github.com/abpframework/abp.git
12 changed files with 162 additions and 45 deletions
@ -0,0 +1,15 @@ |
|||||
|
namespace Volo.Abp.Authorization |
||||
|
{ |
||||
|
public static class AbpAuthorizationErrorCodes |
||||
|
{ |
||||
|
public const string GivenPolicyHasNotGranted = "Volo.Authorization:010001"; |
||||
|
|
||||
|
public const string GivenPolicyHasNotGrantedWithPolicyName = "Volo.Authorization:010002"; |
||||
|
|
||||
|
public const string GivenPolicyHasNotGrantedForGivenResource = "Volo.Authorization:010003"; |
||||
|
|
||||
|
public const string GivenRequirementHasNotGrantedForGivenResource = "Volo.Authorization:010004"; |
||||
|
|
||||
|
public const string GivenRequirementsHasNotGrantedForGivenResource = "Volo.Authorization:010005"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Volo.Abp.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.Authorization.Localization |
||||
|
{ |
||||
|
[LocalizationResourceName("AbpAuthorization")] |
||||
|
public class AbpAuthorizationResource |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"Volo.Authorization:010001": "Authorization failed! Given policy has not granted.", |
||||
|
"Volo.Authorization:010002": "Authorization failed! Given policy has not granted: {PolicyName}", |
||||
|
"Volo.Authorization:010003": "Authorization failed! Given policy has not granted for given resource: {ResourceName}", |
||||
|
"Volo.Authorization:010004": "Authorization failed! Given requirement has not granted for given resource: {ResourceName}", |
||||
|
"Volo.Authorization:010005": "Authorization failed! Given requirements has not granted for given resource: {ResourceName}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"culture": "tr", |
||||
|
"texts": { |
||||
|
"Volo.Authorization:010001": "Yetkilendirme başarısız oldu! Verilen politika verilmemiştir.", |
||||
|
"Volo.Authorization:010002": "Yetkilendirme başarısız oldu! Verilen politika vermedi: {PolicyName}", |
||||
|
"Volo.Authorization:010003": "Yetkilendirme başarısız oldu! Verilen politika, verilen kaynak için verilmemiştir: {ResourceName}", |
||||
|
"Volo.Authorization:010004": "Yetkilendirme başarısız oldu! Belirtilen kaynak için verilen şart verilmedi {ResourceName}", |
||||
|
"Volo.Authorization:010005": "Yetkilendirme başarısız oldu! Verilen gereksinimler, verilen kaynak için verilmemiştir: {ResourceName}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"culture": "zh-Hans", |
||||
|
"texts": { |
||||
|
"Volo.Authorization:010001": "授权失败! 提供的策略尚未授予.", |
||||
|
"Volo.Authorization:010002": "授权失败! 提供的策略尚未授予: {PolicyName}", |
||||
|
"Volo.Authorization:010003": "授权失败! 提供的策略未授予提供的资源: {ResourceName}", |
||||
|
"Volo.Authorization:010004": "授权失败! 提供的要求未授予提供的资源: {ResourceName}", |
||||
|
"Volo.Authorization:010005": "授权失败! 提供的要求未授予提供的资源: {ResourceName}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.ExceptionHandling; |
||||
|
using Volo.Abp.Authorization; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Microsoft.AspNetCore.Authorization |
||||
|
{ |
||||
|
public class AbpAuthorizationServiceExtensions_Tests : AuthorizationTestBase |
||||
|
{ |
||||
|
private readonly IExceptionToErrorInfoConverter _exceptionToErrorInfoConverter; |
||||
|
|
||||
|
public AbpAuthorizationServiceExtensions_Tests() |
||||
|
{ |
||||
|
_exceptionToErrorInfoConverter = GetRequiredService<IExceptionToErrorInfoConverter>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Test_AbpAuthorizationException_Localization() |
||||
|
{ |
||||
|
using (CultureHelper.Use("zh-Hans")) |
||||
|
{ |
||||
|
var exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenPolicyHasNotGranted); |
||||
|
var errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的策略尚未授予."); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenPolicyHasNotGrantedWithPolicyName) |
||||
|
.WithData("PolicyName", "my_policy_name"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的策略尚未授予: my_policy_name"); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenPolicyHasNotGrantedForGivenResource) |
||||
|
.WithData("ResourceName", "my_resource_name"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的策略未授予提供的资源: my_resource_name"); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenRequirementHasNotGrantedForGivenResource) |
||||
|
.WithData("ResourceName", "my_resource_name"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的要求未授予提供的资源: my_resource_name"); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenRequirementsHasNotGrantedForGivenResource) |
||||
|
.WithData("ResourceName", "my_resource_name"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的要求未授予提供的资源: my_resource_name"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue