Added AddAlwaysAllowAuthorization method and AlwaysAllowAuthorizationService.

pull/272/head
Halil İbrahim Kalkan 7 years ago
parent 1045e9dae4
commit f9847e0a67

@ -1,13 +1,23 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Authorization;
using Volo.Abp.Authorization.Permissions;
namespace Microsoft.Extensions.DependencyInjection
{
public static class AbpAuthorizationServiceCollectionExtensions
{
//TODO: Remove this and use AddAlwaysAllowAuthorization
public static IServiceCollection AddAlwaysAllowPermissionChecker(this IServiceCollection services)
{
return services.Replace(ServiceDescriptor.Singleton<IPermissionChecker, AlwaysAllowPermissionChecker>());
}
public static IServiceCollection AddAlwaysAllowAuthorization(this IServiceCollection services)
{
services.Replace(ServiceDescriptor.Singleton<IAuthorizationService, AlwaysAllowAuthorizationService>());
services.Replace(ServiceDescriptor.Singleton<IAbpAuthorizationService, AlwaysAllowAuthorizationService>());
return services.Replace(ServiceDescriptor.Singleton<IPermissionChecker, AlwaysAllowPermissionChecker>());
}
}
}

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Security.Claims;
namespace Volo.Abp.Authorization
{
public class AlwaysAllowAuthorizationService : IAbpAuthorizationService
{
public IServiceProvider ServiceProvider { get; }
public ClaimsPrincipal CurrentPrincipal => _currentPrincipalAccessor.Principal;
private readonly ICurrentPrincipalAccessor _currentPrincipalAccessor;
public AlwaysAllowAuthorizationService(IServiceProvider serviceProvider, ICurrentPrincipalAccessor currentPrincipalAccessor)
{
ServiceProvider = serviceProvider;
_currentPrincipalAccessor = currentPrincipalAccessor;
}
public Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object resource, IEnumerable<IAuthorizationRequirement> requirements)
{
return Task.FromResult(AuthorizationResult.Success());
}
public Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object resource, string policyName)
{
return Task.FromResult(AuthorizationResult.Success());
}
}
}
Loading…
Cancel
Save