Skip to content

Instantly share code, notes, and snippets.

@fables-tales
Created July 20, 2010 20:02
Show Gist options
  • Save fables-tales/483477 to your computer and use it in GitHub Desktop.
Save fables-tales/483477 to your computer and use it in GitHub Desktop.
<?php
/**
* A class for doing LDAP authentication using the secure token system
* implements SecureTokenAuth
* @author Sam Phippen <[email protected]>
*
*/
class LDAPAuth extends SecureTokenAuth {
private $ldapManager;
public function __construct()
{
parent::__construct();
}
public function checkAuthentication($username, $password)
{
$config = Configuration::getInstance();
$this->ldapManager = new LDAPManager($config->getConfig("ldap.host"), $username, $password);
return $this->ldapManager->getAuthed();
}
public function getTeams($username)
{
$config = Configuration::getInstance();
$ldapManager = new LDAPManager($config->getConfig("ldap.host"), "ide", $config->getConfig("ldap.ideuser.password"));
$groups = $this->ldapManager->getGroupsForUser($username);
$teams = array();
foreach ($groups as $group)
{
if (stripos($group["cn"], "team"))
{
$teams[] = substr($group["cn"],4,count($group["cn"])-4);
}
}
return $teams;
}
public function displayNameForGroup($group)
{
}
public function displayNameForUser($user)
{
if ($this->ldapManager->getAuthed()) {
$info = $this->ldapManager->getUserInfo($user);
return $info["name.first"] . " " . $info["name.last"];
}
else
{
throw new Exception("you aren't authed to ldap", E_LDAP_NOT_AUTHED);
}
}
public function emailForUser($user)
{
if ($this->ldapManager->getAuthed())
{
$info = $this->ldapManager->getUserInfo($user);
return $info["email"];
}
else
{
throw new Exception("you aren't authed to ldap", E_LDAP_NOT_AUTHED);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment