2020-12-03 23:49:32 +11:00
|
|
|
using System;
|
2021-02-17 14:17:38 +01:00
|
|
|
using System.Security.Claims;
|
2017-09-14 19:29:12 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.Owin;
|
|
|
|
|
using Microsoft.Owin.Security;
|
|
|
|
|
using Microsoft.Owin.Security.Infrastructure;
|
|
|
|
|
using Owin;
|
2021-02-17 14:17:38 +01:00
|
|
|
using Umbraco.Extensions;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Security;
|
2017-09-14 19:29:12 +02:00
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
|
|
|
|
{
|
2018-08-15 17:44:06 +10:00
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures there's an admin user assigned to the request
|
|
|
|
|
/// </summary>
|
2017-09-14 19:29:12 +02:00
|
|
|
public class AuthenticateEverythingMiddleware : AuthenticationMiddleware<AuthenticationOptions>
|
|
|
|
|
{
|
|
|
|
|
public AuthenticateEverythingMiddleware(OwinMiddleware next, IAppBuilder app, AuthenticationOptions options)
|
|
|
|
|
: base(next, options)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override AuthenticationHandler<AuthenticationOptions> CreateHandler()
|
|
|
|
|
{
|
|
|
|
|
return new AuthenticateEverythingHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AuthenticateEverythingHandler : AuthenticationHandler<AuthenticationOptions>
|
|
|
|
|
{
|
|
|
|
|
protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
|
|
|
|
|
{
|
2020-06-02 17:48:08 +10:00
|
|
|
var securityStamp = Guid.NewGuid().ToString();
|
2021-02-17 14:17:38 +01:00
|
|
|
|
|
|
|
|
var identity = new ClaimsIdentity();
|
2021-02-22 08:38:12 +01:00
|
|
|
identity.AddRequiredClaims(
|
2021-02-22 08:43:28 +01:00
|
|
|
Cms.Core.Constants.Security.SuperUserIdAsString,
|
2021-02-17 14:17:38 +01:00
|
|
|
"admin",
|
|
|
|
|
"Admin",
|
|
|
|
|
new[] { -1 },
|
|
|
|
|
new[] { -1 },
|
|
|
|
|
"en-US",
|
|
|
|
|
securityStamp,
|
|
|
|
|
new[] { "content", "media", "members" },
|
|
|
|
|
new[] { "admin" });
|
2017-09-14 19:29:12 +02:00
|
|
|
|
2020-12-04 12:44:27 +11:00
|
|
|
return Task.FromResult(new AuthenticationTicket(
|
|
|
|
|
identity,
|
2017-09-14 19:29:12 +02:00
|
|
|
new AuthenticationProperties()
|
|
|
|
|
{
|
|
|
|
|
ExpiresUtc = DateTime.Now.AddDays(1)
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AuthenticateEverythingAuthenticationOptions : AuthenticationOptions
|
|
|
|
|
{
|
|
|
|
|
public AuthenticateEverythingAuthenticationOptions()
|
|
|
|
|
: base("AuthenticateEverything")
|
|
|
|
|
{
|
|
|
|
|
AuthenticationMode = AuthenticationMode.Active;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-23 10:08:18 +02:00
|
|
|
}
|