protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, UserAllowedDataCollectionRequirement requirement) { var dataCollectionName = _dataCollectionNameProvider.GetDataCollectionName(); var identityUserId = context.User.Claims.Where(x => x.Type.Equals("sub")).Select(x => x.Value).FirstOrDefault(); if (string.IsNullOrEmpty(identityUserId)) { context.Fail(); } else { var users = await _usersProvider.GetUsersAsync(CancellationToken.None); var user = users.Where(x => x.IdentityUserId == identityUserId).FirstOrDefault(); if ((user == null) || (!user.DataCollectionNames.Contains(dataCollectionName))) { context.Fail(); } else { context.Succeed(requirement); } } }
public DataCollectionFiles( IDataCollectionNameProvider dataCollectionNameProvider, IStoragesProvider storageProvider, IFileNameProvider fileNameProvider) { _dataCollectionName = dataCollectionNameProvider.GetDataCollectionName(); _storageProvider = storageProvider; _fileNameProvider = fileNameProvider; }
public string GetDataCollectionName() { try { _logger.LogInformation("Started getting data name"); var result = _dataCollectionNameProvider.GetDataCollectionName(); _logger.LogInformation("Finished getting data name"); return(result); } catch (Exception e) { _logger.LogCritical("Error getting config data name: {errorMessage}", e.GetAggregateMessages()); throw; } }