ldapsaisie/public_html/includes/class/class.LSauth.php

203 lines
5.4 KiB
PHP
Raw Normal View History

- LSsearch/LSsearchEntry : Added a new classes to doing and exploit ldap object search -> view/select => change to use it (php+template+js) -> LSattr_html_select_object/LSattr_html_select_list => change to use it -> LSldapObject : -> change listObjectsName() / searchObject() / getSelectArray() / listObjects() -> comment search() function -> Add triggers to clean cache -> LSpeople : Update search config -> LSsession : Change function to use it : - getSubDnLdapServer() - loadLSprofiles() - LSrelation : Deplace error codes declaration from LSsession in class file - LSldapObject : -> change getObjectFilter() / getLabel() / getSubDnValue() / getSubDnName() for can call then staticaly -> Add afterModify() function and trigger -> Change getObjectFilter() / listObjectsInRelation() to use Net_LDAP2_Filter -> Add __get() function -> Move one LSerror code for LSrelation function from LSsession class file -> Add a global variable to save cached data ($cache) -> Change subDn and subDnName access methods - LSauth : Move LSsession auth procedure in a dedicated class -> LSsession : Change startLSsession() to use it - LSsession : -> Add getRootDn() function -> Fix getTopDn() to return root DN if no topDn is currently defined -> Create dedicated functions to support recoveryPassword mecanism : - recoverPasswd() - recoverPasswdSendMail() - recoverPasswdFirstStep() - recoverPasswdSecondStep -> Customize LSdebug return and display (php+js) -> Clean unused error codes -> Move LSrelation error codes -> Comment ajax method
2009-10-30 01:03:17 +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.
******************************************************************************/
/**
* Gestion de l'authentification d'un utilisateur
*
2020-04-29 15:54:21 +02:00
* Cette classe gere l'authentification des utilisateurs <20> l'interface
- LSsearch/LSsearchEntry : Added a new classes to doing and exploit ldap object search -> view/select => change to use it (php+template+js) -> LSattr_html_select_object/LSattr_html_select_list => change to use it -> LSldapObject : -> change listObjectsName() / searchObject() / getSelectArray() / listObjects() -> comment search() function -> Add triggers to clean cache -> LSpeople : Update search config -> LSsession : Change function to use it : - getSubDnLdapServer() - loadLSprofiles() - LSrelation : Deplace error codes declaration from LSsession in class file - LSldapObject : -> change getObjectFilter() / getLabel() / getSubDnValue() / getSubDnName() for can call then staticaly -> Add afterModify() function and trigger -> Change getObjectFilter() / listObjectsInRelation() to use Net_LDAP2_Filter -> Add __get() function -> Move one LSerror code for LSrelation function from LSsession class file -> Add a global variable to save cached data ($cache) -> Change subDn and subDnName access methods - LSauth : Move LSsession auth procedure in a dedicated class -> LSsession : Change startLSsession() to use it - LSsession : -> Add getRootDn() function -> Fix getTopDn() to return root DN if no topDn is currently defined -> Create dedicated functions to support recoveryPassword mecanism : - recoverPasswd() - recoverPasswdSendMail() - recoverPasswdFirstStep() - recoverPasswdSecondStep -> Customize LSdebug return and display (php+js) -> Clean unused error codes -> Move LSrelation error codes -> Comment ajax method
2009-10-30 01:03:17 +01:00
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSauth {
2020-04-29 15:54:21 +02:00
static private $authData=NULL;
static private $authObject=NULL;
static private $config=array();
static private $provider=NULL;
2020-04-29 15:54:21 +02:00
static private $params = array (
'displayLoginForm' => true,
'displayLogoutBtn' => true,
'displaySelfAccess' => true
);
public static function start() {
LSdebug('LSauth :: start()');
// Load Config
if (isset(LSsession :: $ldapServer['LSauth']) && is_array(LSsession :: $ldapServer['LSauth'])) {
self :: $config = LSsession :: $ldapServer['LSauth'];
}
if (!LSsession :: loadLSclass('LSauthMethod')) {
LSdebug('LSauth :: Failed to load LSauthMethod');
return;
}
if (!isset(self :: $config['method'])) {
self :: $config['method']='basic';
}
$class='LSauthMethod_'.self :: $config['method'];
LSdebug('LSauth : provider -> '.$class);
if (LSsession :: loadLSclass($class)) {
self :: $provider = new $class();
if (!self :: $provider) {
LSerror :: addErrorCode('LSauth_05',self :: $config['method']);
- LSsearch/LSsearchEntry : Added a new classes to doing and exploit ldap object search -> view/select => change to use it (php+template+js) -> LSattr_html_select_object/LSattr_html_select_list => change to use it -> LSldapObject : -> change listObjectsName() / searchObject() / getSelectArray() / listObjects() -> comment search() function -> Add triggers to clean cache -> LSpeople : Update search config -> LSsession : Change function to use it : - getSubDnLdapServer() - loadLSprofiles() - LSrelation : Deplace error codes declaration from LSsession in class file - LSldapObject : -> change getObjectFilter() / getLabel() / getSubDnValue() / getSubDnName() for can call then staticaly -> Add afterModify() function and trigger -> Change getObjectFilter() / listObjectsInRelation() to use Net_LDAP2_Filter -> Add __get() function -> Move one LSerror code for LSrelation function from LSsession class file -> Add a global variable to save cached data ($cache) -> Change subDn and subDnName access methods - LSauth : Move LSsession auth procedure in a dedicated class -> LSsession : Change startLSsession() to use it - LSsession : -> Add getRootDn() function -> Fix getTopDn() to return root DN if no topDn is currently defined -> Create dedicated functions to support recoveryPassword mecanism : - recoverPasswd() - recoverPasswdSendMail() - recoverPasswdFirstStep() - recoverPasswdSecondStep -> Customize LSdebug return and display (php+js) -> Clean unused error codes -> Move LSrelation error codes -> Comment ajax method
2009-10-30 01:03:17 +01:00
}
LSdebug('LSauth : Provider Started !');
return true;
- LSsearch/LSsearchEntry : Added a new classes to doing and exploit ldap object search -> view/select => change to use it (php+template+js) -> LSattr_html_select_object/LSattr_html_select_list => change to use it -> LSldapObject : -> change listObjectsName() / searchObject() / getSelectArray() / listObjects() -> comment search() function -> Add triggers to clean cache -> LSpeople : Update search config -> LSsession : Change function to use it : - getSubDnLdapServer() - loadLSprofiles() - LSrelation : Deplace error codes declaration from LSsession in class file - LSldapObject : -> change getObjectFilter() / getLabel() / getSubDnValue() / getSubDnName() for can call then staticaly -> Add afterModify() function and trigger -> Change getObjectFilter() / listObjectsInRelation() to use Net_LDAP2_Filter -> Add __get() function -> Move one LSerror code for LSrelation function from LSsession class file -> Add a global variable to save cached data ($cache) -> Change subDn and subDnName access methods - LSauth : Move LSsession auth procedure in a dedicated class -> LSsession : Change startLSsession() to use it - LSsession : -> Add getRootDn() function -> Fix getTopDn() to return root DN if no topDn is currently defined -> Create dedicated functions to support recoveryPassword mecanism : - recoverPasswd() - recoverPasswdSendMail() - recoverPasswdFirstStep() - recoverPasswdSecondStep -> Customize LSdebug return and display (php+js) -> Clean unused error codes -> Move LSrelation error codes -> Comment ajax method
2009-10-30 01:03:17 +01:00
}
else {
LSerror :: addErrorCode('LSauth_04',self :: $config['method']);
return;
}
}
2020-04-29 15:54:21 +02:00
public static function forceAuthentication() {
LSdebug('LSauth :: forceAuthentication()');
if (!is_null(self :: $provider)) {
self :: $authData = self :: $provider -> getAuthData();
if (self :: $authData) {
self :: $authObject = self :: $provider -> authenticate();
return self :: $authObject;
}
// No data : user has not filled the login form
LSdebug('LSauth : No data -> user has not filled the login form');
return;
}
LSerror :: addErrorCode('LSauth_06');
return;
}
/**
* 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 static function getLDAPcredentials($user) {
return self :: $provider -> getLDAPcredentials($user);
}
2010-03-10 19:06:42 +01:00
/**
* Logout
2020-04-29 15:54:21 +02:00
*
2010-03-10 19:06:42 +01:00
* @retval void
**/
public static function logout() {
2019-03-27 18:02:04 +01:00
if (!is_null(self :: $provider)) {
return self :: $provider -> logout();
}
LSerror :: addErrorCode('LSauth_06');
return;
}
/**
* After logout
*
* This method is run by LSsession after the local session was
* was successfully destroyed.
*
* @retval void
**/
public static function afterLogout() {
if (!is_null(self :: $provider)) {
return self :: $provider -> afterLogout();
}
LSerror :: addErrorCode('LSauth_06');
return;
2010-03-10 19:06:42 +01:00
}
/**
* Disable logout button in LSauth parameters
2020-04-29 15:54:21 +02:00
*
* @retval void
**/
public static function disableLogoutBtn() {
self :: $params['displayLogoutBtn'] = false;
}
/**
* Can display or not logout button in LSauth parameters
2020-04-29 15:54:21 +02:00
*
* @retval boolean
**/
public static function displayLogoutBtn() {
return self :: $params['displayLogoutBtn'];
}
2020-04-29 15:54:21 +02:00
/**
* Disable self access
*
* @retval void
**/
public static function disableSelfAccess() {
self :: $params['displaySelfAccess'] = false;
}
/**
* Can display or not self access
*
* @retval boolean
**/
public static function displaySelfAccess() {
return self :: $params['displaySelfAccess'];
}
/*
* For compatibillity until loginForm is migrated in LSauth
*/
public static function disableLoginForm() {
2019-03-11 22:42:20 +01:00
self :: $params['displayLoginForm'] = false;
}
public static function displayLoginForm() {
2019-03-11 22:42:20 +01:00
return self :: $params['displayLoginForm'];
}
- LSsearch/LSsearchEntry : Added a new classes to doing and exploit ldap object search -> view/select => change to use it (php+template+js) -> LSattr_html_select_object/LSattr_html_select_list => change to use it -> LSldapObject : -> change listObjectsName() / searchObject() / getSelectArray() / listObjects() -> comment search() function -> Add triggers to clean cache -> LSpeople : Update search config -> LSsession : Change function to use it : - getSubDnLdapServer() - loadLSprofiles() - LSrelation : Deplace error codes declaration from LSsession in class file - LSldapObject : -> change getObjectFilter() / getLabel() / getSubDnValue() / getSubDnName() for can call then staticaly -> Add afterModify() function and trigger -> Change getObjectFilter() / listObjectsInRelation() to use Net_LDAP2_Filter -> Add __get() function -> Move one LSerror code for LSrelation function from LSsession class file -> Add a global variable to save cached data ($cache) -> Change subDn and subDnName access methods - LSauth : Move LSsession auth procedure in a dedicated class -> LSsession : Change startLSsession() to use it - LSsession : -> Add getRootDn() function -> Fix getTopDn() to return root DN if no topDn is currently defined -> Create dedicated functions to support recoveryPassword mecanism : - recoverPasswd() - recoverPasswdSendMail() - recoverPasswdFirstStep() - recoverPasswdSecondStep -> Customize LSdebug return and display (php+js) -> Clean unused error codes -> Move LSrelation error codes -> Comment ajax method
2009-10-30 01:03:17 +01:00
}
/*
* Error Codes
*/
LSerror :: defineError('LSauth_01',
_("LSauth : Login or password incorrect.")
);
LSerror :: defineError('LSauth_02',
_("LSauth : Impossible to identify you : Duplication of identities.")
);
LSerror :: defineError('LSauth_03',
_("LSauth : Could not load type of identifiable objects.")
);
LSerror :: defineError('LSauth_04',
_("LSauth : Can't load authentication method %{method}.")
- LSsearch/LSsearchEntry : Added a new classes to doing and exploit ldap object search -> view/select => change to use it (php+template+js) -> LSattr_html_select_object/LSattr_html_select_list => change to use it -> LSldapObject : -> change listObjectsName() / searchObject() / getSelectArray() / listObjects() -> comment search() function -> Add triggers to clean cache -> LSpeople : Update search config -> LSsession : Change function to use it : - getSubDnLdapServer() - loadLSprofiles() - LSrelation : Deplace error codes declaration from LSsession in class file - LSldapObject : -> change getObjectFilter() / getLabel() / getSubDnValue() / getSubDnName() for can call then staticaly -> Add afterModify() function and trigger -> Change getObjectFilter() / listObjectsInRelation() to use Net_LDAP2_Filter -> Add __get() function -> Move one LSerror code for LSrelation function from LSsession class file -> Add a global variable to save cached data ($cache) -> Change subDn and subDnName access methods - LSauth : Move LSsession auth procedure in a dedicated class -> LSsession : Change startLSsession() to use it - LSsession : -> Add getRootDn() function -> Fix getTopDn() to return root DN if no topDn is currently defined -> Create dedicated functions to support recoveryPassword mecanism : - recoverPasswd() - recoverPasswdSendMail() - recoverPasswdFirstStep() - recoverPasswdSecondStep -> Customize LSdebug return and display (php+js) -> Clean unused error codes -> Move LSrelation error codes -> Comment ajax method
2009-10-30 01:03:17 +01:00
);
LSerror :: defineError('LSauth_05',
_("LSauth : Failed to build the authentication provider %{method}.")
);
LSerror :: defineError('LSauth_06',
_("LSauth : Not correctly initialized.")
);
LSerror :: defineError('LSauth_07',
_("LSauth : Failed to get authentication informations from provider.")
);