Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/TestServerTest/TestAuthHandler.cs
Nikolaj Geisle 595ee242aa V14: Remove old backoffice project. (#15752)
* Move magical route to management api

* Move auth around

* Remove "New" cookies, as they are no longer needed

* Move all installer related

* Remove BackOfficeServerVariables.cs and trees

* Move webhooks to management api

* Remove remainting controllers

* Remove last services

* Move preview to management api

* Remove mroe extensions

* Remove tours

* Remove old Auth handlers

* Remove server variables entirely

* Remove old backoffice controller

* Remove controllers namespace entirely

* Move rest of preview

* move last services

* Move language file extension

* Remove old backoffice entirely (Backoffice and Web.UI projects)

* Clean up unused security classes

* Fix up installer route

* Remove obsolete tests

* Fix up DI in integration test

* Add missing property mapping

* Move core mapping into core

* Add composers to integration test

* remove identity

* Fix up DI

* Outcomment failing test :)

* Fix up remaining test

* Update mapper

* Remove the actual project files

* Remove backoffice cs proj

* Remove old backoffice from yml

* Run belissima before login

* Remove caching

* Refactor file paths

* Remove belle from static assets

* Dont refer to old project in templates

* update gitignore

* Add missing files

* Remove install view as its no longer used

* Fix up failing test

* Remove outcommented code

* Update submodule to latest

* fix build

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2024-02-27 12:40:30 +01:00

50 lines
1.6 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.Common.Security;
namespace Umbraco.Cms.Tests.Integration.TestServerTest;
public class TestAuthHandler : AuthenticationHandler<AuthenticationSchemeOptions>
{
public const string TestAuthenticationScheme = "Test";
private readonly IBackOfficeSignInManager _backOfficeSignInManager;
private readonly BackOfficeIdentityUser _fakeUser;
public TestAuthHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
IBackOfficeSignInManager backOfficeSignInManager,
IUserService userService,
IUmbracoMapper umbracoMapper)
: base(options, logger, encoder)
{
_backOfficeSignInManager = backOfficeSignInManager;
var user = userService.GetUserById(Constants.Security.SuperUserId);
_fakeUser = umbracoMapper.Map<IUser, BackOfficeIdentityUser>(user);
_fakeUser.SecurityStamp = "Needed";
}
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
var principal = await _backOfficeSignInManager.CreateUserPrincipalAsync(_fakeUser);
var ticket = new AuthenticationTicket(principal, TestAuthenticationScheme);
return AuthenticateResult.Success(ticket);
}
}