using System.Collections.Generic;
using System.Collections.Immutable;
namespace Abp.Authorization
{
///
/// This class is used to get permissions out of the system.
/// Normally, you should inject and use and use it.
/// This class can be used in database migrations or in unit tests where Abp is not initialized.
///
public static class PermissionFinder
{
///
/// Collects and gets all permissions in given providers.
/// This method can be used to get permissions in database migrations or in unit tests where Abp is not initialized.
/// Otherwise, use method.
///
///
/// Authorization providers
/// List of permissions
///
/// This method creates instances of by order and
/// calls to build permission list.
/// So, providers should not use dependency injection.
///
public static IReadOnlyList GetAllPermissions(params AuthorizationProvider[] authorizationProviders)
{
return new InternalPermissionFinder(authorizationProviders).GetAllPermissions();
}
internal class InternalPermissionFinder : PermissionDefinitionContextBase
{
public InternalPermissionFinder(params AuthorizationProvider[] authorizationProviders)
{
foreach (var provider in authorizationProviders)
{
provider.SetPermissions(this);
}
Permissions.AddAllPermissions();
}
public IReadOnlyList GetAllPermissions()
{
return Permissions.Values.ToImmutableList();
}
}
}
}