mirror of https://github.com/Squidex/squidex.git
22 changed files with 128 additions and 418 deletions
@ -1,44 +0,0 @@ |
|||
// ==========================================================================
|
|||
// LazyClientStore.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Authentication; |
|||
using Microsoft.AspNetCore.Authentication.Cookies; |
|||
using Microsoft.AspNetCore.Authentication.OpenIdConnect; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Squidex.Shared.Identity; |
|||
|
|||
namespace Squidex.Areas.OrleansDashboard.Middlewares |
|||
{ |
|||
public sealed class OrleansDashboardAuthenticationMiddleware |
|||
{ |
|||
private readonly RequestDelegate next; |
|||
|
|||
public OrleansDashboardAuthenticationMiddleware(RequestDelegate next) |
|||
{ |
|||
this.next = next; |
|||
} |
|||
|
|||
public async Task Invoke(HttpContext context) |
|||
{ |
|||
var authentication = await context.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); |
|||
|
|||
if (!authentication.Succeeded || !authentication.Principal.IsInRole(SquidexRoles.Administrator)) |
|||
{ |
|||
await context.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties |
|||
{ |
|||
RedirectUri = context.Request.PathBase + context.Request.Path |
|||
}); |
|||
} |
|||
else |
|||
{ |
|||
await next(context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,28 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Startup.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.AspNetCore.Builder; |
|||
using Orleans; |
|||
using Squidex.Areas.OrleansDashboard.Middlewares; |
|||
using Squidex.Config; |
|||
|
|||
namespace Squidex.Areas.OrleansDashboard |
|||
{ |
|||
public static class Startup |
|||
{ |
|||
public static void ConfigureOrleansDashboard(this IApplicationBuilder app) |
|||
{ |
|||
app.Map(Constants.OrleansPrefix, orleansApp => |
|||
{ |
|||
orleansApp.UseAuthentication(); |
|||
orleansApp.UseMiddleware<OrleansDashboardAuthenticationMiddleware>(); |
|||
orleansApp.UseOrleansDashboard(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
// ==========================================================================
|
|||
// PubSubServices.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Log; |
|||
using StackExchange.Redis; |
|||
|
|||
namespace Squidex.Config.Domain |
|||
{ |
|||
public static class PubSubServices |
|||
{ |
|||
public static void AddMyPubSubServices(this IServiceCollection services, IConfiguration config) |
|||
{ |
|||
config.ConfigureByOption("pubSub:type", new Options |
|||
{ |
|||
["InMemory"] = () => |
|||
{ |
|||
services.AddSingletonAs<InMemoryPubSub>() |
|||
.As<IPubSub>(); |
|||
}, |
|||
["Redis"] = () => |
|||
{ |
|||
var configuration = config.GetRequiredValue("pubsub:redis:configuration"); |
|||
|
|||
var redis = Singletons<IConnectionMultiplexer>.GetOrAddLazy(configuration, s => ConnectionMultiplexer.Connect(s)); |
|||
|
|||
services.AddSingletonAs(c => new RedisPubSub(redis, c.GetRequiredService<ISemanticLog>())) |
|||
.As<IPubSub>() |
|||
.As<IExternalSystem>(); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,57 +0,0 @@ |
|||
// ==========================================================================
|
|||
// ClientServices.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Reflection; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Orleans; |
|||
using Orleans.Runtime.Configuration; |
|||
using Squidex.Domain.Apps.Read.State.Orleans.Grains.Implementations; |
|||
using Squidex.Infrastructure.CQRS.Events.Orleans.Grains.Implementation; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public static class ClientServices |
|||
{ |
|||
public static void AddAppClient(this IServiceCollection services) |
|||
{ |
|||
services.AddSingletonAs(c => c.GetRequiredService<IClusterClient>()) |
|||
.As<IGrainFactory>(); |
|||
|
|||
services.AddServicesForSelfHostedDashboard(null, options => |
|||
{ |
|||
options.HideTrace = true; |
|||
}); |
|||
|
|||
services.AddSingletonAs(c => |
|||
{ |
|||
var client = new ClientBuilder() |
|||
.UseConfiguration(ClientConfiguration.LocalhostSilo().WithJsonSerializer()) |
|||
.UseDashboard() |
|||
.AddApplicationPartsFromReferences(typeof(AppStateGrain).Assembly) |
|||
.AddApplicationPartsFromReferences(typeof(EventConsumerGrain).Assembly) |
|||
.UseStaticGatewayListProvider(options => |
|||
{ |
|||
options.Gateways.Add(new Uri("gwy.tcp://127.0.0.1:40000/0")); |
|||
}) |
|||
.Build(); |
|||
|
|||
client.Connect().Wait(); |
|||
|
|||
return client; |
|||
}); |
|||
} |
|||
|
|||
public static ClientConfiguration WithJsonSerializer(this ClientConfiguration config) |
|||
{ |
|||
config.SerializationProviders.Add(typeof(CustomJsonSerializer).GetTypeInfo()); |
|||
|
|||
return config; |
|||
} |
|||
} |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
// ==========================================================================
|
|||
// CustomJsonSerializer.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Newtonsoft.Json; |
|||
using Squidex.Config.Domain; |
|||
using Squidex.Infrastructure.Json.Orleans; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public class CustomJsonSerializer : JsonExternalSerializer |
|||
{ |
|||
public CustomJsonSerializer() |
|||
: base(JsonSerializer.Create(SerializationServices.DefaultJsonSettings)) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,23 +0,0 @@ |
|||
// ==========================================================================
|
|||
// CustomMongoDbStorageProvider.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using Newtonsoft.Json; |
|||
using Orleans.Providers; |
|||
using Orleans.Providers.MongoDB.StorageProviders; |
|||
using Squidex.Config.Domain; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public sealed class CustomMongoDbStorageProvider : MongoStorageProvider |
|||
{ |
|||
protected override JsonSerializerSettings ReturnSerializerSettings(IProviderRuntime providerRuntime, IProviderConfiguration config) |
|||
{ |
|||
return SerializationServices.DefaultJsonSettings; |
|||
} |
|||
} |
|||
} |
|||
@ -1,43 +0,0 @@ |
|||
// ==========================================================================
|
|||
// SiloExtensions.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Reflection; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Orleans; |
|||
using Orleans.Hosting; |
|||
using Orleans.Runtime.Configuration; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public static class SiloExtensions |
|||
{ |
|||
public static ISiloHostBuilder UseContentRoot(this ISiloHostBuilder builder, string path) |
|||
{ |
|||
builder.ConfigureAppConfiguration(config => |
|||
{ |
|||
config.SetBasePath(path); |
|||
}); |
|||
|
|||
return builder; |
|||
} |
|||
|
|||
public static ClusterConfiguration WithJsonSerializer(this ClusterConfiguration config) |
|||
{ |
|||
config.Globals.SerializationProviders.Add(typeof(CustomJsonSerializer).GetTypeInfo()); |
|||
|
|||
return config; |
|||
} |
|||
|
|||
public static ClusterConfiguration WithDashboard(this ClusterConfiguration config) |
|||
{ |
|||
config.RegisterDashboard(); |
|||
|
|||
return config; |
|||
} |
|||
} |
|||
} |
|||
@ -1,89 +0,0 @@ |
|||
// ==========================================================================
|
|||
// SiloServices.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Linq; |
|||
using System.Net; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Orleans; |
|||
using Orleans.Runtime.Configuration; |
|||
using Squidex.Domain.Apps.Read.Rules.Orleans; |
|||
using Squidex.Infrastructure.CQRS.Events.Orleans.Grains; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public static class SiloServices |
|||
{ |
|||
public static void AddAppSiloServices(this IServiceCollection services, IConfiguration config) |
|||
{ |
|||
var clusterConfiguration = |
|||
services.Where(x => x.ServiceType == typeof(ClusterConfiguration)) |
|||
.Select(x => x.ImplementationInstance) |
|||
.Select(x => (ClusterConfiguration)x) |
|||
.FirstOrDefault(); |
|||
|
|||
if (clusterConfiguration != null) |
|||
{ |
|||
clusterConfiguration.Globals.RegisterBootstrapProvider<EventConsumerBootstrap>("EventConsumers"); |
|||
clusterConfiguration.Globals.RegisterBootstrapProvider<RuleDequeuerBootstrap>("RuleDequeuer"); |
|||
|
|||
var ipConfig = config.GetRequiredValue("orleans:hostNameOrIPAddress"); |
|||
|
|||
if (ipConfig.Equals("Host", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
ipConfig = Dns.GetHostName(); |
|||
} |
|||
else if (ipConfig.Equals("FirstIPAddressOfHost")) |
|||
{ |
|||
var ips = Dns.GetHostAddressesAsync(Dns.GetHostName()).Result; |
|||
|
|||
ipConfig = ips.FirstOrDefault()?.ToString(); |
|||
} |
|||
|
|||
clusterConfiguration.Defaults.PropagateActivityId = true; |
|||
clusterConfiguration.Defaults.ProxyGatewayEndpoint = new IPEndPoint(IPAddress.Any, 40000); |
|||
clusterConfiguration.Defaults.HostNameOrIPAddress = ipConfig; |
|||
} |
|||
|
|||
config.ConfigureByOption("store:type", new Options |
|||
{ |
|||
["MongoDB"] = () => |
|||
{ |
|||
var mongoConfiguration = config.GetRequiredValue("store:mongoDb:configuration"); |
|||
var mongoDatabaseName = config.GetRequiredValue("store:mongoDb:database"); |
|||
|
|||
if (clusterConfiguration != null) |
|||
{ |
|||
clusterConfiguration.AddMongoDBStorageProvider<CustomMongoDbStorageProvider>("Default", c => |
|||
{ |
|||
c.ConnectionString = mongoConfiguration; |
|||
c.CollectionPrefix = "States_"; |
|||
c.DatabaseName = mongoDatabaseName; |
|||
c.UseJsonFormat = true; |
|||
}); |
|||
} |
|||
|
|||
services.AddMongoDBMembershipTable(c => |
|||
{ |
|||
c.ConnectionString = mongoConfiguration; |
|||
c.CollectionPrefix = "Orleans_"; |
|||
c.DatabaseName = mongoDatabaseName; |
|||
}); |
|||
|
|||
services.AddMongoDBReminders(c => |
|||
{ |
|||
c.ConnectionString = mongoConfiguration; |
|||
c.CollectionPrefix = "Orleans_"; |
|||
c.DatabaseName = mongoDatabaseName; |
|||
}); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue