ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
sspmod_consent_Auth_Process_Consent Class Reference
+ Inheritance diagram for sspmod_consent_Auth_Process_Consent:
+ Collaboration diagram for sspmod_consent_Auth_Process_Consent:

Public Member Functions

 __construct ($config, $reserved)
 Initialize consent filter. More...
 
 process (&$state)
 Process a authentication response. More...
 
- Public Member Functions inherited from SimpleSAML_Auth_ProcessingFilter
 __construct (&$config, $reserved)
 Constructor for a processing filter. More...
 
 process (&$request)
 Process a request. More...
 

Static Public Member Functions

static getHashedUserID ($userid, $source)
 Generate a unique identifier of the user. More...
 
static getTargetedID ($userid, $source, $destination)
 Generate a unique targeted identifier. More...
 
static getAttributeHash ($attributes, $includeValues=false)
 Generate unique identifier for attributes. More...
 

Static Private Member Functions

static checkDisable ($option, $entityId)
 Helper function to check whether consent is disabled. More...
 

Private Attributes

 $_focus = null
 
 $_includeValues = false
 
 $_checked = false
 
 $_store = null
 
 $_hiddenAttributes = array()
 
 $_noconsentattributes = array()
 
 $_showNoConsentAboutService = true
 

Additional Inherited Members

- Data Fields inherited from SimpleSAML_Auth_ProcessingFilter
 $priority = 50
 Priority of this filter. More...
 

Detailed Description

Definition at line 12 of file Consent.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_consent_Auth_Process_Consent::__construct (   $config,
  $reserved 
)

Initialize consent filter.

Validates and parses the configuration.

Parameters
array$configConfiguration information.
mixed$reservedFor future use.
Exceptions
SimpleSAML_Error_Exceptionif the configuration is not valid.

Definition at line 74 of file Consent.php.

75 {
76 assert(is_array($config));
77 parent::__construct($config, $reserved);
78
79 if (array_key_exists('includeValues', $config)) {
80 if (!is_bool($config['includeValues'])) {
82 'Consent: includeValues must be boolean. '.
83 var_export($config['includeValues'], true).' given.'
84 );
85 }
86 $this->_includeValues = $config['includeValues'];
87 }
88
89 if (array_key_exists('checked', $config)) {
90 if (!is_bool($config['checked'])) {
92 'Consent: checked must be boolean. '.
93 var_export($config['checked'], true).' given.'
94 );
95 }
96 $this->_checked = $config['checked'];
97 }
98
99 if (array_key_exists('focus', $config)) {
100 if (!in_array($config['focus'], array('yes', 'no'), true)) {
102 'Consent: focus must be a string with values `yes` or `no`. '.
103 var_export($config['focus'], true).' given.'
104 );
105 }
106 $this->_focus = $config['focus'];
107 }
108
109 if (array_key_exists('hiddenAttributes', $config)) {
110 if (!is_array($config['hiddenAttributes'])) {
112 'Consent: hiddenAttributes must be an array. '.
113 var_export($config['hiddenAttributes'], true).' given.'
114 );
115 }
116 $this->_hiddenAttributes = $config['hiddenAttributes'];
117 }
118
119 if (array_key_exists('attributes.exclude', $config)) {
120 if (!is_array($config['attributes.exclude'])) {
122 'Consent: attributes.exclude must be an array. '.
123 var_export($config['attributes.exclude'], true).' given.'
124 );
125 }
126 $this->_noconsentattributes = $config['attributes.exclude'];
127 } elseif (array_key_exists('noconsentattributes', $config)) {
128 SimpleSAML\Logger::warning("The 'noconsentattributes' option has been deprecated in favour of 'attributes.exclude'.");
129 if (!is_array($config['noconsentattributes'])) {
131 'Consent: noconsentattributes must be an array. '.
132 var_export($config['noconsentattributes'], true).' given.'
133 );
134 }
135 $this->_noconsentattributes = $config['noconsentattributes'];
136 }
137
138 if (array_key_exists('store', $config)) {
139 try {
140 $this->_store = sspmod_consent_Store::parseStoreConfig($config['store']);
141 } catch (Exception $e) {
143 'Consent: Could not create consent storage: '.
144 $e->getMessage()
145 );
146 }
147 }
148
149 if (array_key_exists('showNoConsentAboutService', $config)) {
150 if (!is_bool($config['showNoConsentAboutService'])) {
151 throw new SimpleSAML_Error_Exception('Consent: showNoConsentAboutService must be a boolean.');
152 }
153 $this->_showNoConsentAboutService = $config['showNoConsentAboutService'];
154 }
155 }
static warning($string)
Definition: Logger.php:177
static error($string)
Definition: Logger.php:166
$config
Definition: bootstrap.php:15

References $config, SimpleSAML\Logger\error(), sspmod_consent_Store\parseStoreConfig(), and SimpleSAML\Logger\warning().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkDisable()

static sspmod_consent_Auth_Process_Consent::checkDisable (   $option,
  $entityId 
)
staticprivate

Helper function to check whether consent is disabled.

Parameters
mixed$optionThe consent.disable option. Either an array of array, an array or a boolean.
string$entityIdThe entityID of the SP/IdP.
Returns
boolean True if disabled, false if not.

Definition at line 166 of file Consent.php.

167 {
168 if (is_array($option)) {
169 // Check if consent.disable array has one element that is an array
170 if (count($option) === count($option, COUNT_RECURSIVE)) {
171 // Array is not multidimensional. Simple in_array search suffices
172 return in_array($entityId, $option, true);
173 }
174
175 // Array contains at least one element that is an array, verify both possibilities
176 if (in_array($entityId, $option, true)) {
177 return true;
178 }
179
180 // Search in multidimensional arrays
181 foreach ($option as $optionToTest) {
182 if (!is_array($optionToTest)) {
183 continue; // bad option
184 }
185
186 if (!array_key_exists('type', $optionToTest)) {
187 continue; // option has no type
188 }
189
190 // Option has a type - switch processing depending on type value :
191 if ($optionToTest['type'] === 'regex') {
192 // regex-based consent disabling
193
194 if (!array_key_exists('pattern', $optionToTest)) {
195 continue; // no pattern defined
196 }
197
198 if (preg_match($optionToTest['pattern'], $entityId) === 1) {
199 return true;
200 }
201 } else {
202 // option type is not supported
203 continue;
204 }
205 } // end foreach
206
207 // Base case : no match
208 return false;
209 } else {
210 return (boolean) $option;
211 }
212 }
if( $source===null) if(!($source instanceof sspmod_saml_Auth_Source_SP)) $entityId
Definition: metadata.php:22

References $entityId.

◆ getAttributeHash()

static sspmod_consent_Auth_Process_Consent::getAttributeHash (   $attributes,
  $includeValues = false 
)
static

Generate unique identifier for attributes.

Create a hash value for the attributes that changes when attributes are added or removed. If the attribute values are included in the hash, the hash will change if the values change.

Parameters
string$attributesThe attributes.
bool$includeValuesWhether or not to include the attribute value in the generation of the hash.
Returns
string SHA1 of the user id, source id, destination id and salt.

Definition at line 384 of file Consent.php.

385 {
386 if ($includeValues) {
387 foreach ($attributes as &$values) {
388 sort($values);
389 }
390 ksort($attributes);
391 $hashBase = serialize($attributes);
392 } else {
393 $names = array_keys($attributes);
394 sort($names);
395 $hashBase = implode('|', $names);
396 }
397 return hash('sha1', $hashBase);
398 }
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
$values

References $attributes, $values, and GuzzleHttp\Psr7\hash().

Referenced by driveProcessingChain(), and process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHashedUserID()

static sspmod_consent_Auth_Process_Consent::getHashedUserID (   $userid,
  $source 
)
static

Generate a unique identifier of the user.

Parameters
string$useridThe user id.
string$sourceThe source id.
Returns
string SHA1 of the user id, source id and salt.

Definition at line 352 of file Consent.php.

353 {
354 return hash('sha1', $userid.'|'.SimpleSAML\Utils\Config::getSecretSalt().'|'.$source);
355 }
$source
Definition: linkback.php:22
if(empty($userids)) $userid
Attribute-related utility methods.

References $source, $userid, and GuzzleHttp\Psr7\hash().

Referenced by process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTargetedID()

static sspmod_consent_Auth_Process_Consent::getTargetedID (   $userid,
  $source,
  $destination 
)
static

Generate a unique targeted identifier.

Parameters
string$useridThe user id.
string$sourceThe source id.
string$destinationThe destination id.
Returns
string SHA1 of the user id, source id, destination id and salt.

Definition at line 367 of file Consent.php.

368 {
369 return hash('sha1', $userid.'|'.SimpleSAML\Utils\Config::getSecretSalt().'|'.$source.'|'.$destination);
370 }
$destination

References $destination, $source, $userid, and GuzzleHttp\Psr7\hash().

Referenced by driveProcessingChain(), and process().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ process()

sspmod_consent_Auth_Process_Consent::process ( $state)

Process a authentication response.

This function saves the state, and redirects the user to the page where the user can authorize the release of the attributes. If storage is used and the consent has already been given the user is passed on.

Parameters
array&$stateThe state of the response.
Returns
void
Exceptions
SimpleSAML_Error_NoPassiveif the request was passive and consent is needed.

If the consent module is active on a bridge $state['saml:sp:IdP'] will contain an entry id for the remote IdP. If not, then the consent module is active on a local IdP and nothing needs to be done.

Reimplemented from SimpleSAML_Auth_ProcessingFilter.

Definition at line 227 of file Consent.php.

228 {
229 assert(is_array($state));
230 assert(array_key_exists('UserID', $state));
231 assert(array_key_exists('Destination', $state));
232 assert(array_key_exists('entityid', $state['Destination']));
233 assert(array_key_exists('metadata-set', $state['Destination']));
234 assert(array_key_exists('entityid', $state['Source']));
235 assert(array_key_exists('metadata-set', $state['Source']));
236
237 $spEntityId = $state['Destination']['entityid'];
238 $idpEntityId = $state['Source']['entityid'];
239
241
248 if (isset($state['saml:sp:IdP'])) {
249 $idpEntityId = $state['saml:sp:IdP'];
250 $idpmeta = $metadata->getMetaData($idpEntityId, 'saml20-idp-remote');
251 $state['Source'] = $idpmeta;
252 }
253
254 $statsData = array('spEntityID' => $spEntityId);
255
256 // Do not use consent if disabled
257 if (isset($state['Source']['consent.disable']) &&
258 self::checkDisable($state['Source']['consent.disable'], $spEntityId)
259 ) {
260 SimpleSAML\Logger::debug('Consent: Consent disabled for entity '.$spEntityId.' with IdP '.$idpEntityId);
261 SimpleSAML_Stats::log('consent:disabled', $statsData);
262 return;
263 }
264 if (isset($state['Destination']['consent.disable']) &&
265 self::checkDisable($state['Destination']['consent.disable'], $idpEntityId)
266 ) {
267 SimpleSAML\Logger::debug('Consent: Consent disabled for entity '.$spEntityId.' with IdP '.$idpEntityId);
268 SimpleSAML_Stats::log('consent:disabled', $statsData);
269 return;
270 }
271
272 if ($this->_store !== null) {
273 $source = $state['Source']['metadata-set'].'|'.$idpEntityId;
274 $destination = $state['Destination']['metadata-set'].'|'.$spEntityId;
275 $attributes = $state['Attributes'];
276
277 // Remove attributes that do not require consent
278 foreach ($attributes as $attrkey => $attrval) {
279 if (in_array($attrkey, $this->_noconsentattributes, true)) {
280 unset($attributes[$attrkey]);
281 }
282 }
283
284 SimpleSAML\Logger::debug('Consent: userid: '.$state['UserID']);
285 SimpleSAML\Logger::debug('Consent: source: '.$source);
286 SimpleSAML\Logger::debug('Consent: destination: '.$destination);
287
288 $userId = self::getHashedUserID($state['UserID'], $source);
289 $targetedId = self::getTargetedID($state['UserID'], $source, $destination);
290 $attributeSet = self::getAttributeHash($attributes, $this->_includeValues);
291
293 'Consent: hasConsent() ['.$userId.'|'.$targetedId.'|'.
294 $attributeSet.']'
295 );
296
297 try {
298 if ($this->_store->hasConsent($userId, $targetedId, $attributeSet)) {
299 // Consent already given
300 SimpleSAML\Logger::stats('consent found');
301 SimpleSAML_Stats::log('consent:found', $statsData);
302 return;
303 }
304
305 SimpleSAML\Logger::stats('consent notfound');
306 SimpleSAML_Stats::log('consent:notfound', $statsData);
307
308 $state['consent:store'] = $this->_store;
309 $state['consent:store.userId'] = $userId;
310 $state['consent:store.destination'] = $targetedId;
311 $state['consent:store.attributeSet'] = $attributeSet;
312 } catch (Exception $e) {
313 SimpleSAML\Logger::error('Consent: Error reading from storage: '.$e->getMessage());
314 SimpleSAML\Logger::stats('Ccnsent failed');
315 SimpleSAML_Stats::log('consent:failed', $statsData);
316 }
317 } else {
318 SimpleSAML\Logger::stats('consent nostorage');
319 SimpleSAML_Stats::log('consent:nostorage', $statsData);
320 }
321
322 $state['consent:focus'] = $this->_focus;
323 $state['consent:checked'] = $this->_checked;
324 $state['consent:hiddenAttributes'] = $this->_hiddenAttributes;
325 $state['consent:noconsentattributes'] = $this->_noconsentattributes;
326 $state['consent:showNoConsentAboutService'] = $this->_showNoConsentAboutService;
327
328 // user interaction necessary. Throw exception on isPassive request
329 if (isset($state['isPassive']) && $state['isPassive'] === true) {
330 SimpleSAML_Stats::log('consent:nopassive', $statsData);
332 \SAML2\Constants::STATUS_REQUESTER,
333 'Unable to give consent on passive request.'
334 );
335 }
336
337 // Save state and redirect
338 $id = SimpleSAML_Auth_State::saveState($state, 'consent:request');
339 $url = SimpleSAML\Module::getModuleURL('consent/getconsent.php');
341 }
$metadata['__DYNAMIC:1__']
$spEntityId
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static stats($string)
Definition: Logger.php:222
static debug($string)
Definition: Logger.php:211
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:220
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:959
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
static getMetadataHandler()
This function retrieves the current instance of the metadata handler.
static log($event, array $data=array())
Notify about an event.
Definition: Stats.php:71
if(!array_key_exists('StateId', $_REQUEST)) $id
$idpmeta
Definition: metadata.php:20
$url
$idpEntityId
Definition: prp.php:12

References $_checked, $_focus, $_hiddenAttributes, $_noconsentattributes, $_showNoConsentAboutService, $_store, $attributes, $destination, $id, $idpEntityId, $idpmeta, $metadata, $source, $spEntityId, $state, $url, SimpleSAML\Logger\debug(), SimpleSAML\Logger\error(), getAttributeHash(), getHashedUserID(), SimpleSAML_Metadata_MetaDataStorageHandler\getMetadataHandler(), SimpleSAML\Module\getModuleURL(), getTargetedID(), SimpleSAML_Stats\log(), SimpleSAML\Utils\HTTP\redirectTrustedURL(), SimpleSAML_Auth_State\saveState(), and SimpleSAML\Logger\stats().

+ Here is the call graph for this function:

Field Documentation

◆ $_checked

sspmod_consent_Auth_Process_Consent::$_checked = false
private

Definition at line 33 of file Consent.php.

Referenced by process().

◆ $_focus

sspmod_consent_Auth_Process_Consent::$_focus = null
private

Definition at line 19 of file Consent.php.

Referenced by process().

◆ $_hiddenAttributes

sspmod_consent_Auth_Process_Consent::$_hiddenAttributes = array()
private

Definition at line 47 of file Consent.php.

Referenced by process().

◆ $_includeValues

sspmod_consent_Auth_Process_Consent::$_includeValues = false
private

Definition at line 26 of file Consent.php.

◆ $_noconsentattributes

sspmod_consent_Auth_Process_Consent::$_noconsentattributes = array()
private

Definition at line 54 of file Consent.php.

Referenced by process().

◆ $_showNoConsentAboutService

sspmod_consent_Auth_Process_Consent::$_showNoConsentAboutService = true
private

Definition at line 61 of file Consent.php.

Referenced by process().

◆ $_store

sspmod_consent_Auth_Process_Consent::$_store = null
private

Definition at line 40 of file Consent.php.

Referenced by process().


The documentation for this class was generated from the following file: