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;
35 'displayLoginForm' => true,
36 'displayLogoutBtn' => true
42 * @retval boolean True if post data permit the authentification or False
44 public function getPostData() {
45 if (isset($_POST['LSsession_user']) && !empty($_POST['LSsession_user'])) {
46 $this -> authData = array(
47 'username' => $_POST['LSsession_user'],
48 'password' => $_POST['LSsession_pwd'],
49 'ldapserver' => $_POST['LSsession_ldapserver'],
50 'topDn' => $_POST['LSsession_topDn']
60 * @param[in] $username The username
61 * @param[in] $password The password
63 * @retval LSldapObject|false The LSldapObject of the user authificated or false
65 public function authenticate() {
66 if (LSsession :: loadLSobject(LSsession :: $ldapServer['authObjectType'])) {
67 $authobject = new LSsession :: $ldapServer['authObjectType']();
68 $result = $authobject -> searchObject(
69 $this -> authData['username'],
70 LSsession :: getTopDn(),
71 LSsession :: $ldapServer['authObjectFilter']
73 $nbresult=count($result);
76 // identifiant incorrect
77 LSdebug('identifiant incorrect');
78 LSerror :: addErrorCode('LSauth_01');
80 else if ($nbresult>1) {
81 // duplication d'authentité
82 LSerror :: addErrorCode('LSauth_02');
84 elseif ( $this -> checkUserPwd($result[0],$this -> authData['password']) ) {
85 // Authentication succeeded
89 LSerror :: addErrorCode('LSauth_01');
90 LSdebug('mdp incorrect');
94 LSerror :: addErrorCode('LSauth_03');
100 * Test un couple LSobject/pwd
102 * Test un bind sur le serveur avec le dn de l'objet et le mot de passe fourni.
104 * @param[in] LSobject L'object "user" pour l'authentification
105 * @param[in] string Le mot de passe à tester
107 * @retval boolean True si l'authentification à réussi, false sinon.
109 public static function checkUserPwd($object,$pwd) {
110 return LSldap :: checkBind($object -> getValue('dn'),$pwd);
114 * Define if login form can be displayed or not
118 public function __get($key) {
119 if ($key=='params') {
120 return $this -> params;
130 LSerror :: defineError('LSauth_01',
131 _("LSauth : Login or password incorrect.")
133 LSerror :: defineError('LSauth_02',
134 _("LSauth : Impossible to identify you : Duplication of identities.")
136 LSerror :: defineError('LSauth_03',
137 _("LSsession : Could not load type of identifiable objects.")