Browse Source

Add ReturnOrginalValueIfDecryptFailed to

pull/21744/head
liangshiwei 2 years ago
parent
commit
0d10a22181
  1. 3
      framework/src/Volo.Abp.Settings/Volo/Abp/Settings/AbpSettingOptions.cs
  2. 16
      framework/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingEncryptionService.cs

3
framework/src/Volo.Abp.Settings/Volo/Abp/Settings/AbpSettingOptions.cs

@ -11,10 +11,13 @@ public class AbpSettingOptions
public HashSet<string> DeletedSettings { get; }
public bool ReturnOrginalValueIfDecryptFailed { get; set; }
public AbpSettingOptions()
{
DefinitionProviders = new TypeList<ISettingDefinitionProvider>();
ValueProviders = new TypeList<ISettingValueProvider>();
DeletedSettings = new HashSet<string>();
ReturnOrginalValueIfDecryptFailed = true;
}
}

16
framework/src/Volo.Abp.Settings/Volo/Abp/Settings/SettingEncryptionService.cs

@ -1,6 +1,7 @@
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Encryption;
@ -10,10 +11,12 @@ public class SettingEncryptionService : ISettingEncryptionService, ITransientDep
{
protected IStringEncryptionService StringEncryptionService { get; }
public ILogger<SettingEncryptionService> Logger { get; set; }
protected IOptions<AbpSettingOptions> Options { get; }
public SettingEncryptionService(IStringEncryptionService stringEncryptionService)
public SettingEncryptionService(IStringEncryptionService stringEncryptionService, IOptions<AbpSettingOptions> options)
{
StringEncryptionService = stringEncryptionService;
Options = options;
Logger = NullLogger<SettingEncryptionService>.Instance;
}
@ -38,13 +41,14 @@ public class SettingEncryptionService : ISettingEncryptionService, ITransientDep
{
return StringEncryptionService.Decrypt(encryptedValue);
}
catch (FormatException)
{
// not an encrypted value, return the original value
return encryptedValue;
}
catch (Exception e)
{
if (Options.Value.ReturnOrginalValueIfDecryptFailed)
{
Logger.LogWarning(e, "Failed to decrypt the setting: {0}. Returning the original value...", settingDefinition.Name);
return encryptedValue;
}
Logger.LogException(e);
return string.Empty;

Loading…
Cancel
Save