private Dictionary <string, AuthorizationPolicy> GetDynamicAuthorizationPoliciesFromModulesPermissions()
        {
            var cacheKey = CacheKey.With(GetType(), "GetDynamicAuthorizationPoliciesFromModulesPermissions");
            var result   = _memoryCache.GetOrCreateExclusive(cacheKey, (cacheEntry) =>
            {
                var resultLookup = new Dictionary <string, AuthorizationPolicy>();
                foreach (var permission in _permissionsProvider.GetAllPermissions())
                {
                    resultLookup[permission.Name] = new AuthorizationPolicyBuilder().AddRequirements(new PermissionAuthorizationRequirement {
                        Permission = permission
                    }).Build();
                }
                return(resultLookup);
            });

            return(result);
        }
        public ActionResult GetAllRegisteredPermissions()
        {
            var result = _permissionsProvider.GetAllPermissions().ToArray();

            return(Ok(result));
        }
Пример #3
0
        private async Task ExportPlatformEntriesInternalAsync(ZipArchive zipArchive, PlatformExportManifest manifest, Action <ExportImportProgressInfo> progressCallback, CancellationToken cancellationToken)
        {
            var progressInfo      = new ExportImportProgressInfo();
            var platformExportObj = new PlatformExportEntries();

            if (manifest.HandleSecurity)
            {
                //Roles
                platformExportObj.Roles = _roleManager.Roles.ToList();
                if (_roleManager.SupportsRoleClaims)
                {
                    var permissions = _permissionsProvider.GetAllPermissions();
                    foreach (var role in platformExportObj.Roles)
                    {
                        role.Permissions = (await _roleManager.GetClaimsAsync(role)).Join(permissions, c => c.Value, p => p.Name, (c, p) => p).ToArray();
                    }
                }
                //users
                var usersResult = _userManager.Users.ToArray();
                progressInfo.Description = $"Security: {usersResult.Count()} users exporting...";
                progressCallback(progressInfo);

                foreach (var user in usersResult)
                {
                    var userExt = await _userManager.FindByIdAsync(user.Id);

                    if (userExt != null)
                    {
                        platformExportObj.Users.Add(userExt);
                    }
                }
            }

            //Export setting for selected modules
            if (manifest.HandleSettings)
            {
                progressInfo.Description = "Settings: selected modules settings exporting...";
                progressCallback(progressInfo);

                platformExportObj.Settings = manifest.Modules.SelectMany(x => _settingsManager.GetModuleSettings(x.Id)).ToList();
            }

            //Dynamic properties
            var allTypes = _dynamicPropertyService.GetAvailableObjectTypeNames();

            progressInfo.Description = "Dynamic properties: load properties...";
            progressCallback(progressInfo);

            platformExportObj.DynamicProperties = allTypes.SelectMany(x => _dynamicPropertyService.GetProperties(x)).ToList();
            platformExportObj.DynamicPropertyDictionaryItems = platformExportObj.DynamicProperties.Where(x => x.IsDictionary).SelectMany(x => _dynamicPropertyService.GetDictionaryItems(x.Id)).ToList();

            //Notification templates
            progressInfo.Description = "Notifications: load templates...";
            progressCallback(progressInfo);

            //Create part for platform entries
            var platformEntiriesPart = zipArchive.CreateEntry(_platformZipEntryName, CompressionLevel.Optimal);

            using (var partStream = platformEntiriesPart.Open())
            {
                platformExportObj.SerializeJson(partStream);
            }
        }