protected virtual async Task <List <KeyValuePair <string, PermissionGrantCacheItem> > > SetCacheItemsAsync( string providerName, string providerKey, List <string> notCacheKeys) { var permissions = PermissionDefinitionManager.GetPermissions().Where(x => notCacheKeys.Any(k => GetPermissionNameFormCacheKeyOrNull(k) == x.Name)).ToList(); Logger.LogDebug($"Getting not cache granted permissions from the repository for this provider name,key: {providerName},{providerKey}"); var grantedPermissionsHashSet = new HashSet <string>( (await PermissionGrantRepository.GetListAsync(notCacheKeys.Select(GetPermissionNameFormCacheKeyOrNull).ToArray(), providerName, providerKey)).Select(p => p.Name) ); Logger.LogDebug($"Setting the cache items. Count: {permissions.Count}"); var cacheItems = new List <KeyValuePair <string, PermissionGrantCacheItem> >(); foreach (var permission in permissions) { var isGranted = grantedPermissionsHashSet.Contains(permission.Name); cacheItems.Add(new KeyValuePair <string, PermissionGrantCacheItem>( CalculateCacheKey(permission.Name, providerName, providerKey), new PermissionGrantCacheItem(isGranted)) ); } await Cache.SetManyAsync(cacheItems); Logger.LogDebug($"Finished setting the cache items. Count: {permissions.Count}"); return(cacheItems); }
public virtual async Task <List <PermissionWithGrantedProviders> > GetAllAsync(string providerName, string providerKey) { var permissionDefinitions = PermissionDefinitionManager.GetPermissions().ToArray(); var multiplePermissionWithGrantedProviders = await GetInternalAsync(permissionDefinitions, providerName, providerKey); return(multiplePermissionWithGrantedProviders.Result); }
public virtual async Task <List <PermissionWithGrantedProviders> > GetAllAsync(string providerName, string providerKey) { var results = new List <PermissionWithGrantedProviders>(); foreach (var permissionDefinition in PermissionDefinitionManager.GetPermissions()) { results.Add(await GetInternalAsync(permissionDefinition, providerName, providerKey)); } return(results); }
private async Task GrantedAllPermissionsToAdminUser(IdentityUser adminUser, MultiTenancySides multiTenancySides) { foreach (var permission in PermissionDefinitionManager.GetPermissions()) { if (permission.MultiTenancySide != multiTenancySides) { continue; } await PermissionManager.SetForUserAsync(adminUser.Id, permission.Name, true); } }
public Task SeedAsync(DataSeedContext context) { var permissionNames = PermissionDefinitionManager .GetPermissions() .Select(p => p.Name) //TODO: Filter host/tenant permissions! .ToArray(); return(PermissionDataSeeder.SeedAsync( RolePermissionValueProvider.ProviderName, "admin", permissionNames, context.TenantId )); }
public virtual Task SeedAsync(DataSeedContext context) { var multiTenancySide = CurrentTenant.GetMultiTenancySide(); var permissionNames = PermissionDefinitionManager .GetPermissions() .Where(p => p.MultiTenancySide.HasFlag(multiTenancySide)) .Select(p => p.Name) .ToArray(); return(PermissionDataSeeder.SeedAsync( RolePermissionValueProvider.ProviderName, "admin", permissionNames, context.TenantId )); }
public virtual async Task SeedAsync(DataSeedContext context) { var multiTenancySide = CurrentTenant.GetMultiTenancySide(); var permissionDefinitions = PermissionDefinitionManager .GetPermissions() .Where(p => p.MultiTenancySide.HasFlag(multiTenancySide)) .ToArray(); var permissions = new Dictionary <string, string> (); foreach (var permissionDefinition in permissionDefinitions) { var selectedScope = permissionDefinition.Scopes.FirstOrDefault(); // 系统权限需要首先设置Scope范围 if (selectedScope == null) { throw new RocketException($"No scopes defined for the permission '{permissionDefinition.Name}', please define permission scopes first."); } // 系统权限需要设置最大权限作为第一个权限 if (selectedScope.Name == nameof(PermissionScopeType.Prohibited)) { throw new RocketException($"Prohibited scope for the permission '{permissionDefinition.Name}' can not set as first scope, please set max scope as the first scope."); } permissions.Add(permissionDefinition.Name, selectedScope.Name); } // 设置超级管理员角色权限 63eab816-3619-a6d7-c82b-39f53e403b4a await PermissionDataSeeder.SeedAsync( RolePermissionValueProvider.ProviderName, "63eab816-3619-a6d7-c82b-39f53e403b4a", permissions, context.TenantId ); // 设置超管账号权限 716d0fe6-3101-057b-ba30-39f53e403930 await PermissionDataSeeder.SeedAsync( UserPermissionValueProvider.ProviderName, "716d0fe6-3101-057b-ba30-39f53e403930", permissions, context.TenantId ); }
protected virtual async Task SetCacheItemsAsync( string providerName, string providerKey, string currentName, PermissionGrantCacheItem currentCacheItem) { var permissions = PermissionDefinitionManager.GetPermissions(); Logger.LogDebug($"Getting all granted permissions from the repository for this provider name,key: {providerName},{providerKey}"); var grantedPermissionsHashSet = new HashSet <string>( (await PermissionGrantRepository.GetListAsync(providerName, providerKey)).Select(p => p.Name) ); Logger.LogDebug($"Setting the cache items. Count: {permissions.Count}"); var cacheItems = new List <KeyValuePair <string, PermissionGrantCacheItem> >(); foreach (var permission in permissions) { var isGranted = grantedPermissionsHashSet.Contains(permission.Name); cacheItems.Add(new KeyValuePair <string, PermissionGrantCacheItem>( CalculateCacheKey(permission.Name, providerName, providerKey), new PermissionGrantCacheItem(isGranted)) ); if (permission.Name == currentName) { currentCacheItem.IsGranted = isGranted; } } await Cache.SetManyAsync(cacheItems); Logger.LogDebug($"Finished setting the cache items. Count: {permissions.Count}"); }