ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
StatisticsWithAttribute.php
Go to the documentation of this file.
1 <?php
2 
10 {
15  private $attribute = null;
16 
20  private $typeTag = 'saml20-idp-SSO';
21 
25  private $skipPassive = false;
26 
27 
34  public function __construct($config, $reserved)
35  {
36  parent::__construct($config, $reserved);
37 
38  assert(is_array($config));
39 
40  if (array_key_exists('attributename', $config)) {
41  $this->attribute = $config['attributename'];
42  if (!is_string($this->attribute)) {
43  throw new Exception('Invalid attribute name given to core:StatisticsWithAttribute filter.');
44  }
45  }
46 
47  if (array_key_exists('type', $config)) {
48  $this->typeTag = $config['type'];
49  if (!is_string($this->typeTag)) {
50  throw new Exception('Invalid typeTag given to core:StatisticsWithAttribute filter.');
51  }
52  }
53 
54  if (array_key_exists('skipPassive', $config)) {
55  $this->skipPassive = (bool) $config['skipPassive'];
56  }
57  }
58 
59 
65  public function process(&$state)
66  {
67  assert(is_array($state));
68  assert(array_key_exists('Attributes', $state));
69 
70  $logAttribute = 'NA';
71  $isPassive = '';
72 
73  if (array_key_exists('isPassive', $state) && $state['isPassive'] === true) {
74  if ($this->skipPassive === true) {
75  // We have a passive request. Skip logging statistics
76  return;
77  }
78  $isPassive = 'passive-';
79  }
80 
81  if (array_key_exists($this->attribute, $state['Attributes'])) {
82  $logAttribute = $state['Attributes'][$this->attribute][0];
83  }
84 
85  $source = $this->setIdentifier('Source', $state);
86  $dest = $this->setIdentifier('Destination', $state);
87 
88  if (!array_key_exists('PreviousSSOTimestamp', $state)) {
89  // The user hasn't authenticated with this SP earlier in this session
90  SimpleSAML\Logger::stats($isPassive.$this->typeTag.'-first '.$dest.' '.$source.' '. $logAttribute);
91  }
92 
93  SimpleSAML\Logger::stats($isPassive.$this->typeTag.' '.$dest.' '.$source.' '.$logAttribute);
94  }
95 
102  private function setIdentifier($direction, $state)
103  {
104  if (array_key_exists($direction, $state)) {
105  if (isset($state[$direction]['core:statistics-id'])) {
106  return $state[$direction]['core:statistics-id'];
107  } else {
108  return $state[$direction]['entityid'];
109  }
110  }
111  return 'NA';
112  }
113 }
$config
Definition: bootstrap.php:15
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static stats($string)
Definition: Logger.php:222
__construct($config, $reserved)
Initialize this filter.
$source
Definition: linkback.php:22