Files
Umbraco-CMS/src/Umbraco.Infrastructure/Services/Implement/BasicAuthService.cs

34 lines
1012 B
C#
Raw Normal View History

2021-08-06 09:51:08 +02:00
using System.Net;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
2021-08-06 10:41:21 +02:00
namespace Umbraco.Cms.Core.Services.Implement
2021-08-06 09:51:08 +02:00
{
public class BasicAuthService : IBasicAuthService
{
private BasicAuthSettings _basicAuthSettings;
public BasicAuthService(IOptionsMonitor<BasicAuthSettings> optionsMonitor)
{
_basicAuthSettings = optionsMonitor.CurrentValue;
optionsMonitor.OnChange(basicAuthSettings => _basicAuthSettings = basicAuthSettings);
}
public bool IsBasicAuthEnabled() => _basicAuthSettings.Enabled;
public bool IsIpAllowListed(IPAddress clientIpAddress)
{
foreach (var allowedIpString in _basicAuthSettings.AllowedIPs)
{
if (IPNetwork.TryParse(allowedIpString, out IPNetwork allowedIp) && allowedIp.Contains(clientIpAddress))
2021-08-06 09:51:08 +02:00
{
return true;
}
2021-08-06 09:51:08 +02:00
}
return false;
}
}
}