From c551b954fe331408a6e08d5d45cc3f55fcda02bf Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 7 Sep 2018 18:42:24 +0200 Subject: [PATCH] Improve LSauthMethod::HTTP to support multiple methods to retreive user and password from HTTP server --- .../LSauthMethod/LSauthMethod_HTTP.docbook | 54 ++++++++++++++++++ .../conf/LSauth/config.LSauthMethod_HTTP.php | 18 ++++++ .../class/class.LSauthMethod_HTTP.php | 53 +++++++++++++++-- .../lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo | Bin 45446 -> 45598 bytes .../lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po | 8 ++- public_html/lang/ldapsaisie.pot | 6 +- 6 files changed, 130 insertions(+), 9 deletions(-) diff --git a/doc/conf/LSauthMethod/LSauthMethod_HTTP.docbook b/doc/conf/LSauthMethod/LSauthMethod_HTTP.docbook index a924dbb0..513374d6 100644 --- a/doc/conf/LSauthMethod/LSauthMethod_HTTP.docbook +++ b/doc/conf/LSauthMethod/LSauthMethod_HTTP.docbook @@ -46,5 +46,59 @@ + + LSAUTHMETHOD_HTTP_METHOD + + Permet de définir la méthode utilisée par le serveur HTTP pour + passer à PHP l'identifiant de l'utilisateur connecté et son mot de passe. + Cette constance peut pendre les valeurs suivantes : + + + + PHP_PASS + + Dans cette méthode, le serveur HTTP défini les variables + d'environnement PHP_AUTH_USER et + PHP_AUTH_PW. Cette méthode est la méthode par défaut et + convient en cas d'utilisation de mod_php. + + + + + REMOTE_USER + + Dans cette méthode, le serveur HTTP défini la variable + d'environnement REMOTE_USER. Cette variable ne contient + que l'identifiant de l'utilisateur connecté. Cette méthode ne peut donc + être utilisée que conjointement avec l'activation du paramètre + LSAUTHMETHOD_HTTP_TRUST_WITHOUT_PASSWORD_CHALLENGE. + + + + + + AUTHORIZATION + + Dans cette méthode, le serveur HTTP passe le contenu de l'entête + HTTP Authorization dans la variable d'environnement + HTTP_AUTHORIZATION. Cette méthode convient en cas d' + utilisation de PHP en mode CGI ou encore via PHP-FPM. Pour utiliser cette + méthode, il faudra adapter la configuration du serveur HTTP. Par exemple, + pour Apache HTTPd, vous pouvez utiliser le module rewrite + et la règle de réécriture suivante : + + + + + + + + + + + + + + diff --git a/public_html/conf/LSauth/config.LSauthMethod_HTTP.php b/public_html/conf/LSauth/config.LSauthMethod_HTTP.php index 8166b1c0..815647b6 100644 --- a/public_html/conf/LSauth/config.LSauthMethod_HTTP.php +++ b/public_html/conf/LSauth/config.LSauthMethod_HTTP.php @@ -28,3 +28,21 @@ // Don't check HTTP server's login/password by LDAP authentication challenge //define('LSAUTHMETHOD_HTTP_TRUST_WITHOUT_PASSWORD_CHALLENGE',true); + +/* + * Set the HTTP server's method to pass authentifcated user/password informations + * to PHP : + * - PHP_PASS : server define the PHP_AUTH_USER and PHP_AUTH_PW environnement + * variables. This is the default way using mod_php. + * - REMOTE_USER : server define the REMOTE_USER environnement variable. By using + * this method, only the user is pass by HTTP server to PHP and it + * could be only used if you enable the "don't check HTTP server's + * login/password by LDAP authentication challenge" option. + * - AUTHORIZATION : server pass HTTP Authorization header value to PHP by setting + * the HTTP_AUTHORIZATION environnement variable. This way could + * be use when using PHP in CGI-mode or with PHP-FPM. When using + * Apache, you could pass this information by using the rewrite module + * and setting the following rewrite rule : + * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] + */ +//define('LSAUTHMETHOD_HTTP_METHOD', 'PHP_PASS'); diff --git a/public_html/includes/class/class.LSauthMethod_HTTP.php b/public_html/includes/class/class.LSauthMethod_HTTP.php index 5f0be440..9d73ee77 100644 --- a/public_html/includes/class/class.LSauthMethod_HTTP.php +++ b/public_html/includes/class/class.LSauthMethod_HTTP.php @@ -43,12 +43,46 @@ class LSauthMethod_HTTP extends LSauthMethod_basic { * @retval Array|false Array of authentication data or False **/ public function getAuthData() { - if (isset($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_USER'])) { - $this -> authData = array( - 'username' => $_SERVER['PHP_AUTH_USER'], - 'password' => $_SERVER['PHP_AUTH_PW'] - ); - return $this -> authData; + if (!defined('LSAUTHMETHOD_HTTP_METHOD')) + define('LSAUTHMETHOD_HTTP_METHOD', 'PHP_AUTH'); + + switch(constant('LSAUTHMETHOD_HTTP_METHOD')) { + case 'AUTHORIZATION': + if (isset($_SERVER['HTTP_AUTHORIZATION']) && !empty($_SERVER['HTTP_AUTHORIZATION'])) { + $authData = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); + if (is_array($authData) && count($authData) == 2) { + $this -> authData = array( + 'username' => $authData[0], + 'password' => $authData[1], + ); + } + return $this -> authData; + } + else + LSerror :: addErrorCode('LSauthMethod_HTTP_01', 'HTTP_AUTHORIZATION'); + break; + case 'REMOTE_USER': + if (isset($_SERVER['REMOTE_USER']) && !empty($_SERVER['REMOTE_USER'])) { + $this -> authData = array( + 'username' => $_SERVER['REMOTE_USER'], + 'password' => false, + ); + return $this -> authData; + } + else + LSerror :: addErrorCode('LSauthMethod_HTTP_01', 'REMOTE_USER'); + break; + case 'PHP_AUTH': + default: + if (isset($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_USER'])) { + $this -> authData = array( + 'username' => $_SERVER['PHP_AUTH_USER'], + 'password' => $_SERVER['PHP_AUTH_PW'], + ); + return $this -> authData; + } + else + LSerror :: addErrorCode('LSauthMethod_HTTP_01', 'PHP_AUTH_USER'); } return; } @@ -69,3 +103,10 @@ class LSauthMethod_HTTP extends LSauthMethod_basic { } } + +/* + * Error Codes + */ +LSerror :: defineError('LSauthMethod_HTTP_01', +_("LSauthMethod_HTTP : the %{var} environnement variable is missing.") +); diff --git a/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo b/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo index 4341af97b32d138d84be5fedbceb0f32e2bc82d7..4ec632f5d8b23ddfc6a198b9024f13c9c41eb054 100644 GIT binary patch delta 7219 zcmY+}3w(}sAII^3Gu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@eo~%g+o-2}l&B!uYL8)!QXu~`+w)M-MSYz3b=f2Jit1TV<(n}ktEr>r&Aar2 zdPOb2R%=d!ZFN#EYOLQq~TED2++bn%A;!&&n{?DOkC_WV5h~{Od)GwNFxTD4| zHD;7XJVXr7=WY3m_7lpFW*g!>^=tBZ?A$1qh}c}ui2h}-)^CurM$(lc%JUiNMV963 z-ST&c(QB2j?@<4%_(FUn4whOfzZL&`up#dx{!SF;zyB-sZQ_-9s6VI-aNzHZvP)Ey z$7}YiXi&z=56geK1LGAPHM@5Yo)S>wc z->YGfI3NaTD-nIgvH9bdX^%zQL%x`Ih<)N{`J0TlX-zRq{tq536IEJjJ6Npw)I{Em zkHniL{;C}z-PtlBHj%biYLYAqM_s6MU)Y& zmak_m*-NTyZ^MFICkJjg*vez%mBgp&wYZ8kIGs^Cs`uww@fXomzL^(`YekgXMSblp zM7%4av{4@{qAV8`%4_}s-9Y1ak~75>Sz~&ayG3#S3pc8-5Fd*#MZ7^v^T%#eKUhxB zS5}v8YgClGIiEe9_pZD*^b3Uh#oASZ-BmR(7CqgWOAMbzJl(o+6fr7sRFF zKcZOlalC}B#gAgPh*BgT673>Uj&fcdt}M^|q{_FbKc3IG@^AV2%*?^*Pb!tf6QZXW zBTg1?h^nHOi*#jY4(7KaO8jrMIjmXsW>LGA{bUErkt+4%@32(7CLY_`v`MdeTi2F! n>s+mOr|u;!N=o~5?Opc9v}XU8mUP|v!?c}^x7NO>M(KY6?v|zw diff --git a/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po b/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po index 0eda1293..dcaeb4d9 100644 --- a/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po +++ b/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: LdapSaisie\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-31 17:08+0200\n" -"PO-Revision-Date: 2018-08-31 17:10+0200\n" +"POT-Creation-Date: 2018-09-07 18:40+0200\n" +"PO-Revision-Date: 2018-09-07 18:41+0200\n" "Last-Translator: Benjamin Renard \n" "Language-Team: LdapSaisie \n" @@ -1426,6 +1426,10 @@ msgstr "Afficher la fenêtre de recherche et de sélection étendue." msgid "Invalid value" msgstr "Valeur invalide" +#: includes/class/class.LSauthMethod_HTTP.php:111 +msgid "LSauthMethod_HTTP : the %{var} environnement variable is missing." +msgstr "LSauthMethod_HTTP : la variable d'environnement %{var} est manquante." + #: includes/class/class.LSformElement_mail.php:51 msgid "Send a mail from here." msgstr "Envoyer un mail depuis l'interface." diff --git a/public_html/lang/ldapsaisie.pot b/public_html/lang/ldapsaisie.pot index 15754197..e5b1870d 100644 --- a/public_html/lang/ldapsaisie.pot +++ b/public_html/lang/ldapsaisie.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-31 17:07+0200\n" +"POT-Creation-Date: 2018-09-07 18:40+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1215,6 +1215,10 @@ msgstr "" msgid "Invalid value" msgstr "" +#: includes/class/class.LSauthMethod_HTTP.php:111 +msgid "LSauthMethod_HTTP : the %{var} environnement variable is missing." +msgstr "" + #: includes/class/class.LSformElement_mail.php:51 msgid "Send a mail from here." msgstr ""