diff --git a/modules/core/lib/Auth/Process/StatisticsWithAttribute.php b/modules/core/lib/Auth/Process/StatisticsWithAttribute.php index 965533a2dbbc520d62a32a5104b90192fab071f4..b7fe957fa2b6c68e0ac39ecc9271004f5296b43a 100644 --- a/modules/core/lib/Auth/Process/StatisticsWithAttribute.php +++ b/modules/core/lib/Auth/Process/StatisticsWithAttribute.php @@ -6,83 +6,91 @@ * @author Andreas Ă…kre Solberg, UNINETT AS. * @package SimpleSAMLphp */ -class sspmod_core_Auth_Process_StatisticsWithAttribute extends SimpleSAML_Auth_ProcessingFilter { - - - /** - * The attribute to log - */ - private $attribute = NULL; - - private $typeTag = 'saml20-idp-SSO'; - - private $skipPassive = false; - - - /** - * Initialize this filter. - * - * @param array $config Configuration information about this filter. - * @param mixed $reserved For future use. - */ - public function __construct($config, $reserved) { - parent::__construct($config, $reserved); - - assert(is_array($config)); - - if (array_key_exists('attributename', $config)) { - $this->attribute = $config['attributename']; - if (!is_string($this->attribute)) { - throw new Exception('Invalid attribute name given to core:StatisticsWithAttribute filter.'); - } - } - - if (array_key_exists('type', $config)) { - $this->typeTag = $config['type']; - if (!is_string($this->typeTag)) { - throw new Exception('Invalid typeTag given to core:StatisticsWithAttribute filter.'); - } - } - - if (array_key_exists('skipPassive', $config)) { - $this->skipPassive = (bool)$config['skipPassive']; - } - } +class sspmod_core_Auth_Process_StatisticsWithAttribute extends SimpleSAML_Auth_ProcessingFilter +{ + /** + * The attribute to log + * @var string|null + */ + private $attribute = null; + + /** + * @var string + */ + private $typeTag = 'saml20-idp-SSO'; + + /** + * @var bool + */ + private $skipPassive = false; - /** - * Log line. - * - * @param array &$state The current state. - */ - public function process(&$state) { - assert(is_array($state)); - assert(array_key_exists('Attributes', $state)); + /** + * Initialize this filter. + * + * @param array $config Configuration information about this filter. + * @param mixed $reserved For future use. + */ + public function __construct($config, $reserved) + { + parent::__construct($config, $reserved); - $logAttribute = 'NA'; - $isPassive = ''; + assert(is_array($config)); - if (array_key_exists('isPassive', $state) && $state['isPassive'] === true) { - if ($this->skipPassive === true) { - // We have a passive request. Skip logging statistics - return; - } - $isPassive = 'passive-'; - } + if (array_key_exists('attributename', $config)) { + $this->attribute = $config['attributename']; + if (!is_string($this->attribute)) { + throw new Exception('Invalid attribute name given to core:StatisticsWithAttribute filter.'); + } + } + + if (array_key_exists('type', $config)) { + $this->typeTag = $config['type']; + if (!is_string($this->typeTag)) { + throw new Exception('Invalid typeTag given to core:StatisticsWithAttribute filter.'); + } + } - if (array_key_exists($this->attribute, $state['Attributes'])) { + if (array_key_exists('skipPassive', $config)) { + $this->skipPassive = (bool) $config['skipPassive']; + } + } + + + /** + * Log line. + * + * @param array &$state The current state. + */ + public function process(&$state) + { + assert(is_array($state)); + assert(array_key_exists('Attributes', $state)); + + $logAttribute = 'NA'; + $isPassive = ''; + + if (array_key_exists('isPassive', $state) && $state['isPassive'] === true) { + if ($this->skipPassive === true) { + // We have a passive request. Skip logging statistics + return; + } + $isPassive = 'passive-'; + } + + if (array_key_exists($this->attribute, $state['Attributes'])) { $logAttribute = $state['Attributes'][$this->attribute][0]; } $source = $this->setIdentifier('Source', $state); $dest = $this->setIdentifier('Destination', $state); - if (!array_key_exists('PreviousSSOTimestamp', $state)) { - // The user hasn't authenticated with this SP earlier in this session - SimpleSAML\Logger::stats($isPassive . $this->typeTag . '-first ' . $dest . ' ' . $source . ' ' . $logAttribute); - } + if (!array_key_exists('PreviousSSOTimestamp', $state)) { + // The user hasn't authenticated with this SP earlier in this session + SimpleSAML\Logger::stats($isPassive.$this->typeTag.'-first '.$dest.' '.$source.' '. $logAttribute); + } - SimpleSAML\Logger::stats($isPassive . $this->typeTag . ' ' . $dest . ' ' . $source . ' ' . $logAttribute); + SimpleSAML\Logger::stats($isPassive.$this->typeTag.' '.$dest.' '.$source.' '.$logAttribute); } /** @@ -90,16 +98,16 @@ class sspmod_core_Auth_Process_StatisticsWithAttribute extends SimpleSAML_Auth_P * @param array $state The current state. * * @return string - */ + */ private function setIdentitier($direction, $state) { if (array_key_exists($direction, $state)) { - if (isset($state[$direction]['core:statistics-id'])) { - return $state[$direction]['core:statistics-id']; - } else { - return $state[$direction]['entityid']; - } - } + if (isset($state[$direction]['core:statistics-id'])) { + return $state[$direction]['core:statistics-id']; + } else { + return $state[$direction]['entityid']; + } + } return 'NA'; } }