Skip to content

Commit

Permalink
Feat #597 [Add] a full trust checkbox on the login form to allow conn…
Browse files Browse the repository at this point in the history
…ecting to servers with self signed certificates (#599)
  • Loading branch information
joao4all authored May 8, 2024
1 parent 172870f commit d222f27
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 143 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CodeQuality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
with:
dotnet-version: '8.0.x'

- name: add Github nuget feed
run: dotnet nuget add source https://nuget.pkg.github.com/STARIONGROUP/index.json -n StarionGithubFeed -u STARIONGROUP -p ${{ secrets.PACKAGE_TOKEN }} --store-password-in-clear-text

- name: add DevExpress nuget feed
run: dotnet nuget add source https://nuget.devexpress.com/api -n DXFeed -u DevExpress -p ${{ secrets.DEVEXPRESS_NUGET_KEY }} --store-password-in-clear-text

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
with:
languages: ${{ matrix.language }}

- name: add Github nuget feed
run: dotnet nuget add source https://nuget.pkg.github.com/STARIONGROUP/index.json -n StarionGithubFeed -u STARIONGROUP -p ${{ secrets.PACKAGE_TOKEN }} --store-password-in-clear-text

- name: add DevExpress nuget feed
run: dotnet nuget add source https://nuget.devexpress.com/api -n DXFeed -u DevExpress -p ${{ secrets.DEVEXPRESS_NUGET_KEY }} --store-password-in-clear-text

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ public void VerifyIndexPageWithRedirectionNotAuthorized()
var url = QueryHelpers.AddQueryString("ModelDashboard", QueryKeys.ServerKey, targetServer);

var renderer = this.context.RenderComponent<IndexComponent>(parameters =>
parameters.Add(p => p.Redirect, url));
{
parameters.Add(p => p.Redirect, url);
parameters.Add(p => p.FullTrustCheckboxVisible, true);
});

var login = renderer.FindComponent<Login>();
Assert.That(login.Instance.ViewModel.AuthenticationDto.SourceAddress, Is.EqualTo(targetServer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public async Task VerifyLogout()
public async Task VerifyValidLogin()
{
this.sessionService.Setup(x => x.OpenSession(It.IsAny<Credentials>())).ReturnsAsync(Result.Ok);

this.authenticationDto.FullTrust = true;
var loginResult = await this.authenticationService.Login(this.authenticationDto);

Assert.That(loginResult.IsSuccess, Is.EqualTo(true));
Expand Down
2 changes: 1 addition & 1 deletion COMET.Web.Common/COMET.Web.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ItemGroup>
<PackageReference Include="AsyncEnumerator" Version="4.0.2" />
<PackageReference Include="Blazored.FluentValidation" Version="2.1.0" />
<PackageReference Include="CDP4ServicesDal-CE" Version="26.6.0" />
<PackageReference Include="CDP4ServicesDal-CE" Version="26.7.0-8940498145-641-1-PR-339" />
<PackageReference Include="CDP4Web-CE" Version="26.6.0" />
<PackageReference Include="DevExpress.Blazor" Version="23.2.3" />
<PackageReference Include="FluentResults" Version="3.15.2" />
Expand Down
2 changes: 1 addition & 1 deletion COMET.Web.Common/Components/IndexComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<div id="unauthorized-notice" class="text-align-center font-weight-bold">Connect and Open a Model.</div>
<div class="m-top-10px color-title">
<h5 class="color-title font-weight-bold">Connect</h5>
<Login RequestedServer="@this.requestedServer"/>
<Login RequestedServer="@this.requestedServer" FullTrustCheckboxVisible="@this.FullTrustCheckboxVisible"/>
</div>
</div>
</div>
Expand Down
82 changes: 44 additions & 38 deletions COMET.Web.Common/Components/IndexComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IndexComponent.razor.cs" company="Starion Group S.A.">
// Copyright (c) 2023-2024 Starion Group S.A.
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of CDP4-COMET WEB Community Edition
// The CDP4-COMET WEB Community Edition is the Starion Web Application implementation of ECSS-E-TM-10-25
// Annex A and Annex C.
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

Expand All @@ -29,7 +28,6 @@ namespace COMET.Web.Common.Components
using CDP4Common.SiteDirectoryData;

using COMET.Web.Common.Extensions;
using COMET.Web.Common.Services.RegistrationService;
using COMET.Web.Common.Utilities;
using COMET.Web.Common.ViewModels.Components;

Expand Down Expand Up @@ -72,6 +70,12 @@ public partial class IndexComponent
[Parameter]
public string Redirect { get; set; }

/// <summary>
/// The condition to check if the full trust checkbox should be visible or not
/// </summary>
[Parameter]
public bool FullTrustCheckboxVisible { get; set; }

/// <summary>
/// The <see cref="NavigationManager" />
/// </summary>
Expand All @@ -98,29 +102,31 @@ protected override void OnParametersSet()
{
base.OnParametersSet();

if (!string.IsNullOrEmpty(this.Redirect))
if (string.IsNullOrEmpty(this.Redirect))
{
return;
}

var options = this.Redirect.GetParametersFromUrl();

if (options.TryGetValue(QueryKeys.ServerKey, out var server))
{
this.requestedServer = server;
}

if (options.TryGetValue(QueryKeys.ModelKey, out var model))
{
this.requestedModel = model.FromShortGuid();
}

if (options.TryGetValue(QueryKeys.DomainKey, out var domain))
{
this.requestedDomainOfExpertise = domain.FromShortGuid();
}

if (options.TryGetValue(QueryKeys.IterationKey, out var iteration))
{
var options = this.Redirect.GetParametersFromUrl();

if (options.TryGetValue(QueryKeys.ServerKey, out var server))
{
this.requestedServer = server;
}

if (options.TryGetValue(QueryKeys.ModelKey, out var model))
{
this.requestedModel = model.FromShortGuid();
}

if (options.TryGetValue(QueryKeys.DomainKey, out var domain))
{
this.requestedDomainOfExpertise = domain.FromShortGuid();
}

if (options.TryGetValue(QueryKeys.IterationKey, out var iteration))
{
this.requestedIteration = iteration.FromShortGuid();
}
this.requestedIteration = iteration.FromShortGuid();
}
}

Expand Down
47 changes: 32 additions & 15 deletions COMET.Web.Common/Components/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
@inherits DisposableComponent

<EditForm Context="editFormContext" Model="@(this.ViewModel.AuthenticationDto)" OnValidSubmit="this.ExecuteLogin">
<DataAnnotationsValidator/>
<DataAnnotationsValidator/>
<DxFormLayout CaptionPosition="CaptionPosition.Vertical">
@if (string.IsNullOrEmpty(this.ViewModel.serverConnectionService.ServerConfiguration.ServerAddress))
@if (string.IsNullOrEmpty(this.ViewModel.ServerConnectionService.ServerConfiguration.ServerAddress))
{
<DxFormLayoutItem Caption="Source Address:" ColSpanLg="12">
<Template>
Expand All @@ -35,7 +35,7 @@
BindValueMode="BindValueMode.OnInput"
@onfocus="@(() => this.HandleFieldFocus("SourceAddress"))"
@onblur="@(() => this.HandleFieldBlur("SourceAddress"))"
Enabled="@string.IsNullOrEmpty(this.RequestedServer)" />
Enabled="@string.IsNullOrEmpty(this.RequestedServer)"/>
</Template>
</DxFormLayoutItem>
}
Expand All @@ -46,7 +46,7 @@
NullText="Enter your username"
BindValueMode="BindValueMode.OnInput"
@onfocus="@(() => this.HandleFieldFocus("UserName"))"
@onblur="@(() => this.HandleFieldBlur("UserName"))" />
@onblur="@(() => this.HandleFieldBlur("UserName"))"/>
</Template>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="@(this.PasswordLabel)" BeginRow="true" ColSpanLg="12">
Expand All @@ -60,6 +60,17 @@
Password="true"/>
</Template>
</DxFormLayoutItem>

@if (this.FullTrustCheckboxVisible)
{
<DxFormLayoutItem Caption="@(this.FullTrustLabel)" BeginRow="true" ColSpanLg="12" CaptionPosition="CaptionPosition.Horizontal">
<Template>
<DxCheckBox Id="fulltrust"
@bind-Checked="@(this.ViewModel.AuthenticationDto.FullTrust)"
Attributes="@(new Dictionary<string, object> { ["title"] = "Checking this option will allow connecting to servers with self signed certificates" })" />
</Template>
</DxFormLayoutItem>
}
</DxFormLayout>

<ul class="validation-errors">
Expand All @@ -72,23 +83,29 @@

@if (fieldFocusedStatus.Key == "SourceAddress" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.SourceAddress).FirstOrDefault()))
{
<li class="validation-message"><ValidationMessage For="() => this.ViewModel.AuthenticationDto.SourceAddress" /></li>
<li class="validation-message">
<ValidationMessage For="() => this.ViewModel.AuthenticationDto.SourceAddress"/>
</li>
}

@if (fieldFocusedStatus.Key == "UserName" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.UserName).FirstOrDefault()))
{
<li class="validation-message"><ValidationMessage For="() => this.ViewModel.AuthenticationDto.UserName" /></li>
<li class="validation-message">
<ValidationMessage For="() => this.ViewModel.AuthenticationDto.UserName"/>
</li>
}

@if (fieldFocusedStatus.Key == "Password" && !string.IsNullOrEmpty(editFormContext.GetValidationMessages(() => this.ViewModel.AuthenticationDto.Password).FirstOrDefault()))
{
<li class="validation-message"><ValidationMessage For="() => this.ViewModel.AuthenticationDto.Password" /></li>
<li class="validation-message">
<ValidationMessage For="() => this.ViewModel.AuthenticationDto.Password"/>
</li>
}
}
</ul>

@if (this.ErrorMessages.Any())
{
@if (this.ErrorMessages.Any())
{
<div class="form-group row m-top-10px text-danger">
<ul>
@foreach (var errrorMessage in this.ErrorMessages)
Expand All @@ -97,11 +114,11 @@
}
</ul>
</div>
}
}

<div class="modal-footer">
<DxButton Id="connectbtn" Text="@(this.LoginButtonDisplayText)" CssClass="btn btn-connect"
Enabled="@this.LoginEnabled"
SubmitFormOnClick="true"/>
</div>
<div class="modal-footer">
<DxButton Id="connectbtn" Text="@(this.LoginButtonDisplayText)" CssClass="btn btn-connect"
Enabled="@(this.LoginEnabled)"
SubmitFormOnClick="true"/>
</div>
</EditForm>
12 changes: 12 additions & 0 deletions COMET.Web.Common/Components/Login.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ public partial class Login
[Parameter]
public string PasswordLabel { get; set; } = "Password:";

/// <summary>
/// The label for the full trust checkbox field
/// </summary>
[Parameter]
public string FullTrustLabel { get; set; } = "FullTrust:";

/// <summary>
/// The condition to check if the full trust checkbox should be visible or not
/// </summary>
[Parameter]
public bool FullTrustCheckboxVisible { get; set; } = false;

/// <summary>
/// The text of the login button
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions COMET.Web.Common/Model/DTO/AuthenticationDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ public class AuthenticationDto
/// </summary>
[Required]
public string Password { get; set; }

/// <summary>
/// Gets or sets the condition to check if full trust is active. This option allows connecting to servers with self signed certificates
/// </summary>
public bool FullTrust { get; set; } = false;
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AuthenticationService.cs" company="Starion Group S.A.">
// Copyright (c) 2023-2024 Starion Group S.A.
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of CDP4-COMET WEB Community Edition
// The CDP4-COMET WEB Community Edition is the Starion Web Application implementation of ECSS-E-TM-10-25
// Annex A and Annex C.
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Services.SessionManagement
{
using System.Net;

using CDP4Dal;
using CDP4Dal.DAL;

Expand All @@ -36,8 +37,6 @@ namespace COMET.Web.Common.Services.SessionManagement

using Microsoft.AspNetCore.Components.Authorization;

using System.Net;

/// <summary>
/// The purpose of the <see cref="AuthenticationService" /> is to authenticate against
/// a E-TM-10-25 Annex C.2 data source
Expand Down Expand Up @@ -76,7 +75,7 @@ public AuthenticationService(ISessionService sessionService, AuthenticationState
/// The authentication information with data source, username and password
/// </param>
/// <returns>
/// The <see cref="Result"/> of the request
/// The <see cref="Result" /> of the request
/// </returns>
public async Task<Result> Login(AuthenticationDto authenticationDto)
{
Expand All @@ -89,7 +88,7 @@ public async Task<Result> Login(AuthenticationDto authenticationDto)
}

var uri = new Uri(authenticationDto.SourceAddress);
var credentials = new Credentials(authenticationDto.UserName, authenticationDto.Password, uri);
var credentials = new Credentials(authenticationDto.UserName, authenticationDto.Password, uri, authenticationDto.FullTrust);
result = await this.sessionService.OpenSession(credentials);

if (result.IsSuccess)
Expand Down
2 changes: 1 addition & 1 deletion COMET.Web.Common/ViewModels/Components/ILoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface ILoginViewModel
/// <summary>
/// Gets the <see cref="IConfigurationService" />
/// </summary>
IConfigurationService serverConnectionService { get; }
IConfigurationService ServerConnectionService { get; }

/// <summary>
/// Gets or sets the loading state
Expand Down
Loading

0 comments on commit d222f27

Please sign in to comment.