ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SQLNameID.php
Go to the documentation of this file.
1<?php
2
9
15 private static function createTable(\SimpleSAML\Store\SQL $store) {
16
17 if ($store->getTableVersion('saml_PersistentNameID') === 1) {
18 return;
19 }
20
21 $query = 'CREATE TABLE ' . $store->prefix . '_saml_PersistentNameID (
22 _idp VARCHAR(256) NOT NULL,
23 _sp VARCHAR(256) NOT NULL,
24 _user VARCHAR(256) NOT NULL,
25 _value VARCHAR(40) NOT NULL,
26 UNIQUE (_idp, _sp, _user)
27 )';
28 $store->pdo->exec($query);
29
30 $query = 'CREATE INDEX ' . $store->prefix . '_saml_PersistentNameID_idp_sp ON ' . $store->prefix . '_saml_PersistentNameID (_idp, _sp)';
31 $store->pdo->exec($query);
32
33 $store->setTableVersion('saml_PersistentNameID', 1);
34 }
35
36
44 private static function getStore() {
45
47 if (!($store instanceof \SimpleSAML\Store\SQL)) {
48 throw new SimpleSAML_Error_Exception('SQL NameID store requires SimpleSAMLphp to be configured with a SQL datastore.');
49 }
50
52
53 return $store;
54 }
55
56
66 public static function add($idpEntityId, $spEntityId, $user, $value) {
67 assert('is_string($idpEntityId)');
68 assert('is_string($spEntityId)');
69 assert('is_string($user)');
70 assert('is_string($value)');
71
73
74 $params = array(
75 '_idp' => $idpEntityId,
76 '_sp' => $spEntityId,
77 '_user' => $user,
78 '_value' => $value,
79 );
80
81 $query = 'INSERT INTO ' . $store->prefix . '_saml_PersistentNameID (_idp, _sp, _user, _value) VALUES(:_idp, :_sp, :_user, :_value)';
82 $query = $store->pdo->prepare($query);
83 $query->execute($params);
84 }
85
86
95 public static function get($idpEntityId, $spEntityId, $user) {
96 assert('is_string($idpEntityId)');
97 assert('is_string($spEntityId)');
98 assert('is_string($user)');
99
101
102 $params = array(
103 '_idp' => $idpEntityId,
104 '_sp' => $spEntityId,
105 '_user' => $user,
106 );
107
108 $query = 'SELECT _value FROM ' . $store->prefix . '_saml_PersistentNameID WHERE _idp = :_idp AND _sp = :_sp AND _user = :_user';
109 $query = $store->pdo->prepare($query);
110 $query->execute($params);
111
112 $row = $query->fetch(PDO::FETCH_ASSOC);
113 if ($row === FALSE) {
114 // No NameID found
115 return NULL;
116 }
117
118 return $row['_value'];
119 }
120
121
129 public static function delete($idpEntityId, $spEntityId, $user) {
130 assert('is_string($idpEntityId)');
131 assert('is_string($spEntityId)');
132 assert('is_string($user)');
133
135
136 $params = array(
137 '_idp' => $idpEntityId,
138 '_sp' => $spEntityId,
139 '_user' => $user,
140 );
141
142 $query = 'DELETE FROM ' . $store->prefix . '_saml_PersistentNameID WHERE _idp = :_idp AND _sp = :_sp AND _user = :_user';
143 $query = $store->pdo->prepare($query);
144 $query->execute($params);
145 }
146
147
155 public static function getIdentities($idpEntityId, $spEntityId) {
156 assert('is_string($idpEntityId)');
157 assert('is_string($spEntityId)');
158
160
161 $params = array(
162 '_idp' => $idpEntityId,
163 '_sp' => $spEntityId,
164 );
165
166 $query = 'SELECT _user, _value FROM ' . $store->prefix . '_saml_PersistentNameID WHERE _idp = :_idp AND _sp = :_sp';
167 $query = $store->pdo->prepare($query);
168 $query->execute($params);
169
170 $res = array();
171 while ( ($row = $query->fetch(PDO::FETCH_ASSOC)) !== FALSE) {
172 $res[$row['_user']] = $row['_value'];
173 }
174
175 return $res;
176 }
177
178}
$spEntityId
An exception for terminatinating execution or to throw for unit testing.
static getInstance()
Retrieve our singleton instance.
Definition: Store.php:31
static getIdentities($idpEntityId, $spEntityId)
Retrieve all federated identities for an IdP-SP pair.
Definition: SQLNameID.php:155
static add($idpEntityId, $spEntityId, $user, $value)
Add a NameID into the database.
Definition: SQLNameID.php:66
static getStore()
Retrieve the SQL datastore.
Definition: SQLNameID.php:44
static createTable(\SimpleSAML\Store\SQL $store)
Create NameID table in SQL, if it is missing.
Definition: SQLNameID.php:15
if(! $oauthconfig->getBoolean('getUserInfo.enable', FALSE)) $store
Definition: getUserInfo.php:11
Attribute-related utility methods.
$query
$idpEntityId
Definition: prp.php:12
foreach($_POST as $key=> $value) $res
$params
Definition: disable.php:11