|
|
|||
Information Services
|
||||
|
||||
|
|
Centaur - PHP exampleCertificatesFor information regarding configuration of certificates used by php for LDAPS connections see the OpenLDAP configuration page. Sample codeThe following sample code could be used in a PHP application to authenticate against Centaur: simple authentication<?php
$username = 'johnsmith';
$password = 'secret';
$ldap_uri = 'ldaps://centaur.unimelb.edu.au/';
$ldapconn = ldap_connect($ldap_uri)
or die("Could not connect to $ldap_uri");
if (! ldap_bind($ldapconn,"uid=$username,ou=people,o=unimelb", $password)) {
die("Failed to authenticate");
} else {
print "Successfully authenticated";
...
...
}
?>
authentication using attributes for authorisationYou can also use the attributes in Centaur to make authorisation decisions. There are two ways of doing this:
<?php
$username = 'john smith';
$password = 'secret';
$ldap_uri = 'ldaps://centaur.unimelb.edu.au/';
$ldap_base_dn = "ou=people,o=unimelb";
$ldap_filter = "(&(uid=$username)(auEduPersonType=staff))";
$ldap_conn = ldap_connect($ldap_uri)
or die("Could not connect to $ldap_uri");
$search_results = ldap_search($ldap_conn, $ldap_base_dn, $ldap_filter)
or die("Search error");
if (ldap_count_entries($ldap_conn, $search_results) != 1) {
// User does not exist or not a staff member
die("Failed to authenticate");
}
if (! ldap_bind($ldap_conn,"uid=$username,$ldap_base_dn", $password)) {
die("Failed to authenticate");
} else {
print "Successfully authenticated";
}
?>
simple authentication using PEAR frameworkIf you are using the PEAR Auth framework you could do something like the following: <?php
$myauth = new Auth("LDAP", array (
'url' => 'ldaps://centaur.unimelb.edu.au',
'basedn' => 'ou=people,o=unimelb',
'userattr' => 'uid'
));
?>
|
|
Contact the University : Disclaimer & Copyright : Privacy : Accessibility |
|
Date Created: 8 June 2006 |
© The University of Melbourne 1994-2005 |