This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnldap/classes/Kohana/Auth/LDAP.php
2013-08-16 12:21:17 +10:00

85 lines
2.0 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* LDAP Auth driver.
*
* @package Auth/LDAP
* @category Helpers
* @author Deon George
* @copyright (c) 2013 phpLDAPadmin Development Team
* @license http://dev.phpldapadmin.org/license.html
*/
abstract class Kohana_Auth_LDAP extends Auth {
// Unnused required abstract functions
public function password($username) {}
public function check_password($password) {}
// Overrides
public function hash($str) {
// Since this is used automatically to encrypted a password, we need to suppress that for LDAP
if (! $this->_config['hash_key'])
return $str;
else
return parent::hash($str);
}
/**
* Logs a user in.
*
* @param string username
* @param string password
* @param boolean enable autologin (not supported)
* @return boolean
*/
protected function _login($user, $password, $remember) {
if ( ! is_object($user)) {
$username = $user;
// Load the user
// @todo Get the server ID
$user = LDAP::factory('user')->bind($username,$password);
}
// @todo Implement conditional logging based on memberships to groups or other criteria.
// @todo This check of user being logged in needs to be better
if ($user) {
/*
// @todo To implement
if ($remember === TRUE) {
// Token data
$data = array(
'user_id'=>$user->id,
'expires'=>time()+$this->_config['lifetime'],
'user_agent'=>sha1(Request::$user_agent),
);
// Create a new autologin token
$token = ORM::factory('user_token')
->values($data)
->create();
// Set the autologin cookie
Cookie::set('authautologin', $token->token, $this->_config['lifetime']);
}
*/
// Finish the login
if (PHP_SAPI !== 'cli')
$this->complete_login($user);
return TRUE;
}
// Login failed
return FALSE;
}
public function logout($destroy=FALSE,$logout_all=FALSE) {
LDAP::factory('user')->disconnect();
if (PHP_SAPI !== 'cli')
return parent::logout($destroy,$logout_all);
}
}
?>