ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
NameIDAttribute.php
Go to the documentation of this file.
1<?php
2
3
10{
11
17 private $attribute;
18
19
25 private $format;
26
27
34 public function __construct($config, $reserved)
35 {
36 parent::__construct($config, $reserved);
37 assert('is_array($config)');
38
39 if (isset($config['attribute'])) {
40 $this->attribute = (string) $config['attribute'];
41 } else {
42 $this->attribute = 'nameid';
43 }
44
45 if (isset($config['format'])) {
46 $format = (string) $config['format'];
47 } else {
48 $format = '%I!%S!%V';
49 }
50
51 $this->format = self::parseFormat($format);
52 }
53
54
63 private static function parseFormat($format)
64 {
65 assert('is_string($format)');
66
67 $ret = array();
68 $pos = 0;
69 while (($next = strpos($format, '%', $pos)) !== false) {
70 $ret[] = substr($format, $pos, $next - $pos);
71
72 $replacement = $format[$next + 1];
73 switch ($replacement) {
74 case 'F':
75 $ret[] = 'Format';
76 break;
77 case 'I':
78 $ret[] = 'NameQualifier';
79 break;
80 case 'S':
81 $ret[] = 'SPNameQualifier';
82 break;
83 case 'V':
84 $ret[] = 'value';
85 break;
86 case '%':
87 $ret[] = '%';
88 break;
89 default:
90 throw new SimpleSAML_Error_Exception('NameIDAttribute: Invalid replacement: "%'.$replacement.'"');
91 }
92
93 $pos = $next + 2;
94 }
95 $ret[] = substr($format, $pos);
96
97 return $ret;
98 }
99
100
106 public function process(&$state)
107 {
108 assert('is_array($state)');
109 assert('isset($state["Source"]["entityid"])');
110 assert('isset($state["Destination"]["entityid"])');
111
112 if (!isset($state['saml:sp:NameID'])) {
113 return;
114 }
115
116 $rep = $state['saml:sp:NameID'];
117 assert(isset($rep->value));
118
119 $rep->{'%'} = '%';
120 if (!isset($rep->Format)) {
122 }
123 if (!isset($rep->NameQualifier)) {
124 $rep->NameQualifier = $state['Source']['entityid'];
125 }
126 if (!isset($rep->SPNameQualifier)) {
127 $rep->SPNameQualifier = $state['Destination']['entityid'];
128 }
129
130 $value = '';
131 $isString = true;
132 foreach ($this->format as $element) {
133 if ($isString) {
134 $value .= $element;
135 } else {
136 $value .= $rep->$element;
137 }
138 $isString = !$isString;
139 }
140
141 $state['Attributes'][$this->attribute] = array($value);
142 }
143}
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
An exception for terminatinating execution or to throw for unit testing.
const NAMEID_UNSPECIFIED
Unspecified NameID format.
Definition: Constants.php:160
static parseFormat($format)
Parse a NameID format string into an array.
__construct($config, $reserved)
Initialize this filter, parse configuration.
process(&$state)
Convert NameID to attribute.
$ret
Definition: parser.php:6