Get the NameID value.
84 {
85
86 if (!isset(
$state[
'saml:NameIDFormat']) && !$this->allowUnspecified) {
88 'SQLPersistentNameID: Request did not specify persistent NameID format, '.
89 'not generating persistent NameID.'
90 );
91 return null;
92 }
93
94 $validNameIdFormats = @array_filter(array(
95 $state[
'saml:NameIDFormat'],
96 $state[
'SPMetadata'][
'NameIDPolicy'],
97 $state[
'SPMetadata'][
'NameIDFormat']
98 ));
99 if (count($validNameIdFormats) && !in_array($this->format, $validNameIdFormats, true) &&
100 !$this->allowDifferent
101 ) {
103 'SQLPersistentNameID: SP expects different NameID format ('.
104 implode(', ', $validNameIdFormats).'), not generating persistent NameID.'
105 );
106 return null;
107 }
108
109 if (!isset(
$state[
'Destination'][
'entityid'])) {
111 return null;
112 }
114
115 if (!isset(
$state[
'Source'][
'entityid'])) {
117 return null;
118 }
120
121 if (!isset(
$state[
'Attributes'][$this->attribute]) || count(
$state[
'Attributes'][$this->attribute]) === 0) {
123 'SQLPersistentNameID: Missing attribute '.var_export($this->attribute, true).
124 ' on user - not generating persistent NameID.'
125 );
126 return null;
127 }
128 if (count(
$state[
'Attributes'][$this->attribute]) > 1) {
130 'SQLPersistentNameID: More than one value in attribute '.var_export($this->attribute, true).
131 ' on user - not generating persistent NameID.'
132 );
133 return null;
134 }
135 $uid = array_values(
$state[
'Attributes'][$this->attribute]);
136 $uid = $uid[0];
137
138 if (empty($uid)) {
140 'Empty value in attribute '.var_export($this->attribute, true).
141 ' on user - not generating persistent NameID.'
142 );
143 return null;
144 }
145
147 if ($value !== null) {
149 'SQLPersistentNameID: Found persistent NameID '.var_export($value, true).' for user '.
150 var_export($uid, true).'.'
151 );
152 return $value;
153 }
154
155 if ((!isset(
$state[
'saml:AllowCreate']) || !
$state[
'saml:AllowCreate']) && !$this->alwaysCreate) {
157 'SQLPersistentNameID: Did not find persistent NameID for user, and not allowed to create new NameID.'
158 );
160 \
SAML2\Constants::STATUS_RESPONDER,
161 'urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy'
162 );
163 }
164
165 $value = bin2hex(openssl_random_pseudo_bytes(20));
167 'SQLPersistentNameID: Created persistent NameID '.var_export($value, true).' for user '.
168 var_export($uid, true).'.'
169 );
171
172 return $value;
173 }
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
static add($idpEntityId, $spEntityId, $user, $value)
Add a NameID into the database.
static get($idpEntityId, $spEntityId, $user)
Retrieve a NameID into from database.