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';
}

Comments

timberland boots

It is a good timberland 6 inch boots thing that the God Who made us is not impatient with people like me with my timberland shoe company orchid. He lovingly thinks about us all the time timberland boots and he even temporarily gave up His heavenly home and his timberland traditional handsewn hold on diety to die for the sins of timberland mens custom world nearly 2,000 years ago. His death back then covered the sins of every cheap timberland boots person who will ever live. He then rose to life after three mens timberland chukka days and ever since has wanted us to accept His gracious act by loving Him and also those around us. When we do this, we will see people in a totally different timberland womens premium boots light — one that redefines what it means to be ugly or different or weird or strange. Instead, we see people with ugly timberland shoes store problems in whom God is working so they can bloom beautifully — just like I now see in my orchids whether they are “lumps” or blossoms! On a certain timberland work shoes day at a certain hour, we will pull into the station. Bands will be playing and flags waving. Once we get there, so many wonderful dreams will come true and the pieces of our timberland wheat shoes lives will fit together like a completed jigsaw puzzle. How restlessly we pace the aisles, *ing the minutes for timberland for you loitering --waiting, waiting, waiting for the station.

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.
  • Internal paths in double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or relative path.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.