ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
TargetedID.php
Go to the documentation of this file.
1 <?php
2 
32 
33 
38  private $attribute = NULL;
39 
40 
46  private $generateNameId = FALSE;
47 
48 
55  public function __construct($config, $reserved) {
56  parent::__construct($config, $reserved);
57 
58  assert('is_array($config)');
59 
60  if (array_key_exists('attributename', $config)) {
61  $this->attribute = $config['attributename'];
62  if (!is_string($this->attribute)) {
63  throw new Exception('Invalid attribute name given to core:TargetedID filter.');
64  }
65  }
66 
67  if (array_key_exists('nameId', $config)) {
68  $this->generateNameId = $config['nameId'];
69  if (!is_bool($this->generateNameId)) {
70  throw new Exception('Invalid value of \'nameId\'-option to core:TargetedID filter.');
71  }
72  }
73  }
74 
75 
81  public function process(&$state) {
82  assert('is_array($state)');
83  assert('array_key_exists("Attributes", $state)');
84 
85  if ($this->attribute === NULL) {
86  if (!array_key_exists('UserID', $state)) {
87  throw new Exception('core:TargetedID: Missing UserID for this user. Please' .
88  ' check the \'userid.attribute\' option in the metadata against the' .
89  ' attributes provided by the authentication source.');
90  }
91 
92  $userID = $state['UserID'];
93  } else {
94  if (!array_key_exists($this->attribute, $state['Attributes'])) {
95  throw new Exception('core:TargetedID: Missing attribute \'' . $this->attribute .
96  '\', which is needed to generate the targeted ID.');
97  }
98 
99  $userID = $state['Attributes'][$this->attribute][0];
100  }
101 
102 
103  $secretSalt = SimpleSAML\Utils\Config::getSecretSalt();
104 
105  if (array_key_exists('Source', $state)) {
106  $srcID = self::getEntityId($state['Source']);
107  } else {
108  $srcID = '';
109  }
110 
111  if (array_key_exists('Destination', $state)) {
112  $dstID = self::getEntityId($state['Destination']);
113  } else {
114  $dstID = '';
115  }
116 
117  $uidData = 'uidhashbase' . $secretSalt;
118  $uidData .= strlen($srcID) . ':' . $srcID;
119  $uidData .= strlen($dstID) . ':' . $dstID;
120  $uidData .= strlen($userID) . ':' . $userID;
121  $uidData .= $secretSalt;
122 
123  $uid = hash('sha1', $uidData);
124 
125  if ($this->generateNameId) {
126  // Convert the targeted ID to a SAML 2.0 name identifier element
127  $nameId = new \SAML2\XML\saml\NameID();
128  $nameId->value = $uid;
129  $nameId->Format = \SAML2\Constants::NAMEID_PERSISTENT;
130 
131  if (isset($state['Source']['entityid'])) {
132  $nameId->NameQualifier = $state['Source']['entityid'];
133  }
134  if (isset($state['Destination']['entityid'])) {
135  $nameId->SPNameQualifier = $state['Destination']['entityid'];
136  }
137  } else {
138  $nameId = $uid;
139  }
140 
141  $state['Attributes']['eduPersonTargetedID'] = array($nameId);
142  }
143 
144 
154  private static function getEntityId($metadata) {
155  assert('is_array($metadata)');
156 
157  $id = '';
158 
159  if (array_key_exists('metadata-set', $metadata)) {
160  $set = $metadata['metadata-set'];
161  $id .= 'set' . strlen($set) . ':' . $set;
162  }
163 
164  if (array_key_exists('entityid', $metadata)) {
165  $entityid = $metadata['entityid'];
166  $id .= 'set' . strlen($entityid) . ':' . $entityid;
167  }
168 
169  return $id;
170  }
171 
172 }
File written to
Sum of both Ranges is
Definition: 03formulas.php:77
process(&$state)
Apply filter to add the targeted ID.
Definition: TargetedID.php:81
$metadata['__DYNAMIC:1__']
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
__construct($config, $reserved)
Initialize this filter.
Definition: TargetedID.php:55
$attribute
The attribute we should generate the targeted id from, or NULL if we should use the UserID...
Definition: TargetedID.php:38