From 3da82e4837eb1a03895b167a68578ce2e45e7b21 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Mon, 11 Jan 2021 09:13:44 +0000
Subject: [PATCH] FEAT #14594 TIME 6 add login azure saml

(cherry picked from commit 63c6a762e486d4fe2dbf0853048949dbc9723826)
---
 src/frontend/app/login/login.component.html | 6 +++---
 src/frontend/app/login/login.component.ts   | 5 +++--
 src/frontend/service/auth.service.ts        | 2 +-
 src/lang/lang-fr.json                       | 1 +
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/frontend/app/login/login.component.html b/src/frontend/app/login/login.component.html
index f3df9f0e697..e6da8a5dd17 100644
--- a/src/frontend/app/login/login.component.html
+++ b/src/frontend/app/login/login.component.html
@@ -6,11 +6,11 @@
                 <div style="color: white;font-size: 14px;" [innerHTML]="authService.loginMessage | safeHtml"></div>
                 <p style="color: white;font-size: 14px;font-weight: bold;">{{authService.applicationName}}</p>
                 <div style="padding-left: 30px;padding-right: 30px;">
-                    <mat-form-field *ngIf="['cas', 'keycloak', 'sso'].indexOf(authService.authMode) === -1" class="input-row login" appearance="outline" style="padding-bottom: 0px;">
+                    <mat-form-field *ngIf="['cas', 'keycloak', 'sso', 'azure_saml'].indexOf(authService.authMode) === -1" class="input-row login" appearance="outline" style="padding-bottom: 0px;">
                         <input id="login" name="login" matInput [placeholder]="'lang.id' | translate" formControlName="login"
                             type="text">
                     </mat-form-field>
-                    <mat-form-field *ngIf="['cas', 'keycloak', 'sso'].indexOf(authService.authMode) === -1" class="input-row" appearance="outline">
+                    <mat-form-field *ngIf="['cas', 'keycloak', 'sso', 'azure_saml'].indexOf(authService.authMode) === -1" class="input-row" appearance="outline">
                         <input id="password" name="password" matInput [placeholder]="'lang.password' | translate" type="password"
                             formControlName="password">
                         <mat-hint align="end" *ngIf="authService.authMode === 'standard'"><a
@@ -19,7 +19,7 @@
                                 class="infoLogin">{{'lang.' + authService.authMode + 'Enabled' | translate}}</span></mat-hint>
                     </mat-form-field>
                 </div>
-                <div *ngIf="['cas', 'keycloak', 'sso'].indexOf(authService.authMode) > -1" class="alert-message alert-message-info" role="alert" style="max-width: 100%;">
+                <div *ngIf="['cas', 'keycloak', 'sso', 'azure_saml'].indexOf(authService.authMode) > -1" class="alert-message alert-message-info" role="alert" style="max-width: 100%;">
                     {{'lang.' + authService.authMode + 'Enabled' | translate}}
                 </div>
                 <button id="submit" type="submit" mat-stroked-button [disabled]="loginForm.invalid || loading"
diff --git a/src/frontend/app/login/login.component.ts b/src/frontend/app/login/login.component.ts
index ef65c1f8006..6a5224b5531 100644
--- a/src/frontend/app/login/login.component.ts
+++ b/src/frontend/app/login/login.component.ts
@@ -43,7 +43,6 @@ export class LoginComponent implements OnInit {
     ) { }
 
     ngOnInit(): void {
-
         this.headerService.hideSideBar = true;
         this.loginForm = this.formBuilder.group({
             login: [null, Validators.required],
@@ -104,6 +103,8 @@ export class LoginComponent implements OnInit {
                     window.location.href = this.authService.authUri;
                 } else if (this.authService.authMode === 'openam' && err.error.errors === 'Authentication Failed : User cookie is not set' && !this.functionsService.empty(this.authService.authUri)) {
                     window.location.href = this.authService.authUri;
+                } else if (this.authService.authMode === 'azure_saml' && err.error.errors === 'Authentication Failed : not logged') {
+                    window.location.href = err.error.authUri;
                 } else {
                     this.notify.handleSoftErrors(err);
                 }
@@ -113,7 +114,7 @@ export class LoginComponent implements OnInit {
     }
 
     initConnection() {
-        if (['sso', 'openam'].indexOf(this.authService.authMode) > -1) {
+        if (['sso', 'openam', 'azure_saml'].indexOf(this.authService.authMode) > -1) {
             this.loginForm.disable();
             this.loginForm.setValidators(null);
             this.onSubmit();
diff --git a/src/frontend/service/auth.service.ts b/src/frontend/service/auth.service.ts
index 3081bbe7363..a33b0a28150 100644
--- a/src/frontend/service/auth.service.ts
+++ b/src/frontend/service/auth.service.ts
@@ -103,7 +103,7 @@ export class AuthService {
     }
 
     async logout(cleanUrl: boolean = true, forcePageLogin: boolean = false) {
-        if (['cas', 'keycloak'].indexOf(this.authMode) > -1 && !forcePageLogin) {
+        if (['cas', 'keycloak', 'azure_saml'].indexOf(this.authMode) > -1 && !forcePageLogin) {
             this.SsoLogout(cleanUrl);
         } else {
             // AVOID UNLOCK ON DESROY COMPONENT
diff --git a/src/lang/lang-fr.json b/src/lang/lang-fr.json
index ef04ea6351e..054815e0058 100644
--- a/src/lang/lang-fr.json
+++ b/src/lang/lang-fr.json
@@ -2112,6 +2112,7 @@
     "keycloakEnabled": "Authentification Keycloak activée",
     "ssoEnabled": "Authentification SSO activée",
     "casEnabled": "Authentification CAS activée",
+    "azure_samlEnabled": "Authentification Azure AD activée",
     "displayAsTechnicalData": "Afficher en tant que donnée technique",
     "displayInForm": "Afficher dans le formulaire",
     "formDescription": "Permet d'utiliser ce champ dans les modèles d'enregistrement",
-- 
GitLab