ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
authmemcookie.php
Go to the documentation of this file.
1<?php
2
15require_once('_include.php');
16
17try {
18 // load SimpleSAMLphp configuration
20
21 // check if this module is enabled
22 if (!$globalConfig->getBoolean('enable.authmemcookie', false)) {
23 throw new SimpleSAML_Error_Error('NOACCESS');
24 }
25
26 // load Auth MemCookie configuration
28
29 $sourceId = $amc->getAuthSource();
30 $s = new \SimpleSAML\Auth\Simple($sourceId);
31
32 // check if the user is authorized. We attempt to authenticate the user if not
33 $s->requireAuth();
34
35 // generate session id and save it in a cookie
37 $cookieName = $amc->getCookieName();
39
40 // generate the authentication information
41 $attributes = $s->getAttributes();
42
43 $authData = array();
44
45 // username
46 $usernameAttr = $amc->getUsernameAttr();
47 if (!array_key_exists($usernameAttr, $attributes)) {
48 throw new Exception(
49 "The user doesn't have an attribute named '".$usernameAttr.
50 "'. This attribute is expected to contain the username."
51 );
52 }
54
55 // groups
56 $groupsAttr = $amc->getGroupsAttr();
57 if ($groupsAttr !== null) {
58 if (!array_key_exists($groupsAttr, $attributes)) {
59 throw new Exception(
60 "The user doesn't have an attribute named '".$groupsAttr.
61 "'. This attribute is expected to contain the groups the user is a member of."
62 );
63 }
65 } else {
66 $authData['Groups'] = array();
67 }
68
69 $authData['RemoteIP'] = $_SERVER['REMOTE_ADDR'];
70
71 foreach ($attributes as $n => $v) {
72 $authData['ATTR_'.$n] = $v;
73 }
74
75 // store the authentication data in the memcache server
76 $data = '';
77 foreach ($authData as $name => $values) {
78 if (is_array($values)) {
79 foreach ($values as $i => $value) {
80 if (!is_a($value, 'DOMNodeList')) {
81 continue;
82 }
83 /* @var \DOMNodeList $value */
84 if ($value->length === 0) {
85 continue;
86 }
87 $values[$i] = new \SAML2\XML\saml\AttributeValue($value->item(0)->parentNode);
88 }
89 $values = implode(':', $values);
90 }
91 $data .= $name.'='.$values."\r\n";
92 }
93
94 $memcache = $amc->getMemcache();
95 $expirationTime = $s->getAuthData('Expire');
97
98 // register logout handler
100 $session->registerLogoutHandler($sourceId, 'SimpleSAML_AuthMemCookie', 'logoutHandler');
101
102 // redirect the user back to this page to signal that the login is completed
104} catch (Exception $e) {
105 throw new SimpleSAML_Error_Error('CONFIG', $e);
106}
$n
Definition: RandomTest.php:85
An exception for terminatinating execution or to throw for unit testing.
static setCookie($name, $value, $params=null, $throw=true)
Set a cookie.
Definition: HTTP.php:1107
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:962
static generateID()
Generate a random identifier, ID_LENGTH bytes long.
Definition: Random.php:26
static getInstance()
This function is used to retrieve the singleton instance of this class.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
static getSessionFromRequest()
Retrieves the current session.
Definition: Session.php:243
$i
Definition: disco.tpl.php:19
if($format !==null) $name
Definition: metadata.php:146
Attribute-related utility methods.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$groupsAttr
$usernameAttr
if(! $globalConfig->getBoolean('enable.authmemcookie', false)) $amc
foreach($attributes as $n=> $v) $data
$authData
$expirationTime
$cookieName
$session
$sourceId
foreach($authData as $name=> $values) $memcache
$attributes
$sessionID
$globalConfig