Skip to content

Commit 5186a79

Browse files
authored
Add webapp for NLB node simulation with local index. (#2214)
* Add webapp for NLB node simulation with local index. * refactor.
1 parent 8ed7e53 commit 5186a79

File tree

9 files changed

+405
-0
lines changed

9 files changed

+405
-0
lines changed

src/SenseNet.sln

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnWebApplication.Api.Sql.To
9696
EndProject
9797
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnWebApplication.Api.Sql.SearchService.TokenAuth.Preview", "WebApps\SnWebApplication.Api.Sql.SearchService.TokenAuth.Preview\SnWebApplication.Api.Sql.SearchService.TokenAuth.Preview.csproj", "{8BA4865A-4C72-43C1-A3B2-FC21119C2CD6}"
9898
EndProject
99+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnWebApplication.Api.Sql.TokenAuth.NLB", "WebApps\SnWebApplication.Api.Sql.TokenAuth.NLB\SnWebApplication.Api.Sql.TokenAuth.NLB.csproj", "{F91BACBA-937D-4282-CC0C-098383E793DC}"
100+
EndProject
99101
Global
100102
GlobalSection(SolutionConfigurationPlatforms) = preSolution
101103
Debug|Any CPU = Debug|Any CPU
@@ -740,6 +742,22 @@ Global
740742
{8BA4865A-4C72-43C1-A3B2-FC21119C2CD6}.Release|x64.Build.0 = Release|Any CPU
741743
{8BA4865A-4C72-43C1-A3B2-FC21119C2CD6}.Release|x86.ActiveCfg = Release|Any CPU
742744
{8BA4865A-4C72-43C1-A3B2-FC21119C2CD6}.Release|x86.Build.0 = Release|Any CPU
745+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
746+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
747+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
748+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
749+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Debug|x64.ActiveCfg = Debug|Any CPU
750+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Debug|x64.Build.0 = Debug|Any CPU
751+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Debug|x86.ActiveCfg = Debug|Any CPU
752+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Debug|x86.Build.0 = Debug|Any CPU
753+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
754+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Release|Any CPU.Build.0 = Release|Any CPU
755+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
756+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
757+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Release|x64.ActiveCfg = Release|Any CPU
758+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Release|x64.Build.0 = Release|Any CPU
759+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Release|x86.ActiveCfg = Release|Any CPU
760+
{F91BACBA-937D-4282-CC0C-098383E793DC}.Release|x86.Build.0 = Release|Any CPU
743761
EndGlobalSection
744762
GlobalSection(SolutionProperties) = preSolution
745763
HideSolutionNode = FALSE
@@ -785,6 +803,7 @@ Global
785803
{9E9B0B82-46B4-4A80-918F-32E855406DBC} = {C68D256D-7D40-4E33-8A2B-B1625538B138}
786804
{4C6517FA-E734-4090-BCE3-BC50FBC632B8} = {61F11B98-137D-402E-AAF9-DA329D109B4B}
787805
{8BA4865A-4C72-43C1-A3B2-FC21119C2CD6} = {61F11B98-137D-402E-AAF9-DA329D109B4B}
806+
{F91BACBA-937D-4282-CC0C-098383E793DC} = {61F11B98-137D-402E-AAF9-DA329D109B4B}
788807
EndGlobalSection
789808
GlobalSection(ExtensibilityGlobals) = postSolution
790809
SolutionGuid = {7D903DEB-CA0B-43D8-BD9D-820BB1453C4C}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
2+
3+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
4+
WORKDIR /app
5+
EXPOSE 80
6+
EXPOSE 443
7+
8+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
9+
WORKDIR /src
10+
COPY . .
11+
WORKDIR "/src/WebApps/SnWebApplication.Api.Sql.TokenAuth.NLB"
12+
RUN dotnet restore "SnWebApplication.Api.Sql.TokenAuth.NLB.csproj"
13+
RUN dotnet build "SnWebApplication.Api.Sql.TokenAuth.NLB.csproj" -c Release -o /app/build
14+
15+
FROM build AS publish
16+
RUN dotnet publish "SnWebApplication.Api.Sql.TokenAuth.NLB.csproj" -c Release -o /app/publish
17+
18+
FROM base AS final
19+
RUN apt-get update && apt-get install -y libgdiplus
20+
WORKDIR /app
21+
COPY --from=publish /app/publish .
22+
ENTRYPOINT ["dotnet", "SnWebApplication.Api.Sql.TokenAuth.NLB.dll"]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
using Microsoft.Extensions.Logging;
4+
using Serilog;
5+
6+
namespace SnWebApplication.Api.Sql.TokenAuth.NLB
7+
{
8+
public class Program
9+
{
10+
public static void Main(string[] args)
11+
{
12+
CreateHostBuilder(args).Build().Run();
13+
}
14+
15+
public static IHostBuilder CreateHostBuilder(string[] args) =>
16+
Host.CreateDefaultBuilder(args)
17+
.ConfigureWebHostDefaults(webBuilder =>
18+
{
19+
webBuilder.UseStartup<Startup>()
20+
.ConfigureLogging(loggingConfiguration =>
21+
loggingConfiguration.ClearProviders());
22+
})
23+
.UseSerilog((hostingContext, loggerConfiguration) =>
24+
loggerConfiguration.ReadFrom
25+
.Configuration(hostingContext.Configuration));
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:51945",
8+
"sslPort": 44362
9+
}
10+
},
11+
"profiles": {
12+
"SnWebApplication.Api.Sql.TokenAuth.NLB": {
13+
"commandName": "Project",
14+
"launchBrowser": true,
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
},
18+
"applicationUrl": "https://localhost:44362"
19+
},
20+
"Docker": {
21+
"commandName": "Docker",
22+
"environmentVariables": {
23+
"sensenet:Authentication:metadatahost": "http://SnIdentityServer"
24+
},
25+
"launchBrowser": true,
26+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
27+
"publishAllPorts": true,
28+
"useSSL": true,
29+
"sslPort": 44362
30+
}
31+
}
32+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<UserSecretsId>6856b5d1-6865-4d80-b2d7-d0a42c8d79e8</UserSecretsId>
6+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
7+
<DockerfileContext>..\..</DockerfileContext>
8+
<DockerfileRunArguments>--network sensenet --name SnWebApplication</DockerfileRunArguments>
9+
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
14+
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.3.0" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
19+
<PackageReference Include="SenseNet.AI.Text.SemanticKernel" Version="0.0.3" />
20+
<PackageReference Include="SenseNet.AI.Vision.Azure" Version="0.0.1-beta1" />
21+
<PackageReference Include="SenseNet.Search.Lucene29.Local" Version="7.5.1" />
22+
<PackageReference Include="SenseNet.Messaging.RabbitMQ" Version="1.2.0" />
23+
<PackageReference Include="SenseNet.Security.Messaging.RabbitMQ" Version="1.3.1" />
24+
<PackageReference Include="SenseNet.Security.EFCSecurityStore" Version="3.2.0" />
25+
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
26+
<PackageReference Include="Serilog.Sinks.Graylog" Version="3.1.1" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<ProjectReference Include="..\..\ContentRepository.MsSql\SenseNet.ContentRepository.MsSql.csproj" />
31+
<ProjectReference Include="..\..\OData\SenseNet.OData.csproj" />
32+
<ProjectReference Include="..\..\OpenApi\SenseNet.OpenApi.csproj" />
33+
<ProjectReference Include="..\..\Services.Core.Install\SenseNet.Services.Core.Install.csproj" />
34+
<ProjectReference Include="..\..\Services.Core\SenseNet.Services.Core.csproj" />
35+
<ProjectReference Include="..\..\Services.Wopi\SenseNet.Services.Wopi.csproj" />
36+
<ProjectReference Include="..\..\WebHooks\SenseNet.WebHooks.csproj" />
37+
</ItemGroup>
38+
39+
<ItemGroup>
40+
<Folder Include="App_Data\" />
41+
</ItemGroup>
42+
43+
</Project>
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
using System;
2+
using System.IdentityModel.Tokens.Jwt;
3+
using System.IO;
4+
using System.Security.Claims;
5+
using Microsoft.AspNetCore.Authentication.JwtBearer;
6+
using Microsoft.AspNetCore.Builder;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Http;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
12+
using Microsoft.Extensions.Logging;
13+
using Microsoft.Extensions.Options;
14+
using Microsoft.IdentityModel.Tokens;
15+
using SenseNet.Configuration;
16+
using SenseNet.ContentRepository;
17+
using SenseNet.ContentRepository.Security.ApiKeys;
18+
using SenseNet.Diagnostics;
19+
using SenseNet.Extensions.DependencyInjection;
20+
using SenseNet.Search.Lucene29;
21+
using SenseNet.Security.Messaging.RabbitMQ;
22+
using SenseNet.Services.Core.Authentication;
23+
24+
namespace SnWebApplication.Api.Sql.TokenAuth.NLB
25+
{
26+
public class Startup
27+
{
28+
public Startup(IConfiguration configuration)
29+
{
30+
Configuration = configuration;
31+
}
32+
33+
public IConfiguration Configuration { get; }
34+
35+
// This method gets called by the runtime. Use this method to add services to the container.
36+
public void ConfigureServices(IServiceCollection services)
37+
{
38+
services.AddRazorPages();
39+
40+
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
41+
42+
// [sensenet]: Authentication
43+
var authOptions = new AuthenticationOptions();
44+
Configuration.GetSection("sensenet:authentication").Bind(authOptions);
45+
46+
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
47+
.AddJwtBearer(options =>
48+
{
49+
options.RequireHttpsMetadata = false;
50+
options.SaveToken = true;
51+
52+
if (authOptions.AuthServerType == AuthenticationServerType.SNAuth)
53+
{
54+
options.TokenValidationParameters = new TokenValidationParameters
55+
{
56+
ValidateIssuerSigningKey = false
57+
};
58+
59+
options.TokenHandlers.Clear();
60+
options.TokenHandlers.Add(new SenseNetJwtSecurityTokenHandler(
61+
$"{authOptions.Authority}/api/auth/validate-token"));
62+
}
63+
else
64+
{
65+
options.Audience = "sensenet";
66+
67+
options.Authority = authOptions.Authority;
68+
if (!string.IsNullOrWhiteSpace(authOptions.MetadataHost))
69+
options.MetadataAddress =
70+
$"{authOptions.MetadataHost.AddUrlSchema().TrimEnd('/')}/.well-known/openid-configuration";
71+
}
72+
});
73+
74+
// [sensenet]: Set options for ApiKeys
75+
services.Configure<ApiKeysOptions>(Configuration.GetSection("sensenet:ApiKeys"));
76+
77+
// [sensenet]: Set options for EFCSecurityDataProvider
78+
services.AddOptions<SenseNet.Security.EFCSecurityStore.Configuration.DataOptions>()
79+
.Configure<IOptions<ConnectionStringOptions>>((securityOptions, systemConnections) =>
80+
securityOptions.ConnectionString = systemConnections.Value.Security);
81+
82+
// [sensenet]: add sensenet services
83+
services
84+
.AddSenseNetInstallPackage()
85+
.AddSenseNet(Configuration, (repositoryBuilder, provider) =>
86+
{
87+
var searchEngineLogger = repositoryBuilder.Services.GetService<ILogger<Lucene29SearchEngine>>();
88+
repositoryBuilder
89+
.UseLogger(provider)
90+
.UseLucene29LocalSearchEngine(searchEngineLogger,
91+
Path.Combine(Environment.CurrentDirectory, "App_Data", "LocalIndex"));
92+
})
93+
.AddEFCSecurityDataProvider()
94+
.AddSenseNetMsSqlProviders(configureInstallation: installOptions =>
95+
{
96+
Configuration.Bind("sensenet:install:mssql", installOptions);
97+
})
98+
.Configure<RabbitMqOptions>(Configuration.GetSection("sensenet:security:rabbitmq"))
99+
.AddRabbitMqSecurityMessageProvider()
100+
.AddRabbitMqMessageProvider(configureRabbitMq: options =>
101+
{
102+
Configuration.GetSection("sensenet:rabbitmq").Bind(options);
103+
})
104+
.AddSenseNetOData()
105+
.AddSenseNetWebHooks()
106+
.AddSenseNetWopi()
107+
.AddSenseNetSemanticKernel(options =>
108+
{
109+
Configuration.Bind("sensenet:ai:SemanticKernel", options);
110+
})
111+
.AddSenseNetAzureVision(options =>
112+
{
113+
Configuration.Bind("sensenet:ai:AzureVision", options);
114+
});
115+
116+
// [sensenet]: statistics overrides
117+
var statOptions = new StatisticsOptions();
118+
Configuration.GetSection("sensenet:statistics").Bind(statOptions);
119+
if (!statOptions.Enabled)
120+
{
121+
// reset to default/null services
122+
services
123+
.AddDefaultStatisticalDataProvider()
124+
.AddDefaultStatisticalDataCollector();
125+
}
126+
}
127+
128+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
129+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
130+
{
131+
if (env.IsDevelopment())
132+
{
133+
app.UseDeveloperExceptionPage();
134+
}
135+
136+
app.UseRouting();
137+
138+
// [sensenet]: custom CORS policy
139+
app.UseSenseNetCors();
140+
// [sensenet]: use Authentication and set User.Current
141+
app.UseSenseNetAuthentication();
142+
143+
// [sensenet]: MembershipExtender middleware
144+
app.UseSenseNetMembershipExtenders();
145+
146+
app.UseAuthorization();
147+
148+
// [sensenet] Add the sensenet binary handler
149+
app.UseSenseNetFiles();
150+
151+
// [sensenet]: Health middleware
152+
app.UseSenseNetHealth();
153+
// [sensenet]: OData middleware
154+
app.UseSenseNetOdata();
155+
// [sensenet]: WOPI middleware
156+
app.UseSenseNetWopi();
157+
158+
app.UseEndpoints(endpoints =>
159+
{
160+
endpoints.MapRazorPages();
161+
162+
endpoints.MapGet("/", async context =>
163+
{
164+
await context.Response.WriteAsync("sensenet is listening. Visit https://sensenet.com for " +
165+
"more information on how to call the REST API.");
166+
});
167+
});
168+
}
169+
}
170+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Serilog": {
3+
"WriteTo": [
4+
{ "Name": "Console" },
5+
{
6+
"Name": "File",
7+
"Args": {
8+
"path": "App_Data/Logs/log-.txt",
9+
"rollingInterval": "Day"
10+
}
11+
}
12+
]
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"Serilog": {
3+
"WriteTo": [
4+
{ "Name": "Console" },
5+
{
6+
"Name": "Graylog",
7+
"Args": {
8+
"hostnameOrAddress": "",
9+
"port": "12201",
10+
"transportType": "Udp",
11+
"restrictedToMinimumLevel": "Verbose"
12+
}
13+
}
14+
]
15+
}
16+
}

0 commit comments

Comments
 (0)