Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

54 lines
1.7 KiB

// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Security;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Squidex.Domain.Apps.Entities;
using Squidex.Infrastructure.Commands;
using Squidex.Infrastructure.Security;
namespace Squidex.Web.CommandMiddlewares
{
public class EnrichWithActorCommandMiddleware : ICommandMiddleware
{
private readonly IHttpContextAccessor httpContextAccessor;
public EnrichWithActorCommandMiddleware(IHttpContextAccessor httpContextAccessor)
{
this.httpContextAccessor = httpContextAccessor;
}
public Task HandleAsync(CommandContext context, Func<Task> next)
{
if (httpContextAccessor.HttpContext == null)
{
return next();
}
if (context.Command is SquidexCommand squidexCommand)
{
var user = httpContextAccessor.HttpContext.User;
if (squidexCommand.Actor == null)
{
var actorToken = user.Token();
squidexCommand.Actor = actorToken ?? throw new SecurityException("No actor with subject or client id available.");
}
if (squidexCommand.User == null)
{
squidexCommand.User = httpContextAccessor.HttpContext.User;
}
}
return next();
}
}
}