1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DMK\MKSamlAuth\Enricher; |
6
|
|
|
|
7
|
|
|
use DMK\MKSamlAuth\Model\FrontendUser; |
8
|
|
|
use Doctrine\DBAL\Connection; |
9
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
10
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
11
|
|
|
|
12
|
|
|
class SSOGroupEnricher implements EnricherInterface |
13
|
|
|
{ |
14
|
|
|
const ATTRIBUTE_KEY = 'memberof'; |
15
|
|
|
|
16
|
|
|
public function process(FrontendUser $user, array $context) |
17
|
|
|
{ |
18
|
|
|
$names = $context['attributes'][self::ATTRIBUTE_KEY] ?? []; |
19
|
|
|
$names = \is_array($names) ? $names : [$names]; |
20
|
|
|
|
21
|
|
|
if (0 === \count($names)) { |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$qb = GeneralUtility::makeInstance(ConnectionPool::class) |
26
|
|
|
->getQueryBuilderForTable('tx_mksamlauth_domain_model_group_mapping'); |
27
|
|
|
|
28
|
|
|
$qb->select('e.group_ids'); |
29
|
|
|
$qb->from('tx_mksamlauth_domain_model_group_mapping', 'e'); |
30
|
|
|
$qb->where($qb->expr()->andX( |
31
|
|
|
$qb->expr()->eq('e.idp_id', ':id'), |
32
|
|
|
$qb->expr()->in('e.idp_name', ':names') |
33
|
|
|
)); |
34
|
|
|
$qb->setParameter('id', $context['idp']['uid']); |
35
|
|
|
$qb->setParameter('names', $names, Connection::PARAM_STR_ARRAY); |
36
|
|
|
|
37
|
|
|
$groups = $qb->execute()->fetchAll(); |
38
|
|
|
|
39
|
|
|
// If there are no groups, we don't want to override them. |
40
|
|
|
if (0 === \count($groups)) { |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$groups = array_map('current', $groups); |
45
|
|
|
$groups = implode(',', $groups); |
46
|
|
|
|
47
|
|
|
$user->setProperty('usergroup', $groups); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|