feat(saml): option to create minimal SAML metadata file (#6671)

* feat: initial look and feel

* feat: initial textarea

* feat: app details and i18n

* fix: add @peintnermax suggestions

* fix: detail component move code to valueChanges.subscribe and clear inputs if metadataurl set

---------

Co-authored-by: Max Peintner <[email protected]>
Co-authored-by: Elio Bischof <[email protected]>
Co-authored-by: Fabi <[email protected]>
Co-authored-by: Tim Möhlmann <[email protected]>
This commit is contained in:
Miguel Cabrerizo
2023-10-25 20:39:28 +03:00
committed by GitHub
co-authored by Max Peintner Elio Bischof Fabi Tim Möhlmann
parent b51ad53e5a
commit 9d77dcb467
17 changed files with 349 additions and 83 deletions
@@ -1,6 +1,6 @@
import { COMMA, ENTER, SPACE } from '@angular/cdk/keycodes';
import { Location } from '@angular/common';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { AbstractControl, FormControl, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { MatLegacyCheckboxChange as MatCheckboxChange } from '@angular/material/legacy-checkbox';
import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
@@ -183,8 +183,33 @@ export class AppDetailComponent implements OnInit, OnDestroy {
this.samlForm = this.fb.group({
metadataUrl: [{ value: '', disabled: true }],
entityId: ['', []],
acsURL: ['', []],
metadataXml: [{ value: '', disabled: true }],
});
this.samlForm.valueChanges.subscribe((form) => {
let minimalMetadata =
this.entityId?.value && this.acsURL?.value
? `<?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="${this.entityId?.value}">
<md:SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol urn:oasis:names:tc:SAML:1.1:protocol">
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="${this.acsURL?.value}" index="0"/>
</md:SPSSODescriptor>
</md:EntityDescriptor>`
: '';
if (this.metadataUrl && this.metadataUrl.value.length > 0) {
if (this.app && this.app.samlConfig && this.app.samlConfig.metadataXml) {
this.app.samlConfig.metadataXml = '';
}
}
if (this.app && this.app.samlConfig && this.app.samlConfig.metadataXml && minimalMetadata) {
const base64 = Buffer.from(minimalMetadata, 'utf-8').toString('base64');
this.app.samlConfig.metadataXml = base64;
}
});
}
public formatClockSkewLabel(seconds: number): string {
@@ -406,6 +431,8 @@ export class AppDetailComponent implements OnInit, OnDestroy {
this.toast.showInfo('POLICY.PRIVATELABELING.MAXSIZEEXCEEDED', true);
} else {
this.metadataUrl?.setValue('');
this.entityId?.setValue('');
this.acsURL?.setValue('');
const reader = new FileReader();
reader.onload = ((aXML) => {
return (e) => {
@@ -779,6 +806,14 @@ export class AppDetailComponent implements OnInit, OnDestroy {
return this.samlForm.get('metadataUrl');
}
public get entityId(): AbstractControl | null {
return this.samlForm.get('entityId');
}
public get acsURL(): AbstractControl | null {
return this.samlForm.get('acsURL');
}
get decodedBase64(): string {
if (
this.app &&