Skip to content
This repository has been archived by the owner on Feb 16, 2019. It is now read-only.

Applied fixes from StyleCI #1

Open
wants to merge 1 commit into
base: 3.3/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions classes/Auth/LDAP.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* AD/LDAP Driver for Kohana Auth.
*
* @package Kadldap
* @author Beau Dacious <dacious.beau@gmail.com>
* @copyright (c) 2009 Beau Dacious
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Auth_LDAP extends Kadldap_Auth_LDAP { }
<?php

defined('SYSPATH') or die('No direct access allowed.');
/**
* AD/LDAP Driver for Kohana Auth.
*
* @author Beau Dacious <dacious.beau@gmail.com>
* @copyright (c) 2009 Beau Dacious
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Auth_LDAP extends Kadldap_Auth_LDAP
{
}
132 changes: 61 additions & 71 deletions classes/Controller/Kadldap.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
<?php

defined('SYSPATH') or die('No direct access allowed.');
/**
* Module controller for Kadldap, to test configuration and connection details. This
* uses the Userguide controller and views, and is linked to from the userguide.
*
* @package Kadldap
* @author Sam Wilson <sam@samwilson.id.au>
* @copyright (c) 2011 Sam Wilson
* @author Github user 'sfroeth'
Expand All @@ -12,76 +13,65 @@
*/
class Controller_Kadldap extends Controller_Userguide
{
public function action_index()
{
// Set up template and view
$view = View::factory('kadldap/index');
$this->template->content = $view;
$this->template->title = 'Kadldap';
$this->template->menu = '';
$this->template->breadcrumb = [
Route::get('docs/guide')->uri() => __('User Guide'),
Route::get('docs/guide')->uri().'/kadldap' => $this->template->title,
'Configuration Test',
];
$view->kadldap = Kadldap::instance();
$view->message = false;

public function action_index()
{
// Set up template and view
$view = View::factory('kadldap/index');
$this->template->content = $view;
$this->template->title = 'Kadldap';
$this->template->menu = '';
$this->template->breadcrumb = array(
Route::get('docs/guide')->uri() => __('User Guide'),
Route::get('docs/guide')->uri().'/kadldap' => $this->template->title,
'Configuration Test'
);
$view->kadldap = Kadldap::instance();
$view->message = FALSE;

// Check auth driver
$auth_driver = Kohana::$config->load('auth')->get('driver');
if ($auth_driver != 'LDAP')
{
$view->message = "Incorrect configuration! Auth driver is set to '$auth_driver', but should be 'LDAP'.";
}

// Process login
if (isset($_POST['login']))
{
$post = Validation::factory($_POST)
->rule('username', 'not_empty')
->rule('password', 'not_empty');
if ($post->check())
{
$username = $post['username'];
$password = arr::get($post, 'password', '');
try
{
if (Auth::instance()->login($username, $password))
{
$view->message = 'Successful login.';
} else
{
$view->message = 'Login failed.';
}
} catch (\Adldap\Exceptions\AdldapException $e)
{
$view->message = $e->getMessage();
}
} else
{
$view->message = 'You must enter both your username and password.';
}
}
// Check auth driver
$auth_driver = Kohana::$config->load('auth')->get('driver');
if ($auth_driver != 'LDAP') {
$view->message = "Incorrect configuration! Auth driver is set to '$auth_driver', but should be 'LDAP'.";
}

// Get information about the logged-in user
if (Auth::instance()->logged_in())
{
$username = Auth::instance()->get_user();
$password = Auth::instance()->password($username);
$view->kadldap->authenticate($username, $password);
$view->userinfo = $view->kadldap->users()
->find($username)
->getAttributes();
} else {
$view->userinfo = NULL;
}
}
// Process login
if (isset($_POST['login'])) {
$post = Validation::factory($_POST)
->rule('username', 'not_empty')
->rule('password', 'not_empty');
if ($post->check()) {
$username = $post['username'];
$password = arr::get($post, 'password', '');
try {
if (Auth::instance()->login($username, $password)) {
$view->message = 'Successful login.';
} else {
$view->message = 'Login failed.';
}
} catch (\Adldap\Exceptions\AdldapException $e) {
$view->message = $e->getMessage();
}
} else {
$view->message = 'You must enter both your username and password.';
}
}

public function action_logout()
{
Auth::instance()->logout();
$this->redirect('kadldap');
}
// Get information about the logged-in user
if (Auth::instance()->logged_in()) {
$username = Auth::instance()->get_user();
$password = Auth::instance()->password($username);
$view->kadldap->authenticate($username, $password);
$view->userinfo = $view->kadldap->users()
->find($username)
->getAttributes();
} else {
$view->userinfo = null;
}
}

}
public function action_logout()
{
Auth::instance()->logout();
$this->redirect('kadldap');
}
}
176 changes: 86 additions & 90 deletions classes/Kadldap.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
<?php

defined('SYSPATH') or die('No direct access allowed.');
/**
* AD/LDAP Module for Kohana.
*
* @package Kadldap
* @author Beau Dacious <dacious.beau@gmail.com>
* @copyright (c) 2009 Beau Dacious
* @author Sam Wilson <sam@samwilson.id.au>
Expand All @@ -13,70 +14,68 @@
*/
class Kadldap
{
/** @var \Adldap\Adldap Instance of third-party Adldap library. */
protected $_adldap;
/** @var \Adldap\Adldap Instance of third-party Adldap library. */
protected $_adldap;

/**
* Return a singleton instance of Kadldap.
*
* @return Kadldap
*/
public static function instance()
{
static $instance;
/**
* Return a singleton instance of Kadldap.
*
* @return Kadldap
*/
public static function instance()
{
static $instance;

// Load the Kadldap instance
empty($instance) AND $instance = new Kadldap();
// Load the Kadldap instance
empty($instance) and $instance = new self();

return $instance;
}
return $instance;
}

/**
* Reads config file and loads third-party adLDAP library.
*
* @return void
*/
public function __construct()
{
/*
* Get and check config.
*/
$config = Kohana::$config->load('kadldap')->kadldap;
if (count($config['domain_controllers'])==0)
{
$message = "No domain controllers provided in Kadldap configuration.";
throw new Kohana_Exception($message);
}
/**
* Reads config file and loads third-party adLDAP library.
*
* @return void
*/
public function __construct()
{
/*
* Get and check config.
*/
$config = Kohana::$config->load('kadldap')->kadldap;
if (count($config['domain_controllers']) == 0) {
$message = 'No domain controllers provided in Kadldap configuration.';
throw new Kohana_Exception($message);
}

/*
* Include third-party adLDAP library from vendor directory, if it's not
* already autoloaded (via Composer).
*/
if ( ! class_exists('\Adldap\Adldap'))
{
$adldap_file = Kohana::find_file('vendor/Adldap/src', 'Adldap');
if (!$adldap_file)
{
throw new Kohana_Exception('Unable to find Adldap library.');
}
require_once $adldap_file;
}
/*
* Include third-party adLDAP library from vendor directory, if it's not
* already autoloaded (via Composer).
*/
if (!class_exists('\Adldap\Adldap')) {
$adldap_file = Kohana::find_file('vendor/Adldap/src', 'Adldap');
if (!$adldap_file) {
throw new Kohana_Exception('Unable to find Adldap library.');
}
require_once $adldap_file;
}

/*
* Store instantiation of Adldap library.
*/
$this->_adldap = new \Adldap\Adldap($config);
}
/*
* Store instantiation of Adldap library.
*/
$this->_adldap = new \Adldap\Adldap($config);
}

/**
* Validate a user's login credentials. Wraps [adLDAP::authenticate] so we
* can catch the connection or authentication error.
*
* @param string $username A user's AD username
* @param string $password A user's AD password
* @param bool optional $prevent_rebind
* @return bool
*/
/**
* Validate a user's login credentials. Wraps [adLDAP::authenticate] so we
* can catch the connection or authentication error.
*
* @param string $username A user's AD username
* @param string $password A user's AD password
* @param bool optional $prevent_rebind
*
* @return bool
*/
// public function authenticate($username, $password, $prevent_rebind = FALSE)
// {
// try
Expand All @@ -88,36 +87,33 @@ public function __construct()
// }
// }

/**
* Wrapper for all functions in the adLDAP class that have not already been
* wrapped in this class.
*
* @param <type> $name
* @param <type> $arguments
* @return <type>
*/
public function __call($name, $arguments)
{
if ( method_exists($this->_adldap, $name) )
{
return call_user_func_array(array($this->_adldap, $name), $arguments);
}
else
{
throw new Exception("Method $name does not exist in \Adldap\Adldap.");
}
}

/**
* Override for adLDAP::user_info() method. Prevents the display of errors
* if the user does not exist.
*
* @see adLDAP::user_info()
*/
/*public function user_info()
{
$args = func_get_args();
return call_user_func_array(array($this->_adldap, __FUNCTION__), $args);
}*/
/**
* Wrapper for all functions in the adLDAP class that have not already been
* wrapped in this class.
*
* @param <type> $name
* @param <type> $arguments
*
* @return <type>
*/
public function __call($name, $arguments)
{
if (method_exists($this->_adldap, $name)) {
return call_user_func_array([$this->_adldap, $name], $arguments);
} else {
throw new Exception("Method $name does not exist in \Adldap\Adldap.");
}
}

/*
* Override for adLDAP::user_info() method. Prevents the display of errors
* if the user does not exist.
*
* @see adLDAP::user_info()
*/
/*public function user_info()
{
$args = func_get_args();
return call_user_func_array(array($this->_adldap, __FUNCTION__), $args);
}*/
}
Loading