Skip to content

Commit

Permalink
Added logging, added test mode, reduce course selection to deeplink, …
Browse files Browse the repository at this point in the history
…if given
  • Loading branch information
Fred Neumann committed Mar 23, 2021
1 parent f847c5a commit f11f2cf
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 20 deletions.
25 changes: 25 additions & 0 deletions classes/class.ilVhbShibAuthConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,31 @@ public function __construct($a_plugin_object)
'Gibt die übermittelten Daten aus und beendet die Verarbeitung.',
ilVhbShibAuthParam::TYPE_BOOLEAN
);
$params[] = ilVhbShibAuthParam::_create(
'log_server_data',
'Logge Serverdaten',
'Protokolliere die Serverdaten unter ' . ILIAS_DATA_DIR . '/VhbShibAuth.log',
ilVhbShibAuthParam::TYPE_BOOLEAN
);
$params[] = ilVhbShibAuthParam::_create(
'test_activation',
'Testmodus-Aktivierung',
'Wert für den URL-Parameter "test", der die unten stehenden Testdaten aktiviert.',
ilVhbShibAuthParam::TYPE_TEXT
);
$params[] = ilVhbShibAuthParam::_create(
'test_principal_name',
'Test: eduPersonPrincipalName',
'Überschreibt im Testmodus den Wert des Attributs.',
ilVhbShibAuthParam::TYPE_TEXT
);
$params[] = ilVhbShibAuthParam::_create(
'test_entitlement',
'Test: eduPersonEntitlement',
'Überschreibt im Testmodus den Wert des Attributs.',
ilVhbShibAuthParam::TYPE_TEXT
);



foreach ($params as $param)
Expand Down
43 changes: 31 additions & 12 deletions classes/class.ilVhbShibAuthMatching.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,32 @@ public function getMatchedUser()

/**
* Get the list of courses that need a selection
* @param string $lvnr
* @return array $lvnr => ref_ids
*/
public function getCoursesToSelect()
public function getCoursesToSelect($lvnr = null)
{
return $this->coursesToSelect;
if (empty($lvnr)) {
// no deep link => offer all that need selection
return $this->coursesToSelect;
}
elseif (isset($this->coursesToSelect[$lvnr])) {
// deep link needs selection => offer only this
return [$lvnr => $this->coursesToSelect[$lvnr]];
}
else {
// deep link does not need a selection => dont' offer a selection
return [];
}
}

/**
* Save the list of courses that need a selection
* @param string $lvnr
*/
public function saveCoursesToSelect()
public function saveCoursesToSelect($lvnr = null)
{
$_SESSION['ilVhbShibAuth']['coursesToSelect'] = $this->coursesToSelect;
$_SESSION['ilVhbShibAuth']['coursesToSelect'] = $this->getCoursesToSelect($lvnr);
}

/**
Expand Down Expand Up @@ -287,15 +300,21 @@ protected function findRelevantIliasCourses()
/**
* Print a data dump and exit
*/
public function dumpData()
public function getDataDump()
{
echo '<pre>';
echo 'Extracted Shibboleth Data: ';
print_r($this->data->getData());
echo '';
echo 'Raw Server Data: ';
print_r((array) $_SERVER);
echo '</pre>';
return (implode("\n", [
'Extracted Shibboleth Data: ',
print_r($this->data->getData(), true),
'',
'$_SERVER: ',
print_r((array) $_SERVER, true),
'$_GET: ',
print_r((array) $_GET, true),
'$_POST: ',
print_r((array) $_POST, true),
'$_COOKIE: ',
print_r((array) $_COOKIE,true)
]));
}

}
40 changes: 32 additions & 8 deletions classes/class.ilVhbShibAuthPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,39 @@ public function getConfig()
*/
public function getMatching()
{
if (!isset($this->matching)) {
$this->includeClass('class.ilVhbShibAuthMatching.php');
$this->matching = new ilVhbShibAuthMatching($this);
if (isset($this->matching)) {
return $this->matching;
}

if ($this->config->get('show_server_data')) {
$this->matching->dumpData();
// apply test data as early as possible
if (!empty($_GET['test']) && $_GET['test'] == $this->getConfig()->get('test_activation')) {
$_SERVER['eduPersonPrincipalName'] = $this->getConfig()->get('test_principal_name');
$_SERVER['eduPersonEntitlement'] = $this->getConfig()->get('test_entitlement');
}

$this->includeClass('class.ilVhbShibAuthMatching.php');
$this->matching = new ilVhbShibAuthMatching($this);

// debugging output
if ($this->getConfig()->get('show_server_data')) {
echo '<pre>';
echo $this->matching->getDataDump();
echo '</pre>';
exit;
}

// logging
if ($this->getConfig()->get('log_server_data')) {

$content = "-------------------\n"
. date('Y-m-d H:i:s') . "\n"
. "-------------------\n"
. $this->matching->getDataDump();

file_put_contents(ILIAS_DATA_DIR . '/VhbShibAuth.log', $content, FILE_APPEND);
}


return $this->matching;
}

Expand All @@ -71,8 +95,8 @@ protected function prepareRedirection($user)
{
global $DIC;

if (!empty($this->getMatching()->getCoursesToSelect())) {
$this->getMatching()->saveCoursesToSelect();
if (!empty($this->getMatching()->getCoursesToSelect($_GET['id']))) {
$this->getMatching()->saveCoursesToSelect($_GET['id']);

if (isset($_GET['id'])) {
$DIC->ctrl()->setParameterByClass('ilVhbShibAuthCourseSelectGUI', 'deepLink', $_GET['id']);
Expand All @@ -89,7 +113,7 @@ protected function prepareRedirection($user)


/**
* Hook from shibboleth authentication before the user object is created
* Hook from Shibboleth authentication before the user object is created
* Ignore the prepared user from the default matching conditions
* Return an own user object for the vhb matching conditions
* @param ilObjUser $user
Expand Down

0 comments on commit f11f2cf

Please sign in to comment.