I have written the following class for my PHP applications and it works fine, but I am unable to configure Mantis to use LDAP. Can anybody help?
File: SynchUser.class.php
<?
// Define the IC ADS constants
define("LDAP_HOST", "ICENT-Query.ic.gc.ca");
define("LDAP_DN", "OU=ICUSERS,DC=ICENT,DC=IC,DC=GC,DC=CA");
define("LDAP_USER", "AOReadOnlyIFMS@icent.ic.gc.ca"); // Our format is Lan ID, You can test with you ID and Password.
define("LDAP_PWD", "XXXXXX"); // Our format is Lan ID, You can test with you ID and Password.
// Define the error messages constants
define("LDAP_COULD_NOT_CONNECT", 100);
define("LDAP_COULD_NOT_SET_PROTOCOL", 101);
define("LDAP_COULD_NOT_BIND", 200);
class SynchUser {
var $ds;
var $bd;
var $auth = 0;
var $sr;
var $entries;
var $bound = 0;
var $err = null;
var $msg = "";
function SynchUser() {
$this->ds = ldap_connect(LDAP_HOST) or
$this->setError(LDAP_COULD_NOT_CONNECT);
if ($this->err == null) {
ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3) or
$this->setError(LDAP_COULD_NOT_SET_PROTOCOL);
}
$this->bind();
}
function bind($user = LDAP_USER, $pswd = LDAP_PWD) {
if (!$this->bd = @ ldap_bind($this->ds, $user, $pswd)) {
$this->setError(LDAP_COULD_NOT_BIND);
$this->bound = 0;
} else {
$this->bound = 1;
}
return $this->bound;
}
function search($in_email) {
$this->sr = ldap_search($this->ds, LDAP_DN, "mail=$in_email");
if (ldap_count_entries($this->ds, $this->sr) >0) {
$this->entries = ldap_get_entries($this->ds, $this->sr);
}
}
function authenticate($user, $pwd) {
$result = @ldap_search($this->ds, LDAP_DN, "samaccountname=" . $user);
if (ldap_count_entries($this->ds, $result) == 1) {
$username = $user . "@ic.gc.ca";
$this->auth = @ldap_bind($this->ds, $username, $pwd);
}
if (!$this->auth) {
return 0;
}else{;
return 1;
}
}
function setError ($error) {
$this->err = $error;
}
function errorMsg() {
switch ($this->err) {
case LDAP_COULD_NOT_CONNECT:
$this->msg = "LDAP could not connect!";
break;
case LDAP_COULD_NOT_SET_PROTOCOL:
$this->msg = "LDAP could not set protocol!";
break;
case LDAP_COULD_NOT_BIND:
$this->msg = "LDAP could not bind!";
break;
default:
$this->msg = "No error!";
}
return $this->msg;
}
function close() {
ldap_close($this->ds);
}
}
?>
Configuring LDAP for Active Directory (Windows/Apache)
Moderators: Developer, Contributor