68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using BeWo.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.ServiceModel.Channels;
|
|
using System.ServiceModel;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Xml;
|
|
using System.ServiceModel.Dispatcher;
|
|
using BeWo.Service.Core;
|
|
using BS.Shared.Extensions;
|
|
using BeWo.Service.ServiceUtils;
|
|
using BS.Shared.Attributes;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
|
|
|
|
namespace BeWo.Service.ServiceBehavior
|
|
{
|
|
public class AdminMultitenancyContextInitializer : ICallContextInitializer
|
|
{
|
|
public void AfterInvoke(object pCorrelationState)
|
|
{
|
|
if (pCorrelationState is MultitenancyOperationContextExt)
|
|
{
|
|
OperationContext.Current.Extensions.Remove((MultitenancyOperationContextExt)pCorrelationState);
|
|
}
|
|
}
|
|
|
|
public object BeforeInvoke(InstanceContext pInstanceContext, IClientChannel pChannel, Message pMessage)
|
|
{
|
|
string lTenant = null;
|
|
|
|
// RequireNoTenant
|
|
var lTemp = ServiceHelper.GetCustomAttribute<RequireNoTenantAttribute>(pChannel.LocalAddress.Uri, pMessage.Headers.To);
|
|
if (lTemp is object)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
//// Hole tenant aus Query
|
|
if (pMessage.Properties?.Via is Uri uri)
|
|
{
|
|
var query = HttpUtility.ParseQueryString(uri.Query);
|
|
var tenant = query["tenant"];
|
|
|
|
lTenant = tenant;
|
|
}
|
|
|
|
// Hole tenant aus Header
|
|
if (string.IsNullOrWhiteSpace(lTenant))
|
|
{
|
|
|
|
}
|
|
|
|
// Wenn kein Tenant gefunden wird,
|
|
if (string.IsNullOrWhiteSpace(lTenant))
|
|
{
|
|
throw new ArgumentException($"Zugriff verweigert. Tenant (\'{lTenant}\') darf nicht leer sein.", nameof(lTenant));
|
|
}
|
|
|
|
var lExt = new MultitenancyOperationContextExt { Tenant = lTenant };
|
|
OperationContext.Current.Extensions.Add(lExt);
|
|
return lExt;
|
|
}
|
|
}
|
|
}
|