Skip to content

Commit f0cf0cc

Browse files
committed
Implement lobby session creation passphrase
1 parent 5537124 commit f0cf0cc

File tree

8 files changed

+63
-2
lines changed

8 files changed

+63
-2
lines changed

doc/Installation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ For instance with section `Server.Https` and setting `CertificatePath` becomes:
8686
}
8787
}
8888

89+
You can add a `appsettings.Production.json` file to keep your own settings.
90+
8991
### General configuration - `Server`
9092

9193
`BaseUrl`: Base URL used for mailing. If not set, auto-detection is attempted.
@@ -110,6 +112,10 @@ To configure logging to a file:
110112

111113
`MaxRollingFiles`: Maximum file rollover. 0 for unlimited.
112114

115+
### Security settings
116+
117+
`LobbyCreationPassphrase`: Passphrase to create a lobby. Prevents anyone without this passphrase from creating retrospectives.
118+
113119
### Database set-up - `Database`
114120

115121
Create an new empty database with a case insensitive collation (`SQL_Latin1_General_CP1_CI_AS` is preferred).
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ******************************************************************************
2+
// © 2020 Sebastiaan Dammann | damsteen.nl
3+
//
4+
// File: : SecuritySettings.cs
5+
// Project : Return.Application
6+
// ******************************************************************************
7+
8+
namespace Return.Application.Common.Settings {
9+
using System;
10+
11+
public sealed class SecuritySettings {
12+
/// <summary>
13+
/// Passphrase for creating lobby's - set on server side to prevent just anyone from hosting retrospectives
14+
/// </summary>
15+
public string? LobbyCreationPassphrase { get; set; }
16+
17+
18+
public bool LobbyCreationNeedsPassphrase => !String.IsNullOrEmpty(this.LobbyCreationPassphrase);
19+
}
20+
}

src/Return.Application/Retrospectives/Commands/CreateRetrospective/CreateRetrospectiveCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public class CreateRetrospectiveCommand : IRequest<CreateRetrospectiveCommandRes
1717
#nullable enable
1818
public string? Passphrase { get; set; }
1919

20-
20+
public string? LobbyCreationPassphrase { get; set; }
2121
}
2222
}

src/Return.Application/Retrospectives/Commands/CreateRetrospective/CreateRetrospectiveCommandValidator.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@
66
// ******************************************************************************
77

88
namespace Return.Application.Retrospectives.Commands.CreateRetrospective {
9+
using System;
10+
using Common.Settings;
911
using FluentValidation;
12+
using Microsoft.Extensions.Options;
1013

1114
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", Justification = "This is a validation rule set.")]
1215
public sealed class CreateRetrospectiveCommandValidator : AbstractValidator<CreateRetrospectiveCommand> {
13-
public CreateRetrospectiveCommandValidator() {
16+
public CreateRetrospectiveCommandValidator(IOptions<SecuritySettings> securitySettingsAccessor) {
17+
if (securitySettingsAccessor == null) throw new ArgumentNullException(nameof(securitySettingsAccessor));
18+
1419
this.RuleFor(x => x.Title).NotEmpty().MaximumLength(256);
1520
this.RuleFor(x => x.Passphrase).MaximumLength(512);
1621
this.RuleFor(x => x.FacilitatorPassphrase).NotEmpty().MaximumLength(512);
22+
23+
this.RuleFor(x => x.LobbyCreationPassphrase)
24+
.Equal(securitySettingsAccessor.Value.LobbyCreationPassphrase)
25+
.When(_ => securitySettingsAccessor.Value.LobbyCreationNeedsPassphrase)
26+
.WithMessage("Invalid passphrase entered needed for creating a lobby");
1727
}
1828
}
1929
}

src/Return.Application/Return.Application.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
</PackageReference>
1616

17+
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.2" />
18+
1719
<PackageReference Include="MediatR" Version="8.0.1" />
1820
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />
1921

src/Return.Web/Pages/CreateRetrospective.razor

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
@page "/create-retro"
22
@inherits MediatorComponent
33
@using Microsoft.Extensions.Logging
4+
@using Microsoft.Extensions.Options
5+
@using Return.Application.Common.Settings
46
@using Return.Application.Retrospectives.Commands.CreateRetrospective
57
@inject ILogger<CreateRetrospective> Logger
8+
@inject IOptions<SecuritySettings> SecuritySettingsAccessor
69

710
@if (ShowCompletionMessage)
811
{
@@ -106,6 +109,18 @@ else
106109
</div>
107110
</div>
108111
</div>
112+
113+
@if (SecuritySettingsAccessor.Value.LobbyCreationNeedsPassphrase)
114+
{
115+
<div class="field">
116+
<label class="label" for="retro-lobby-creation-passphrase">Lobby creation passphrase</label>
117+
<div class="control">
118+
<InputText id="retro-lobby-creation-passphrase" class="input" type="password" @bind-Value="@Model.LobbyCreationPassphrase" />
119+
</div>
120+
121+
<ValidationMessage For="() => Model.LobbyCreationPassphrase"></ValidationMessage>
122+
</div>
123+
}
109124

110125
<div class="field is-grouped">
111126
<div class="control">

src/Return.Web/Startup.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Return.Web {
88
using System;
99
using Application;
1010
using Application.Common.Abstractions;
11+
using Application.Common.Settings;
1112
using Application.Services;
1213
using Configuration;
1314
using Domain;
@@ -54,6 +55,8 @@ public void ConfigureServices(IServiceCollection services) {
5455
services.Configure<HttpsServerOptions>(this.Configuration.GetSection("server").GetSection("https"));
5556
services.Configure<ServerOptions>(this.Configuration.GetSection("server"));
5657

58+
services.Configure<SecuritySettings>(this.Configuration.GetSection("Security"));
59+
5760
// Framework
5861
services.AddRazorPages();
5962
services.AddServerSideBlazor();

src/Return.Web/appsettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
"MaxRollingFiles": 24
1313
}
1414
},
15+
1516
"AllowedHosts": "*",
1617

18+
"Security": {
19+
"LobbyCreationPassphrase": null
20+
},
21+
1722
"Database": {
1823
"ConnectionString": "",
1924
"Server": "(localdb)\\mssqllocaldb",

0 commit comments

Comments
 (0)