esempio: pear auth con autenticazione su ldap


Ldap
, panacea di tutti i mali e spina nel fianco ;-) . Comunque lo ritengo fermamente l'unica soluzione valida per la gestione di contatti e l'autenticazione degli utenti. Tutto il resto è fuffa o esclusivamente un modo per fare meno fatica e raggiungere i risultati velocemente precludendo possibilità e futuri sviluppi per il proprio software.

Vediamo come utilizzare ldap in php sfruttando le classi di pear.

Nella (penosa) documentazione del pacchetto Auth di pear non viene enfatizzato che auth assume che le entries abbiano object class di tipo posix.

userfilter" string "(objectClass=posixAccount)"

Quindi di default Auth va a filtrare le entry cercando esclusivamente quelle di tipo posix. L'ho potuto capire grazie all'eccellente funzione di debug di ldap da attivare SEMPRE quando si brancola nel buio come in questi casi 

Mi baso su questo esempio e  scrivo un blocco di codice funzionante da cui trarre spunto. Il file si chiama test.php:

require_once "Auth/Auth.php";

function loginFunction($username = null, $status = null, &$auth = null)
{
/*
* Change the HTML output so that it fits to your
* application. !!!!!!!!!!!!!!!! NOTE the modified fields UID and userPassword !!!!!!!!!!!!!!!!!!!

*/

echo '<form method="post" action="test.php">';
echo '<input type="text" name="uid">';
echo '<input type="password" name="userPassword">';
echo '<input type="submit">';
echo '</form>';
}

$options=array(
'host' => 'spippolo',
'port' => '389',
'version' => 2,
'basedn' => 'ou=utenti,dc=spippolo,dc=2v,dc=ntw',
'userattr' => 'uid','userPassword',
'binddn' => 'cn=admin,dc=spippolo,dc=2v,dc=ntw',
'bindpw' => 'pippo',
'postUsername' => 'uid',
'postPassword' => 'userPassword',
'usernamecol' => 'uid',
'passwordcol' => 'userPassword',
'enableLogging' => 'true',
'cryptType' => 'md5',
"userfilter" => "(objectClass=inetOrgPerson)"

$a1 = new Auth("LDAP", $options, loginFunction);

$a1->start();

if ($a1->checkAuth())
{
echo 'autenticato';
}
else
{
echo 'non autenticato';
}

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
16 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.