From 0d0eb609d339f3d464dd10f037acd3d8494c9562 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Fri, 19 Nov 2021 21:22:05 +1000 Subject: [PATCH] [Key Connector] Test that Key Connector URL can be reached before saving (#1291) * Test that Key Connector URL can be reached before saving * Update jslib * Add styling to validation messages * Use inline button, fix styling * Add accessibility call out to form validation --- .../organizations/manage/sso.component.html | 18 ++++++++- .../app/organizations/manage/sso.component.ts | 37 +++++++++++++++++++ src/locales/en/messages.json | 9 +++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/bitwarden_license/src/app/organizations/manage/sso.component.html b/bitwarden_license/src/app/organizations/manage/sso.component.html index ddcf4f2f03..ec9e6a1e9e 100644 --- a/bitwarden_license/src/app/organizations/manage/sso.component.html +++ b/bitwarden_license/src/app/organizations/manage/sso.component.html @@ -54,7 +54,23 @@
- +
+ +
+ +
+
+ +
diff --git a/bitwarden_license/src/app/organizations/manage/sso.component.ts b/bitwarden_license/src/app/organizations/manage/sso.component.ts index 706d88af97..5e4f1b3de1 100644 --- a/bitwarden_license/src/app/organizations/manage/sso.component.ts +++ b/bitwarden_license/src/app/organizations/manage/sso.component.ts @@ -38,6 +38,8 @@ export class SsoComponent implements OnInit { spMetadataUrl: string; spAcsUrl: string; + keyConnectorIsValid: boolean; + enabled = this.fb.control(false); data = this.fb.group({ configType: [], @@ -115,6 +117,15 @@ export class SsoComponent implements OnInit { } async submit() { + if (!this.keyConnectorIsValid || this.keyConnectorUrl.dirty) + { + await this.testKeyConnector(); + if (!this.keyConnectorIsValid) { + this.platformUtilsService.showToast('error', null, this.i18nService.t('keyConnectorTestFail')); + return; + } + } + const request = new OrganizationSsoRequest(); request.enabled = this.enabled.value; request.data = this.data.value; @@ -128,4 +139,30 @@ export class SsoComponent implements OnInit { this.formPromise = null; this.platformUtilsService.showToast('success', null, this.i18nService.t('ssoSettingsSaved')); } + + async testKeyConnector() { + if (this.keyConnectorIsValid && this.keyConnectorUrl.pristine) { + return; + } + + this.keyConnectorUrl.markAsPristine(); + try { + await this.apiService.getKeyConnectorAlive(this.keyConnectorUrl.value); + } catch { + this.keyConnectorIsValid = false; + return; + } + + this.keyConnectorIsValid = true; + } + + get enableTestKeyConnector() { + return this.data.get('keyConnectorEnabled').value && + this.keyConnectorUrl != null && + this.keyConnectorUrl.value !== ''; + } + + get keyConnectorUrl() { + return this.data.get('keyConnectorUrl'); + } } diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index 6a9adc4708..7779d9f44e 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -4571,5 +4571,14 @@ }, "migratedKeyConnector": { "message": "Migrated to Key Connector" + }, + "keyConnectorTest": { + "message": "Test" + }, + "keyConnectorTestSuccess": { + "message": "Success! Key Connector reached." + }, + "keyConnectorTestFail": { + "message": "Cannot reach Key Connector. Check URL." } }