56                parent::__construct(
$config, $reserved);
 
   58                assert(
'is_array($config)');
 
   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.');
 
   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.');
 
   82                assert(
'is_array($state)');
 
   83                assert(
'array_key_exists("Attributes", $state)');
 
   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.');
 
   92                        $userID = 
$state[
'UserID'];
 
   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.
'); 
   99                        $userID = $state['Attributes
'][$this->attribute][0]; 
  103                $secretSalt = SimpleSAML\Utils\Config::getSecretSalt(); 
  105                if (array_key_exists('Source
', $state)) { 
  106                        $srcID = self::getEntityId($state['Source
']); 
  111                if (array_key_exists('Destination
', $state)) { 
  112                        $dstID = self::getEntityId($state['Destination
']); 
  117                $uidData = 'uidhashbase
' . $secretSalt; 
  118                $uidData .= strlen($srcID) . ':
' . $srcID; 
  119                $uidData .= strlen($dstID) . ':
' . $dstID; 
  120                $uidData .= strlen($userID) . ':
' . $userID; 
  121                $uidData .= $secretSalt; 
  123                $uid = hash('sha1
', $uidData); 
  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; 
  131                        if (isset($state['Source
']['entityid
'])) { 
  132                                $nameId->NameQualifier = $state['Source
']['entityid
']; 
  134                        if (isset($state['Destination
']['entityid
'])) { 
  135                                $nameId->SPNameQualifier = $state['Destination
']['entityid
']; 
  141                $state['Attributes
']['eduPersonTargetedID
'] = array($nameId); 
  154        private static function getEntityId($metadata) { 
  159                if (array_key_exists('metadata-
set', $metadata)) { 
  160                        $set = $metadata['metadata-
set']; 
  161                        $id .= 'set' . strlen($set) . ':
' . $set; 
  164                if (array_key_exists('entityid
', $metadata)) { 
  165                        $entityid = $metadata['entityid
']; 
  166                        $id .= 'set' . strlen($entityid) . ':
' . $entityid; 
$metadata['__DYNAMIC:1__']
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
An exception for terminatinating execution or to throw for unit testing.
process(&$state)
Apply filter to add the targeted ID.
$attribute
The attribute we should generate the targeted id from, or NULL if we should use the UserID.
__construct($config, $reserved)
Initialize this filter.