|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SimpleSAML\Module\perun\Auth\Process; |
| 4 | + |
| 5 | +use SimpleSAML\Auth\ProcessingFilter; |
| 6 | +use SimpleSAML\Configuration; |
| 7 | +use SimpleSAML\Logger; |
| 8 | + |
| 9 | +class LoginInfo extends ProcessingFilter |
| 10 | +{ |
| 11 | + const ATTRS = 'attrs'; |
| 12 | + const SOURCE_IDP_ATTR = 'sourceIdPAttr'; |
| 13 | + const SOURCE_IDENTIFIER_ATTR = 'sourceIdentifierAttr'; |
| 14 | + |
| 15 | + private $attrs; |
| 16 | + private $sourceIdpAttr; |
| 17 | + private $sourceIdentifierAttr; |
| 18 | + |
| 19 | + public function __construct($config, $reserved) |
| 20 | + { |
| 21 | + parent::__construct($config, $reserved); |
| 22 | + $config = Configuration::loadFromArray($config); |
| 23 | + $this->attrs = $config->getArray(self::ATTRS); |
| 24 | + $this->sourceIdpAttr = $config->getString(self::SOURCE_IDP_ATTR, ''); |
| 25 | + $this->sourceIdentifierAttr = $config->getString(self::SOURCE_IDENTIFIER_ATTR, ''); |
| 26 | + } |
| 27 | + |
| 28 | + public function process(&$request) |
| 29 | + { |
| 30 | + $spEntityId = $request['SPMetadata']['entityid']; |
| 31 | + |
| 32 | + $finalString = 'User '; |
| 33 | + |
| 34 | + if (isset($request['perun']['user'])) { |
| 35 | + $user = $request['perun']['user']; |
| 36 | + $finalString .= 'ID: ' . $user->getId() . ', '; |
| 37 | + } |
| 38 | + |
| 39 | + if (!empty($this->attrs)) { |
| 40 | + $finalString .= 'identifiers: ['; |
| 41 | + |
| 42 | + foreach ($this->attrs as $attr) { |
| 43 | + if (isset($request['Attributes'][$attr][0])) { |
| 44 | + $finalString .= $attr . ': ' . $request['Attributes'][$attr][0] . ', '; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + $finalString = substr($finalString, 0, -2) . '], '; |
| 49 | + } |
| 50 | + |
| 51 | + $finalString .= 'service: ' . $spEntityId; |
| 52 | + |
| 53 | + if (!empty($this->sourceIdentifierAttr) && isset($request['Attributes'][$this->sourceIdentifierAttr][0])) { |
| 54 | + $finalString .= ', external identity: ' . $request['Attributes'][$this->sourceIdentifierAttr][0]; |
| 55 | + if (!empty($this->sourceIdpAttr) && isset($request['Attributes'][$this->sourceIdpAttr][0])) { |
| 56 | + $finalString .= ' from ' . $request['Attributes'][$this->sourceIdpAttr][0]; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + Logger::notice($finalString); |
| 61 | + } |
| 62 | +} |
0 commit comments