ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SmartID.php
Go to the documentation of this file.
1<?php
2
4
12 private $_candidates = array(
13 'eduPersonTargetedID',
14 'eduPersonPrincipalName',
15 'openid',
16 'facebook_targetedID',
17 'twitter_targetedID',
18 'windowslive_targetedID',
19 'myspace_targetedID',
20 'linkedin_targetedID',
21 );
22
26 private $_id_attribute = 'smart_id';
27
32 private $_add_authority = true;
33
37 private $_add_candidate = true;
38
44 private $attributes = array();
45
46
47 public function __construct($config, $reserved) {
48 parent::__construct($config, $reserved);
49
50 assert('is_array($config)');
51
52 if (array_key_exists('candidates', $config)) {
53 $this->_candidates = $config['candidates'];
54 if (!is_array($this->_candidates)) {
55 throw new Exception('SmartID authproc configuration error: \'candidates\' should be an array.');
56 }
57 }
58
59 if (array_key_exists('id_attribute', $config)) {
60 $this->_id_attribute = $config['id_attribute'];
61 if (!is_string($this->_id_attribute)) {
62 throw new Exception('SmartID authproc configuration error: \'id_attribute\' should be a string.');
63 }
64 }
65
66 if (array_key_exists('add_authority', $config)) {
67 $this->_add_authority = $config['add_authority'];
68 if (!is_bool($this->_add_authority)) {
69 throw new Exception('SmartID authproc configuration error: \'add_authority\' should be a boolean.');
70 }
71 }
72
73 if (array_key_exists('add_candidate', $config)) {
74 $this->_add_candidate = $config['add_candidate'];
75 if (!is_bool($this->_add_candidate)) {
76 throw new Exception('SmartID authproc configuration error: \'add_candidate\' should be a boolean.');
77 }
78 }
79
80 }
81
82 private function addID($attributes, $request) {
83 foreach ($this->_candidates as $idCandidate) {
84 if (isset($attributes[$idCandidate][0])) {
85 if(($this->_add_authority) && (isset($request['saml:AuthenticatingAuthority'][0]))) {
86 return ($this->_add_candidate ? $idCandidate.':' : '').$attributes[$idCandidate][0] . '!' . $request['saml:AuthenticatingAuthority'][0];
87 } else {
88 return ($this->_add_candidate ? $idCandidate.':' : '').$attributes[$idCandidate][0];
89 }
90 }
91 }
92 /*
93 * At this stage no usable id_candidate has been detected.
94 */
95 throw new SimpleSAML_Error_Exception('This service needs at least one of the following
96 attributes to identity users: '.implode(', ', $this->_candidates).'. Unfortunately not
97 one of them was detected. Please ask your institution administrator to release one of
98 them, or try using another identity provider.');
99 }
100
101
109 public function process(&$request) {
110 assert('is_array($request)');
111 assert('array_key_exists("Attributes", $request)');
112
113 $ID = $this->addID($request['Attributes'], $request);
114
115 if(isset($ID)) $request['Attributes'][$this->_id_attribute] = array($ID);
116 }
117}
An exception for terminatinating execution or to throw for unit testing.
process(&$request)
Apply filter to add or replace attributes.
Definition: SmartID.php:109
$_id_attribute
The name of the generated ID attribute.
Definition: SmartID.php:26
$attributes
Attributes which should be added/appended.
Definition: SmartID.php:44
$_add_candidate
Whether to prepend the CandidateID, separated by ':'.
Definition: SmartID.php:37
$_candidates
Which attributes to use as identifiers?
Definition: SmartID.php:12
$_add_authority
Whether to append the AuthenticatingAuthority, separated by '!' This only works when SSP is used as a...
Definition: SmartID.php:32