2009-10-31 02:33:01 +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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2020-05-08 15:49:36 +02:00
|
|
|
LSsession :: loadLSclass('LSlog_staticLoggerClass');
|
|
|
|
|
2009-10-31 02:33:01 +01:00
|
|
|
/**
|
2010-11-24 19:12:21 +01:00
|
|
|
* Base of a authentication provider for LSauth
|
2009-10-31 02:33:01 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
2020-05-08 15:49:36 +02:00
|
|
|
class LSauthMethod extends LSlog_staticLoggerClass {
|
2010-11-24 19:12:21 +01:00
|
|
|
|
2021-02-03 14:40:28 +01:00
|
|
|
protected $authData = array();
|
|
|
|
|
|
|
|
// Boolean flag to specify if this LSauthMethod support API mode
|
|
|
|
protected static $api_mode_supported = false;
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2019-03-12 11:42:53 +01:00
|
|
|
public function __construct() {
|
2020-05-07 11:34:44 +02:00
|
|
|
// Load config (without warning if not found)
|
|
|
|
$conf_file = LS_CONF_DIR."LSauth/config.".get_class($this).".php";
|
|
|
|
if (LSsession :: includeFile($conf_file, false, false))
|
2020-05-08 15:49:36 +02:00
|
|
|
self :: log_debug(get_class($this)." :: __construct(): config file ($conf_file) loaded");
|
2020-05-07 11:34:44 +02:00
|
|
|
else
|
2020-05-08 15:49:36 +02:00
|
|
|
self :: log_debug(get_class($this)." :: __construct(): config file ($conf_file) not found");
|
2019-03-12 11:42:53 +01:00
|
|
|
return true;
|
|
|
|
}
|
2010-11-24 19:12:21 +01:00
|
|
|
|
2009-10-31 02:33:01 +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
|
2009-10-31 02:33:01 +01:00
|
|
|
**/
|
2010-11-24 19:12:21 +01:00
|
|
|
public function getAuthData() {
|
|
|
|
// Do nothing in the standard LSauthMethod class
|
|
|
|
// This method have to define $this -> authData['username']
|
|
|
|
return false;
|
2009-10-31 02:33:01 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-31 02:33:01 +01:00
|
|
|
/**
|
2010-11-24 19:12:21 +01:00
|
|
|
* Check authentication
|
2009-10-31 02:33:01 +01:00
|
|
|
*
|
2020-04-29 15:54:21 +02:00
|
|
|
* @retval LSldapObject|false The LSldapObject of the user authificated or false
|
2009-10-31 02:33:01 +01:00
|
|
|
*/
|
|
|
|
public function authenticate() {
|
2020-05-12 19:23:24 +02:00
|
|
|
$authobjects = LSauth :: username2LSobjects($this -> authData['username']);
|
2020-08-19 15:11:49 +02:00
|
|
|
if (!$authobjects || !is_array($authobjects)) {
|
2020-05-12 19:23:24 +02:00
|
|
|
LSerror :: addErrorCode('LSauth_01');
|
|
|
|
self :: log_debug("No user found for provided username '".$this -> authData['username']."'");
|
2009-10-31 02:33:01 +01:00
|
|
|
}
|
2020-05-12 19:23:24 +02:00
|
|
|
elseif (count($authobjects) > 1) {
|
|
|
|
self :: log_debug('Multiple users match with provided username: '.implode(', ', array_keys($authobjects)));
|
|
|
|
LSerror :: addErrorCode('LSauth_02');
|
|
|
|
return false;
|
2009-10-31 02:33:01 +01:00
|
|
|
}
|
2020-05-12 19:23:24 +02:00
|
|
|
// Authentication succeeded
|
2020-05-12 20:59:21 +02:00
|
|
|
return array_pop($authobjects);
|
2009-10-31 02:33:01 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2010-11-24 19:12:21 +01:00
|
|
|
/**
|
|
|
|
* Logout
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2010-11-24 19:12:21 +01:00
|
|
|
* @retval boolean True on success or False
|
|
|
|
**/
|
|
|
|
public function logout() {
|
|
|
|
// Do nothing in the standard LSauthMethod class
|
|
|
|
return true;
|
|
|
|
}
|
2014-11-18 13:16:38 +01:00
|
|
|
|
2019-03-27 18:02:04 +01:00
|
|
|
/**
|
|
|
|
* After logout
|
|
|
|
*
|
|
|
|
* This method is run by LSsession after the local session was
|
|
|
|
* was successfully destroyed.
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
|
|
|
public static function afterLogout() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-18 13:16:38 +01:00
|
|
|
/**
|
|
|
|
* Get LDAP credentials
|
|
|
|
*
|
|
|
|
* Return LDAP credentials or false
|
|
|
|
*
|
|
|
|
* @params[in] $user The LSldapObject of the user authificated
|
|
|
|
*
|
|
|
|
* @retval Array|false Array of LDAP credentials array('dn','pwd') or False
|
|
|
|
**/
|
|
|
|
public function getLDAPcredentials($user) {
|
2019-03-12 11:42:53 +01:00
|
|
|
if (isset($this -> authData['password'])) {
|
|
|
|
return array(
|
|
|
|
'dn' => $user -> getDn(),
|
|
|
|
'pwd' => $this -> authData['password']
|
|
|
|
);
|
|
|
|
}
|
2014-11-18 13:16:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-11 22:42:20 +01:00
|
|
|
|
2021-02-03 14:40:28 +01:00
|
|
|
/**
|
|
|
|
* Check API mode support of this method
|
|
|
|
*
|
|
|
|
* @retval boolean True if API mode is support, false otherwise
|
|
|
|
*/
|
|
|
|
static public function apiModeSupported() {
|
|
|
|
return static :: $api_mode_supported;
|
|
|
|
}
|
|
|
|
|
2009-10-31 02:33:01 +01:00
|
|
|
}
|