2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
24 * Gestion de l'authentification d'un utilisateur
26 * Cette classe gere l'authentification des utilisateurs à l'interface
28 * @author Benjamin Renard <brenard@easter-eggs.com>
32 static private $authData=NULL;
33 static private $authObject=NULL;
34 static private $config=array();
35 static private $provider=NULL;
37 static private $params = array (
38 'displayLoginForm' => true,
39 'displayLogoutBtn' => true
43 LSdebug('LSauth :: start()');
45 if (isset(LSsession :: $ldapServer['LSauth']) && is_array(LSsession :: $ldapServer['LSauth'])) {
46 self :: $config = LSsession :: $ldapServer['LSauth'];
48 if (!LSsession :: loadLSclass('LSauthMethod')) {
49 LSdebug('LSauth :: Failed to load LSauthMethod');
52 if (!isset(self :: $config['method'])) {
53 self :: $config['method']='basic';
55 $class='LSauthMethod_'.self :: $config['method'];
56 LSdebug('LSauth : provider -> '.$class);
57 if (LSsession :: loadLSclass($class)) {
58 self :: $provider = new $class();
59 if (!self :: $provider) {
60 LSerror :: addErrorCode('LSauth_05',self :: $config['method']);
62 LSdebug('LSauth : Provider Started !');
66 LSerror :: addErrorCode('LSauth_04',self :: $config['method']);
71 function forceAuthentication() {
72 LSdebug('LSauth :: forceAuthentication()');
73 if (!is_null(self :: $provider)) {
74 self :: $authData = self :: $provider -> getAuthData();
75 if (self :: $authData) {
76 self :: $authObject = self :: $provider -> authenticate();
77 return self :: $authObject;
79 // No data : user has not filled the login form
80 LSdebug('LSauth : No data -> user has not filled the login form');
83 LSerror :: addErrorCode('LSauth_06');
92 public function logout() {
93 if (!is_null(self :: $provider)) {
94 return self :: $provider -> logout();
96 LSerror :: addErrorCode('LSauth_06');
101 * Disable logout button in LSauth parameters
105 public function disableLogoutBtn() {
106 self :: $params['displayLogoutBtn'] = false;
110 * Can display or not logout button in LSauth parameters
114 public function displayLogoutBtn() {
115 return self :: $params['displayLogoutBtn'];
119 * For compatibillity until loginForm is migrated in LSauth
121 public function disableLoginForm() {
122 self :: $params['displayLoginForm'] = false;
125 public function displayLoginForm() {
126 return self :: $params['displayLoginForm'];
135 LSerror :: defineError('LSauth_01',
136 _("LSauth : Login or password incorrect.")
138 LSerror :: defineError('LSauth_02',
139 _("LSauth : Impossible to identify you : Duplication of identities.")
141 LSerror :: defineError('LSauth_03',
142 _("LSauth : Could not load type of identifiable objects.")
144 LSerror :: defineError('LSauth_04',
145 _("LSauth : Can't load authentication method %{method}.")
147 LSerror :: defineError('LSauth_05',
148 _("LSauth : Failed to build the authentication provider %{method}.")
150 LSerror :: defineError('LSauth_06',
151 _("LSauth : Not correctly initialized.")
153 LSerror :: defineError('LSauth_07',
154 _("LSauth : Failed to get authentication informations from provider.")