Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 3088ed6

Browse files
Merge pull request #108 from BaranekD/log_filter
Added process filter for logging info about login
2 parents 30eb2bb + 17dd473 commit 3088ed6

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44
## [Unreleased]
55
#### Added
66
- Added facility capabilities to PerunEntitlement
7+
- Added process filter for logging info about login
78

89
#### Changed
910
- Use object `Configuration` for getting base module configuration

lib/Auth/Process/LoginInfo.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)