Skip to content

Commit 064edbe

Browse files
committed
gh-47 Integrate MONAI Deploy Security
Signed-off-by: Victor Chang <[email protected]>
1 parent 80cda34 commit 064edbe

File tree

12 files changed

+79
-37
lines changed

12 files changed

+79
-37
lines changed

src/Client/Test/packages.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,8 @@
725725
},
726726
"Monai.Deploy.Security": {
727727
"type": "Transitive",
728-
"resolved": "0.1.0",
729-
"contentHash": "ZbHei1e/jZVk3pTiTSjlB5dy3VsFBEGed9Md19xfal07K1vHGgn4+LNd+izdB7wAGhVRR0VuDNuCn6teO1Ljhw==",
728+
"resolved": "0.2.0-vchang-logging0008",
729+
"contentHash": "YUgEwyLIe3DVk+SwVMS1sXRJUlpqleHPoNWeIl+sCFbGDzDvjn8k7nnLPgM8KuZ8vpMgVcimBarCThSyDyf8kA==",
730730
"dependencies": {
731731
"Ardalis.GuardClauses": "4.0.1",
732732
"Microsoft.AspNetCore.Authentication.JwtBearer": "6.0.11",
@@ -1688,7 +1688,7 @@
16881688
"Monai.Deploy.InformaticsGateway.Database.EntityFramework": "[1.0.0, )",
16891689
"Monai.Deploy.InformaticsGateway.DicomWeb.Client": "[1.0.0, )",
16901690
"Monai.Deploy.Messaging.RabbitMQ": "[0.1.18, )",
1691-
"Monai.Deploy.Security": "[0.1.0, )",
1691+
"Monai.Deploy.Security": "[0.2.0-vchang-logging0008, )",
16921692
"Monai.Deploy.Storage": "[0.2.11, )",
16931693
"Monai.Deploy.Storage.MinIO": "[0.2.11, )",
16941694
"NLog": "[5.1.0, )",

src/DicomWebClient/CLI/packages.lock.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,20 +1474,20 @@
14741474
"monai.deploy.informaticsgateway.client.common": {
14751475
"type": "Project",
14761476
"dependencies": {
1477-
"Ardalis.GuardClauses": "4.0.1",
1478-
"System.Text.Json": "6.0.7"
1477+
"Ardalis.GuardClauses": "[4.0.1, )",
1478+
"System.Text.Json": "[6.0.7, )"
14791479
}
14801480
},
14811481
"monai.deploy.informaticsgateway.dicomweb.client": {
14821482
"type": "Project",
14831483
"dependencies": {
1484-
"Ardalis.GuardClauses": "4.0.1",
1485-
"Microsoft.AspNet.WebApi.Client": "5.2.9",
1486-
"Microsoft.Extensions.Http": "6.0.0",
1487-
"Microsoft.Net.Http.Headers": "2.2.8",
1488-
"Monai.Deploy.InformaticsGateway.Client.Common": "1.0.0",
1489-
"System.Linq.Async": "6.0.1",
1490-
"fo-dicom": "5.0.3"
1484+
"Ardalis.GuardClauses": "[4.0.1, )",
1485+
"Microsoft.AspNet.WebApi.Client": "[5.2.9, )",
1486+
"Microsoft.Extensions.Http": "[6.0.0, )",
1487+
"Microsoft.Net.Http.Headers": "[2.2.8, )",
1488+
"Monai.Deploy.InformaticsGateway.Client.Common": "[1.0.0, )",
1489+
"System.Linq.Async": "[6.0.1, )",
1490+
"fo-dicom": "[5.0.3, )"
14911491
}
14921492
}
14931493
}

src/DicomWebClient/packages.lock.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,8 @@
12541254
"monai.deploy.informaticsgateway.client.common": {
12551255
"type": "Project",
12561256
"dependencies": {
1257-
"Ardalis.GuardClauses": "4.0.1",
1258-
"System.Text.Json": "6.0.7"
1257+
"Ardalis.GuardClauses": "[4.0.1, )",
1258+
"System.Text.Json": "[6.0.7, )"
12591259
}
12601260
}
12611261
}

src/InformaticsGateway/Monai.Deploy.InformaticsGateway.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
~ Copyright 2022 MONAI Consortium
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,6 +26,7 @@
2626
<LangVersion>latest</LangVersion>
2727
<CodeAnalysisRuleSet>..\.sonarlint\project-monai_monai-deploy-informatics-gatewaycsharp.ruleset</CodeAnalysisRuleSet>
2828
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
29+
<UserSecretsId>be0fffc8-bebb-4509-a2c0-3c981e5415ab</UserSecretsId>
2930
</PropertyGroup>
3031

3132
<ItemGroup>
@@ -50,7 +51,7 @@
5051
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
5152
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
5253
<PackageReference Include="Monai.Deploy.Messaging.RabbitMQ" Version="0.1.18" />
53-
<PackageReference Include="Monai.Deploy.Security" Version="0.1.0" />
54+
<PackageReference Include="Monai.Deploy.Security" Version="0.2.0-vchang-logging0008" />
5455
<PackageReference Include="Monai.Deploy.Storage" Version="0.2.11" />
5556
<PackageReference Include="Monai.Deploy.Storage.MinIO" Version="0.2.11" />
5657
<PackageReference Include="NLog.Web.AspNetCore" Version="5.2.0" />

src/InformaticsGateway/Program.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
using Monai.Deploy.InformaticsGateway.Common;
3030
using Monai.Deploy.InformaticsGateway.Configuration;
3131
using Monai.Deploy.InformaticsGateway.Database;
32-
using Monai.Deploy.InformaticsGateway.Database.Api.Repositories;
33-
using Monai.Deploy.InformaticsGateway.Database.EntityFramework.Repositories;
3432
using Monai.Deploy.InformaticsGateway.Repositories;
3533
using Monai.Deploy.InformaticsGateway.Services.Common;
3634
using Monai.Deploy.InformaticsGateway.Services.Connectors;
@@ -44,6 +42,7 @@
4442
using Monai.Deploy.InformaticsGateway.Services.Storage;
4543
using Monai.Deploy.Messaging;
4644
using Monai.Deploy.Messaging.Configuration;
45+
using Monai.Deploy.Security.Authentication.Configurations;
4746
using Monai.Deploy.Storage;
4847
using Monai.Deploy.Storage.Configuration;
4948
using NLog;
@@ -95,13 +94,10 @@ internal static IHostBuilder CreateHostBuilder(string[] args) =>
9594
})
9695
.ConfigureServices((hostContext, services) =>
9796
{
98-
services.AddOptions<InformaticsGatewayConfiguration>()
99-
.Bind(hostContext.Configuration.GetSection("InformaticsGateway"));
100-
services.AddOptions<MessageBrokerServiceConfiguration>()
101-
.Bind(hostContext.Configuration.GetSection("InformaticsGateway:messaging"));
102-
services.AddOptions<StorageServiceConfiguration>()
103-
.Bind(hostContext.Configuration.GetSection("InformaticsGateway:storage"));
104-
97+
services.AddOptions<InformaticsGatewayConfiguration>().Bind(hostContext.Configuration.GetSection("InformaticsGateway"));
98+
services.AddOptions<MessageBrokerServiceConfiguration>().Bind(hostContext.Configuration.GetSection("InformaticsGateway:messaging"));
99+
services.AddOptions<StorageServiceConfiguration>().Bind(hostContext.Configuration.GetSection("InformaticsGateway:storage"));
100+
services.AddOptions<AuthenticationOptions>().Bind(hostContext.Configuration.GetSection("MonaiDeployAuthentication"));
105101
services.TryAddEnumerable(ServiceDescriptor.Singleton<IValidateOptions<InformaticsGatewayConfiguration>, ConfigurationValidator>());
106102

107103
services.ConfigureDatabase(hostContext.Configuration?.GetSection("ConnectionStrings"));

src/InformaticsGateway/Services/Http/Startup.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using Microsoft.OpenApi.Models;
3131
using Monai.Deploy.InformaticsGateway.Database.EntityFramework;
3232
using Monai.Deploy.InformaticsGateway.Services.Fhir;
33+
using Monai.Deploy.Security.Authentication.Extensions;
3334

3435
namespace Monai.Deploy.InformaticsGateway.Services.Http
3536
{
@@ -106,6 +107,8 @@ public void ConfigureServices(IServiceCollection services)
106107
};
107108
});
108109

110+
services.AddMonaiAuthentication();
111+
109112
services.AddHealthChecks()
110113
.AddCheck<MonaiHealthCheck>("Informatics Gateway Services")
111114
.AddDbContextCheck<InformaticsGatewayContext>("Database");
@@ -123,7 +126,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
123126
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MONAI Deploy Informatics Gateway v1"));
124127
}
125128

126-
app.UseRouting();
127129
app.UseHealthChecks("/health", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions
128130
{
129131
ResponseWriter = async (context, report) =>
@@ -139,13 +141,20 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
139141
});
140142

141143
context.Response.ContentType = MediaTypeNames.Application.Json;
142-
await context.Response.WriteAsync(result);
144+
await context.Response.WriteAsync(result).ConfigureAwait(false);
143145
}
144146
});
145147

148+
app.UseRouting();
149+
app.UseAuthentication();
150+
app.UseAuthorization();
151+
app.UseEndpointAuthorizationMiddleware();
152+
app.UseHttpLogging();
153+
146154
app.UseEndpoints(endpoints =>
147155
{
148-
endpoints.MapControllers();
156+
endpoints.MapHealthChecks("/health").AllowAnonymous();
157+
endpoints.MapControllers().RequireAuthorization();
149158
});
150159
}
151160
}

src/InformaticsGateway/Test/packages.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,8 @@
965965
},
966966
"Monai.Deploy.Security": {
967967
"type": "Transitive",
968-
"resolved": "0.1.0",
969-
"contentHash": "ZbHei1e/jZVk3pTiTSjlB5dy3VsFBEGed9Md19xfal07K1vHGgn4+LNd+izdB7wAGhVRR0VuDNuCn6teO1Ljhw==",
968+
"resolved": "0.2.0-vchang-logging0008",
969+
"contentHash": "YUgEwyLIe3DVk+SwVMS1sXRJUlpqleHPoNWeIl+sCFbGDzDvjn8k7nnLPgM8KuZ8vpMgVcimBarCThSyDyf8kA==",
970970
"dependencies": {
971971
"Ardalis.GuardClauses": "4.0.1",
972972
"Microsoft.AspNetCore.Authentication.JwtBearer": "6.0.11",
@@ -1917,7 +1917,7 @@
19171917
"Monai.Deploy.InformaticsGateway.Database.EntityFramework": "[1.0.0, )",
19181918
"Monai.Deploy.InformaticsGateway.DicomWeb.Client": "[1.0.0, )",
19191919
"Monai.Deploy.Messaging.RabbitMQ": "[0.1.18, )",
1920-
"Monai.Deploy.Security": "[0.1.0, )",
1920+
"Monai.Deploy.Security": "[0.2.0-vchang-logging0008, )",
19211921
"Monai.Deploy.Storage": "[0.2.11, )",
19221922
"Monai.Deploy.Storage.MinIO": "[0.2.11, )",
19231923
"NLog": "[5.1.0, )",

src/InformaticsGateway/appsettings.Development.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"MonaiDeployAuthentication": {
3+
"bypassAuthentication": true
4+
},
25
"ConnectionStrings": {
36
"InformaticsGatewayDatabase": "Data Source=migdev.db"
47
},

src/InformaticsGateway/appsettings.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
{
2+
"MonaiDeployAuthentication": {
3+
"bypassAuthentication": false,
4+
"openId": {
5+
"realm": "http://localhost:8080/realms/monai-test/",
6+
"realmKey": "993kdf2YXmv3itIvVOJX6zDT9o2nLxwW",
7+
"clientId": "monai-app",
8+
"audiences": [ "monai-app-test" ],
9+
"roleClaimType": "roles",
10+
"claimMappings": {
11+
"userClaims": [
12+
{
13+
"claimType": "roles",
14+
"claimValues": [ "monai-deploy-user" ],
15+
"endpoints": [ "Stow", "Fhir", "Inference" ]
16+
},
17+
{
18+
"claimType": "roles",
19+
"claimValues": [ "pacs-admin" ],
20+
"endpoints": [ "MonaiAeTitle", "SourceAeTitle", "DestinationAeTitle" ]
21+
}
22+
],
23+
"adminClaims": [
24+
{
25+
"claimType": "roles",
26+
"claimValues": [ "monai-role-admin" ]
27+
}
28+
]
29+
}
30+
}
31+
},
232
"ConnectionStrings": {
333
"Type": "Sqlite",
434
"InformaticsGatewayDatabase": "Data Source=/database/mig.db"

src/InformaticsGateway/packages.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@
184184
},
185185
"Monai.Deploy.Security": {
186186
"type": "Direct",
187-
"requested": "[0.1.0, )",
188-
"resolved": "0.1.0",
189-
"contentHash": "ZbHei1e/jZVk3pTiTSjlB5dy3VsFBEGed9Md19xfal07K1vHGgn4+LNd+izdB7wAGhVRR0VuDNuCn6teO1Ljhw==",
187+
"requested": "[0.2.0-vchang-logging0008, )",
188+
"resolved": "0.2.0-vchang-logging0008",
189+
"contentHash": "YUgEwyLIe3DVk+SwVMS1sXRJUlpqleHPoNWeIl+sCFbGDzDvjn8k7nnLPgM8KuZ8vpMgVcimBarCThSyDyf8kA==",
190190
"dependencies": {
191191
"Ardalis.GuardClauses": "4.0.1",
192192
"Microsoft.AspNetCore.Authentication.JwtBearer": "6.0.11",

tests/Integration.Test/appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"MonaiDeployAuthentication": {
3+
"BypassAuthentication": true
4+
},
25
"ConnectionStrings": {
36
"Type": "mongodb",
47
"InformaticsGatewayDatabase": "mongodb://root:rootpassword@localhost:27017",

tests/Integration.Test/packages.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,8 @@
811811
},
812812
"Monai.Deploy.Security": {
813813
"type": "Transitive",
814-
"resolved": "0.1.0",
815-
"contentHash": "ZbHei1e/jZVk3pTiTSjlB5dy3VsFBEGed9Md19xfal07K1vHGgn4+LNd+izdB7wAGhVRR0VuDNuCn6teO1Ljhw==",
814+
"resolved": "0.2.0-vchang-logging0008",
815+
"contentHash": "YUgEwyLIe3DVk+SwVMS1sXRJUlpqleHPoNWeIl+sCFbGDzDvjn8k7nnLPgM8KuZ8vpMgVcimBarCThSyDyf8kA==",
816816
"dependencies": {
817817
"Ardalis.GuardClauses": "4.0.1",
818818
"Microsoft.AspNetCore.Authentication.JwtBearer": "6.0.11",
@@ -1811,7 +1811,7 @@
18111811
"Monai.Deploy.InformaticsGateway.Database.EntityFramework": "[1.0.0, )",
18121812
"Monai.Deploy.InformaticsGateway.DicomWeb.Client": "[1.0.0, )",
18131813
"Monai.Deploy.Messaging.RabbitMQ": "[0.1.18, )",
1814-
"Monai.Deploy.Security": "[0.1.0, )",
1814+
"Monai.Deploy.Security": "[0.2.0-vchang-logging0008, )",
18151815
"Monai.Deploy.Storage": "[0.2.11, )",
18161816
"Monai.Deploy.Storage.MinIO": "[0.2.11, )",
18171817
"NLog": "[5.1.0, )",

0 commit comments

Comments
 (0)