2010-11-24 19:12:21 +01:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
LSsession :: loadLSclass('LSauthMethod_basic');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HTTP Authentication provider for LSauth
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
class LSauthMethod_HTTP extends LSauthMethod_basic {
|
|
|
|
|
2019-03-12 13:10:24 +01:00
|
|
|
public function __construct() {
|
2019-03-27 18:28:44 +01:00
|
|
|
parent :: __construct();
|
2019-03-12 11:42:53 +01:00
|
|
|
LSauth :: disableLoginForm();
|
2019-03-27 18:03:25 +01:00
|
|
|
if (!defined('LSAUTHMETHOD_HTTP_LOGOUT_REMOTE_URL'))
|
|
|
|
LSauth :: disableLogoutBtn();
|
2019-03-27 18:28:44 +01:00
|
|
|
return True;
|
2019-03-12 11:42:53 +01:00
|
|
|
}
|
2010-11-24 19:12:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check Auth Data
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2010-11-24 19:12:21 +01:00
|
|
|
* Return authentication data or false
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2010-11-24 19:12:21 +01:00
|
|
|
* @retval Array|false Array of authentication data or False
|
|
|
|
**/
|
|
|
|
public function getAuthData() {
|
2018-09-07 18:42:24 +02:00
|
|
|
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');
|
2010-11-24 19:12:21 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-21 11:24:51 +02:00
|
|
|
/**
|
|
|
|
* Check authentication
|
|
|
|
*
|
|
|
|
* @retval LSldapObject|false The LSldapObject of the user authificated or false
|
|
|
|
*/
|
|
|
|
public function authenticate() {
|
|
|
|
if ( (defined('LSAUTHMETHOD_HTTP_TRUST_WITHOUT_PASSWORD_CHALLENGE')) && (constant('LSAUTHMETHOD_HTTP_TRUST_WITHOUT_PASSWORD_CHALLENGE') === True)) {
|
|
|
|
// Return authObject without checking login/password by LDAP auth challenge
|
|
|
|
return LSauthMethod :: authenticate();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return parent :: authenticate();
|
|
|
|
}
|
|
|
|
}
|
2010-11-24 19:12:21 +01:00
|
|
|
|
2019-03-27 18:03:25 +01:00
|
|
|
/**
|
|
|
|
* After logout
|
|
|
|
*
|
|
|
|
* This method is run by LSsession after the local session was
|
|
|
|
* was successfully destroyed.
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
|
|
|
public static function afterLogout() {
|
|
|
|
if (defined('LSAUTHMETHOD_HTTP_LOGOUT_REMOTE_URL')) {
|
|
|
|
LSsession :: redirect(LSAUTHMETHOD_HTTP_LOGOUT_REMOTE_URL);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-21 11:24:51 +02:00
|
|
|
}
|
2018-09-07 18:42:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Error Codes
|
|
|
|
*/
|
|
|
|
LSerror :: defineError('LSauthMethod_HTTP_01',
|
|
|
|
_("LSauthMethod_HTTP : the %{var} environnement variable is missing.")
|
|
|
|
);
|