2021-03-03 10:40:16 +11:00
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-03-04 15:07:54 +11:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-03-03 10:40:16 +11:00
|
|
|
using Umbraco.Cms.Core.Security;
|
|
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
namespace Umbraco.Cms.Web.Common.Security;
|
|
|
|
|
|
|
|
|
|
public class BackOfficeSecurityAccessor : IBackOfficeSecurityAccessor
|
2021-03-03 10:40:16 +11:00
|
|
|
{
|
2022-05-09 09:39:46 +02:00
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
2021-03-03 10:40:16 +11:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="BackOfficeSecurityAccessor" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public BackOfficeSecurityAccessor(IHttpContextAccessor httpContextAccessor) =>
|
|
|
|
|
_httpContextAccessor = httpContextAccessor;
|
2021-03-03 10:40:16 +11:00
|
|
|
|
2022-05-09 09:39:46 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the current <see cref="IBackOfficeSecurity" /> object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
// RequestServices can be null when testing, even though compiler says it can't
|
|
|
|
|
public IBackOfficeSecurity? BackOfficeSecurity
|
|
|
|
|
=> _httpContextAccessor.HttpContext?.RequestServices?.GetService<IBackOfficeSecurity>();
|
2021-03-03 10:40:16 +11:00
|
|
|
}
|