From d395d1d41a99a510d7630af664f2c68e275e084c Mon Sep 17 00:00:00 2001
From: ArmandBahi <armand.bahi@veremes.com>
Date: Wed, 24 Oct 2018 18:58:49 +0200
Subject: [PATCH] =?UTF-8?q?Probl=C3=A8me=20lors=20de=20l'enregistrement=20?=
 =?UTF-8?q?de=20services=20avec=20mots=20de=20passe?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 module/javascript/vitis/script_module.js | 27 ++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/module/javascript/vitis/script_module.js b/module/javascript/vitis/script_module.js
index f14e1f32..00d7bea3 100644
--- a/module/javascript/vitis/script_module.js
+++ b/module/javascript/vitis/script_module.js
@@ -915,7 +915,9 @@ vitisApp.on('appMainDrtvLoaded', function () {
         }
 
         this['getCapabilities'](serviceUrl, {
-            'version': serviceVersion
+            'version': serviceVersion,
+            'service_login': envSrvc["oFormValues"][envSrvc['sFormDefinitionName']]['service_login'],
+            'service_password': envSrvc["oFormValues"][envSrvc['sFormDefinitionName']]['service_password']
         }).then(function (oResult) {
             if (goog.isDefAndNotNull(oResult)) {
                 if (goog.isDefAndNotNull(oResult['json'])) {
@@ -1098,6 +1100,12 @@ vitisApp.on('appMainDrtvLoaded', function () {
                 if (goog.isDefAndNotNull(scope['oServices'][sServiceId]['service_type_version'])) {
                     envSrvc["oFormValues"][envSrvc['sFormDefinitionName']]["service_type_version"] = scope['oServices'][sServiceId]['service_type_version'];
                 }
+                if (goog.isDefAndNotNull(scope['oServices'][sServiceId]['service_login'])) {
+                    envSrvc["oFormValues"][envSrvc['sFormDefinitionName']]["service_login"] = scope['oServices'][sServiceId]['service_login'];
+                }
+                if (goog.isDefAndNotNull(scope['oServices'][sServiceId]['service_password'])) {
+                    envSrvc["oFormValues"][envSrvc['sFormDefinitionName']]["service_password"] = scope['oServices'][sServiceId]['service_password'];
+                }
             }
         } else {
             sServiceType = envSrvc['oFormValues'][envSrvc['sFormDefinitionName']]['service_type_id'];
@@ -2497,11 +2505,15 @@ vitisApp.on('appMainDrtvLoaded', function () {
 
         $translate(["BTN_ADD_LAYERS_VMAP_MAP_LAYER"]).then(function (oTranslations) {
             var sServiceUrl = envSrvc["oFormValues"][sParentFormDefinitionName]["service_url"];
+            var sServiceLogin = envSrvc["oFormValues"][sParentFormDefinitionName]["service_login"];
+            var sServicePassword = envSrvc["oFormValues"][sParentFormDefinitionName]["service_password"];
             var sVersion = envSrvc["oFormValues"][sParentFormDefinitionName]["service_type_version"];
             sServiceUrl = sServiceUrl.replace("[token]", sha256(sessionSrvc["token"]));
             sServiceUrl = sServiceUrl.replace("[ms_cgi_url]", propertiesSrvc["ms_cgi_url"]);
             this_['showLayerModalWindow']({
                 'service_url': sServiceUrl,
+                'service_login': sServiceLogin,
+                'service_password': sServicePassword,
                 'service_version': sVersion,
                 'buttons': [{
                         "label": oTranslations["BTN_ADD_LAYERS_VMAP_MAP_LAYER"],
@@ -2874,7 +2886,9 @@ vitisApp.on('appMainDrtvLoaded', function () {
         } else if (goog.isDefAndNotNull(sServiceUrl)) {
             // Calques du service wms.
             scope.$root['getCapabilities'](sServiceUrl, {
-                'version': opt_options['service_version']
+                'version': opt_options['service_version'],
+                'service_login': opt_options['service_login'],
+                'service_password': opt_options['service_password']
             }).then(function (oGetCapabilities) {
                 oCapabilities = oGetCapabilities;
                 if (goog.isDefAndNotNull(oCapabilities)) {
@@ -2906,6 +2920,9 @@ vitisApp.on('appMainDrtvLoaded', function () {
             "showErrorMessage": true,
             "version": "1.3.0"
         };
+        var oHeaders = {
+            "charset": "charset=utf-8"
+        };
         if (typeof (oOptions) == "undefined")
             oOptions = oDefaultOptions;
         else {
@@ -2918,6 +2935,11 @@ vitisApp.on('appMainDrtvLoaded', function () {
         if (!goog.isDefAndNotNull(oOptions['showErrorMessage'])) {
             oOptions['showErrorMessage'] = true;
         }
+        if (goog.isDefAndNotNull(oOptions['service_login']) && goog.isDefAndNotNull(oOptions['service_password'])) {
+            if (oOptions['service_login'].length > 0 && oOptions['service_password'].length > 0) {
+                oHeaders['Authorization'] = "Basic " + btoa(oOptions['service_login'] + ":" + oOptions['service_password']);
+            }
+        }
         // Création de l'url vers le service.
         if (sServiceUrl.indexOf("?") === -1)
             sServiceUrl += "?";
@@ -2941,6 +2963,7 @@ vitisApp.on('appMainDrtvLoaded', function () {
                 "method": "GET",
                 "url": propertiesSrvc['proxy_url'],
                 "params": {"url": sServiceUrl},
+                'headers': oHeaders,
                 "scope": scope,
                 "responseType": "text",
                 "success": function (response) {
-- 
GitLab