Skip to content

Commit

Permalink
Update auth plugins; allow them to not require login if it is not nec…
Browse files Browse the repository at this point in the history
…essary; add Moodle prototype; default to Guest and no login is required

git-svn-id: https://xerteonlinetoolkits.googlecode.com/svn/trunk@317 912cdd6b-5c7d-d5a7-a2ba-d0f0cdb91641
  • Loading branch information
Dave Goodwin committed Apr 29, 2012
1 parent 04313cf commit 0907e1e
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 328 deletions.
6 changes: 3 additions & 3 deletions config.php
Expand Up @@ -64,7 +64,7 @@
* @copyright 2008,2009 University of Nottingham
*/
/**
* Include any script that is used for configuration
* Include any script that is used for configuration - for moodle this might be e.g. '/xampp/htdocs/moodle/config.php'.
*/
if ($row['integration_config_path'] != "") {
require_once($row['integration_config_path']);
Expand Down Expand Up @@ -141,8 +141,8 @@
//$xerte_toolkits_site->authentication_method = 'Static';
//$xerte_toolkits_site->authentication_method = "Moodle";

if(isset($_SESSION['integrate_with_moodle']) && $_SESSION['integrate_with_moodle'] == true) {
// skip session_start()
if($xerte_toolkits_site->authentication_method == "Moodle") {
// skip session_start() as we'll probably stomp on Moodle's session if we do.
}
else {
session_start();
Expand Down
649 changes: 325 additions & 324 deletions index.php

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions library/Xerte/Authentication/Abstract.php
Expand Up @@ -52,10 +52,24 @@ public function __construct($xerte_toolkits_site)
$this->xerte_toolkits_site = $xerte_toolkits_site;
}

/**
*@return string $username provided by the end user or the auth mechanism (e.g. Moodle session contents etc)
*/
abstract public function getUsername();
/**
* Perform some sort of check to ensure stuff is configured correctly.... e.g. for LDAP make sure the user has the 'ldap_connect' function available etc
* If any errors are found; retrieve via getErrors();
* @return boolean true
*/
abstract public function check();

/**
*Change this to return FALSE in one of the other authenticators, and the end user shouldn't be shown the login box/dialogue - presumably
* because there's some sort of single sign on in place which we can test immediately without them needing to fill in a login box.
*
* @return boolean true if they need to login.
*/
public function needsLogin() {
return true;
}
}
8 changes: 8 additions & 0 deletions library/Xerte/Authentication/Db.php
Expand Up @@ -21,7 +21,15 @@ public function getFirstname()
}
return null;
}
public function getUsername()
{
if (isset($this->_record['username'])) {
return $this->_record['username'];
}
return null;
}


public function getSurname()
{
if (isset($this->_record['surname'])) {
Expand Down
7 changes: 7 additions & 0 deletions library/Xerte/Authentication/Guest.php
Expand Up @@ -10,6 +10,10 @@ class Xerte_Authentication_Guest extends Xerte_Authentication_Abstract
private $_record = array();


public function getUsername() {
return 'guest';
}

public function getFirstname()
{
return "Guest";
Expand All @@ -29,5 +33,8 @@ public function login($username, $password)
{
return true;
}
public function needsLogin() {
return false;
}

}
9 changes: 8 additions & 1 deletion library/Xerte/Authentication/Ldap.php
Expand Up @@ -18,6 +18,12 @@ class Xerte_Authentication_Ldap extends Xerte_Authentication_Abstract

private $_record = array();

public function getUsername() {
if(isset($this->_record['username'])) {
return $this->_record['username'];
}
return null;
}
public function getFirstname()
{
if (isset($this->_record['fn'])) {
Expand Down Expand Up @@ -144,7 +150,7 @@ private function _authenticate_to_host($host, $port, $bind_pwd, $bind_dn, $based
* valid login, so return true
*/

$this->_record = array('firstname' => $entry[0]['givenname'][0], 'surname' => $entry[0]['sn'][0]);
$this->_record = array('firstname' => $entry[0]['givenname'][0], 'surname' => $entry[0]['sn'][0], 'username' => $eureka_username);
return true;
}
}
Expand All @@ -168,6 +174,7 @@ private function _authenticate_to_host($host, $port, $bind_pwd, $bind_dn, $based
$entry = @ldap_get_entries($ldapConnection, $ldapSearchResult);
if (!empty($entry)) {
$this->_record = $entry;
$this->_record['username'] = $eureka_username;
return true;
}
}
Expand Down
53 changes: 53 additions & 0 deletions library/Xerte/Authentication/Moodle.php
@@ -0,0 +1,53 @@
<?php

/**
* Always returns true; ideal for demonstration so someone can just click the 'login' button.
*
*/
class Xerte_Authentication_Moodle extends Xerte_Authentication_Abstract
{
/* @var $_record array - contains the current user's details - expects keys like firstname, surname */

private $_record = null;

public function getUsername()
{
return $this->_record->username;
}

public function getFirstname()
{
return $this->_record->firstname;
}

public function getSurname()
{
return $this->_record->lastname;
}

public function check()
{
if (!isset($_SESSION['integrate_with_moodle'])) {
$this->addError("Moodle integration not enabled");
}
}

/** Moodle integration should result in us having some funky stuff enabled magically ... */
public function needsLogin()
{
global $USER;
if (empty($USER)) {
return true;
}
$this->_record = $USER;
require_login(); /// moodle function - should shunt the user over to a login page for Moodle if it's needed. Hopefully there are no scope issues from calling it here in a function.
return false;
}

public function login($username, $password)
{
return true;
}

}

3 changes: 3 additions & 0 deletions library/Xerte/Authentication/Static.php
Expand Up @@ -18,6 +18,9 @@ class Xerte_Authentication_Static extends Xerte_Authentication_Abstract
'sarah' => array("username" => "sarah", "password" => "sarahpassword", "firstname" => "Sarah", "surname" => "smith"),
);

public function getUsername() {
return $this->_record['username'];
}
public function getFirstname()
{
return $this->_record['firstname'];
Expand Down

0 comments on commit 0907e1e

Please sign in to comment.