Add NAMESPACE support (not activated, but just needed to add the namespace on top of file)
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4630 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
27
authldap.php
27
authldap.php
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
/** DomFramework
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
require_once ("domframework/auth.php");
|
||||
|
||||
@@ -36,7 +37,7 @@ class authldap extends auth
|
||||
function __construct ()
|
||||
{
|
||||
if (!function_exists ("ldap_connect"))
|
||||
throw new Exception ("LDAP support unavailable in PHP", 500);
|
||||
throw new \Exception ("LDAP support unavailable in PHP", 500);
|
||||
}
|
||||
|
||||
/** Establish a connection to a LDAP server
|
||||
@@ -46,13 +47,13 @@ class authldap extends auth
|
||||
{
|
||||
$this->ldapconn = ldap_connect ($this->ldapserver, $this->ldapport);
|
||||
if (!$this->ldapconn)
|
||||
throw new Exception ("Can't contact LDAP server", 500);
|
||||
throw new \Exception ("Can't contact LDAP server", 500);
|
||||
|
||||
ldap_set_option ($this->ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
ldap_set_option($this->ldapconn, LDAP_OPT_TIMELIMIT, $this->ldaptimeout);
|
||||
$ldapbind = @ldap_bind ($this->ldapconn, $this->ldapauth, $this->ldappwd);
|
||||
if (ldap_errno ($this->ldapconn) !== 0)
|
||||
throw new Exception ("Authentication error in pre-auth LDAP", 500);
|
||||
throw new \Exception ("Authentication error in pre-auth LDAP", 500);
|
||||
}
|
||||
|
||||
/** Try to authenticate the email/password of the user
|
||||
@@ -64,15 +65,15 @@ class authldap extends auth
|
||||
$search = ldap_search ($this->ldapconn, $this->ldapbase, $filter,
|
||||
array ($this->ldapfield));
|
||||
if ($search === FALSE)
|
||||
throw new Exception ("Unable to search in LDAP", 500);
|
||||
throw new \Exception ("Unable to search in LDAP", 500);
|
||||
$info = ldap_get_entries ($this->ldapconn, $search);
|
||||
if (!isset ($info["count"]) || $info["count"] !== 1 || !isset ($info[0]) ||
|
||||
!isset ($info[0]["dn"]))
|
||||
throw new Exception ("Unable to find the user : '$email'", 401);
|
||||
throw new \Exception ("Unable to find the user : '$email'", 401);
|
||||
$dn = $info[0]["dn"];
|
||||
$ldapbind2 = @ldap_bind ($this->ldapconn, $dn, $password);
|
||||
if ($ldapbind2 !== TRUE)
|
||||
throw new Exception ("Bad password for '$email'", 401);
|
||||
throw new \Exception ("Bad password for '$email'", 401);
|
||||
$this->ldapdnuser = $dn;
|
||||
}
|
||||
|
||||
@@ -80,11 +81,11 @@ class authldap extends auth
|
||||
public function getdetails ()
|
||||
{
|
||||
if ($this->ldapdnuser === NULL)
|
||||
throw new Exception ("No user authenticated !", 401);
|
||||
throw new \Exception ("No user authenticated !", 401);
|
||||
$search = ldap_search ($this->ldapconn, $this->ldapdnuser,
|
||||
$this->ldapfiltersearch);
|
||||
if ($search === FALSE)
|
||||
throw new Exception ("Can not found the details for user", 401);
|
||||
throw new \Exception ("Can not found the details for user", 401);
|
||||
$data = ldap_get_entries ($this->ldapconn, $search);
|
||||
$res = array ();
|
||||
if (isset ($data[0]))
|
||||
@@ -103,7 +104,7 @@ class authldap extends auth
|
||||
@param string $newpassword The new password to be recorded */
|
||||
public function changepassword ($oldpassword, $newpassword)
|
||||
{
|
||||
throw new Exception (dgettext("domframework",
|
||||
throw new \Exception (dgettext("domframework",
|
||||
"The password can't be change for LDAP users"), 405);
|
||||
}
|
||||
|
||||
@@ -124,12 +125,12 @@ class authldap extends auth
|
||||
public function listusers ()
|
||||
{
|
||||
if ($this->ldapconn === NULL)
|
||||
throw new Exception ("No established LDAP connection", 500);
|
||||
throw new \Exception ("No established LDAP connection", 500);
|
||||
$search = ldap_search ($this->ldapconn,$this->ldapbase,
|
||||
$this->ldapfiltersearch,
|
||||
array ("mail","sn","givenname"));
|
||||
if ($search === FALSE)
|
||||
throw new Exception ("Unable to search the users in LDAP", 500);
|
||||
throw new \Exception ("Unable to search the users in LDAP", 500);
|
||||
$info = ldap_get_entries ($this->ldapconn, $search);
|
||||
$data = array ();
|
||||
foreach ($info as $key=>$vals)
|
||||
|
||||
Reference in New Issue
Block a user