Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #490 Added container authentication #491

Open
wants to merge 1 commit into
base: develop
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
3 changes: 3 additions & 0 deletions auth_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* See code in library/Xerte/Authentication/*.php - where each file should match up to the value used below.
*/

global $container_auth;
$container_auth = false;

// set authentication method to guest if not set in db via management area
if (!isset($xerte_toolkits_site->authentication_method) || $xerte_toolkits_site->authentication_method=="") {
$xerte_toolkits_site->authentication_method = 'Guest';
Expand Down
9 changes: 8 additions & 1 deletion library/Xerte/Authentication/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ abstract class Xerte_Authentication_Abstract
*/
protected $_errors = array();

/**
* @var boolean - see auth_config.php.
*/
protected $container_auth = false;

/**
* @var StdClass - see config.php.
*/
Expand Down Expand Up @@ -72,10 +77,12 @@ abstract public function getSurname();
abstract public function getEmail();

/**
* @param boolean $container_auth
* @param StdClass $xerte_toolkits_site
*/
public function __construct($xerte_toolkits_site)
public function __construct($container_auth, $xerte_toolkits_site)
{
$this->container_auth = $container_auth;
$this->xerte_toolkits_site = $xerte_toolkits_site;
}

Expand Down
5 changes: 3 additions & 2 deletions library/Xerte/Authentication/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ class Xerte_Authentication_Factory
*/
public static function create($method)
{
global $container_auth;
global $xerte_toolkits_site;

$method = ucfirst(strtolower($method));
if (is_file(dirname(__FILE__) . DIRECTORY_SEPARATOR . $method . ".php")) {
$class_name = "Xerte_Authentication_$method";

$auth_mech = new $class_name($xerte_toolkits_site);
$auth_mech = new $class_name($container_auth, $xerte_toolkits_site);
return $auth_mech;
}
//throw new InvalidArgumentException("Authentication mechanism defined in xerte_site_details is not valid");
}
}
}
10 changes: 9 additions & 1 deletion library/Xerte/Authentication/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,22 @@ private function _authenticate_to_host($host, $port, $bind_pwd, $bind_dn, $based
$this->addError("Issue connecting to ldap server (#4) : No entries found ");
return false;
} else {
if (@ldap_bind($ds, $entry[0]['dn'], $password)) {
$user_record = array('firstname' => $entry[0]['givenname'][0], 'surname' => $entry[0]['sn'][0], 'username' => $xot_username);
if ($this->container_auth) {
_debug("Container auth ok " . print_r($entry, true));
$this->_record = $user_record;
return true;
} else if (@ldap_bind($ds, $entry[0]['dn'], $password)) {
_debug("Login ok " . print_r($entry, true));
/*
* valid login, so return true
*/

$this->_record = array('firstname' => $entry[0]['givenname'][0], 'surname' => $entry[0]['sn'][0], 'username' => $xot_username);
return true;
} else {
_debug("Failed to authenticate " . print_r($entry, true));
return false;
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion website_code/php/login_library.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,29 @@ function login_form($messages, $xerte_toolkits_site)
}

function login_processing($exit = true) {
global $errors, $authmech, $xerte_toolkits_site;
global $errors, $authmech, $xerte_toolkits_site, $container_auth;

/**
* Check to see if anything has been posted to distinguish between log in attempts
*/

$authmech = Xerte_Authentication_Factory::create($xerte_toolkits_site->authentication_method);

if ($_SERVER['REQUEST_METHOD'] !== "POST") {
if ($container_auth) {
if (isset($_SERVER['REMOTE_USER'])) {
_debug("REMOTE_USER: " . $_SERVER['REMOTE_USER']);
$success = $authmech->login($_SERVER['REMOTE_USER'], '');
return(array($success, $errors));
} else {
_debug("container_auth is true but REMOTE_USER has not been set");
}
}
if ($authmech->needsLogin() && $exit) {
login_form($errors, $xerte_toolkits_site);
exit(0);
}
}
if ($authmech->needsLogin()) {
/**
* Check if we are logged in
Expand Down