ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 'linkedin_targetedID',
20 );
21
25 private $_id_attribute = 'smart_id';
26
31 private $_add_authority = true;
32
36 private $_add_candidate = true;
37
43 private $attributes = array();
44
45
46 public function __construct($config, $reserved)
47 {
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 private function addID($attributes, $request)
82 {
83 $state = $request['saml:sp:State'];
84 foreach ($this->_candidates as $idCandidate) {
85 if (isset($attributes[$idCandidate][0])) {
86 if (($this->_add_authority) && (isset($state['saml:AuthenticatingAuthority'][0]))) {
87 return ($this->_add_candidate ? $idCandidate.':' : '').$attributes[$idCandidate][0].'!'.$state['saml:AuthenticatingAuthority'][0];
88 } else {
89 return ($this->_add_candidate ? $idCandidate.':' : '').$attributes[$idCandidate][0];
90 }
91 }
92 }
93 /*
94 * At this stage no usable id_candidate has been detected.
95 */
96 throw new SimpleSAML_Error_Exception('This service needs at least one of the following
97 attributes to identity users: '.implode(', ', $this->_candidates).'. Unfortunately not
98 one of them was detected. Please ask your institution administrator to release one of
99 them, or try using another identity provider.');
100 }
101
109 public function process(&$request)
110 {
111 assert(is_array($request));
112 assert(array_key_exists('Attributes', $request));
113
114 $id = $this->addID($request['Attributes'], $request);
115
116 if (isset($id)) {
117 $request['Attributes'][$this->_id_attribute] = array($id);
118 }
119 }
120}
foreach($paths as $path) $request
Definition: asyncclient.php:32
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.
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:25
$attributes
Attributes which should be added/appended.
Definition: SmartID.php:43
$_add_candidate
Whether to prepend the CandidateID, separated by ':'.
Definition: SmartID.php:36
$_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:31
if(!array_key_exists('StateId', $_REQUEST)) $id
$config
Definition: bootstrap.php:15