Skip to content

Commit 8ac9dd6

Browse files
committed
Add configurable ldap.group.role_prefix parameter (for ACL assignments / checks)
1 parent c4ed695 commit 8ac9dd6

File tree

4 files changed

+25
-39
lines changed

4 files changed

+25
-39
lines changed

Resources/config/services.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ parameters:
1515
# parameter names are now case sensitive
1616
ldap.user.baseDN: '%ldap.user.baseDn%'
1717
ldap.group.baseDN: '%ldap.group.baseDn%'
18-
## Defaults
1918
ldap.group.id: cn
19+
ldap.group.role_prefix: ROLE_GROUP_
2020

2121
services:
2222
ldapClient:
@@ -45,6 +45,7 @@ services:
4545
- '%ldap.group.id%'
4646
- '%ldap.group.adminFilter%'
4747
- '%ldap.group.query%'
48+
- '%ldap.group.role_prefix%'
4849
fom.ldap_client:
4950
alias: ldapClient
5051
fom.identities.provider:

Security/Provider/LDAPGroupProvider.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
namespace Mapbender\LDAPBundle\Security\Provider;
55

66

7+
use FOM\UserBundle\Component\DummyGroup;
78
use FOM\UserBundle\Component\Ldap\Client;
89
use Mapbender\LDAPBundle\Component\LdapClient;
9-
use Mapbender\LDAPBundle\Security\User\LDAPGroup;
1010
use Symfony\Component\Ldap\Entry;
1111

1212
class LDAPGroupProvider
@@ -17,18 +17,20 @@ class LDAPGroupProvider
1717
protected $identifierAttribute;
1818
protected $filter;
1919
protected $queryTemplate;
20+
protected $rolePrefix;
2021

21-
public function __construct(LdapClient $client, $baseDn, $identifierAttribute, $filter, $queryTemplate)
22+
public function __construct(LdapClient $client, $baseDn, $identifierAttribute, $filter, $queryTemplate, $rolePrefix)
2223
{
2324
$this->client = $client;
2425
$this->baseDn = $baseDn;
2526
$this->identifierAttribute = $identifierAttribute;
2627
$this->filter = $filter;
2728
$this->queryTemplate = $queryTemplate;
29+
$this->rolePrefix = $rolePrefix;
2830
}
2931

3032
/**
31-
* @return LDAPGroup[]
33+
* @return DummyGroup[]
3234
*/
3335
public function getGroups()
3436
{
@@ -42,12 +44,14 @@ public function getGroups()
4244

4345
/**
4446
* @param array $record
45-
* @return LDAPGroup
47+
* @return DummyGroup
4648
*/
4749
protected function transformGroupRecord(array $record)
4850
{
4951
$identifier = $record[$this->identifierAttribute][0];
50-
return new LDAPGroup($identifier);
52+
$role = $this->rolePrefix . strtoupper($identifier);
53+
$title = $this->mb_ucfirst($identifier) . ' (LDAP)';
54+
return new DummyGroup($role, $title);
5155
}
5256

5357
/**
@@ -66,9 +70,21 @@ public function getRolesByUserEntry(Entry $user, $name)
6670
foreach ($ldapGroups as $group) {
6771
$groupIds = $group->getAttribute($this->identifierAttribute);
6872
if ($groupIds) {
69-
$roleNames[] = 'ROLE_GROUP_' . strtoupper($groupIds[0]);
73+
$roleNames[] = $this->rolePrefix . strtoupper($groupIds[0]);
7074
}
7175
}
7276
return $roleNames;
7377
}
78+
79+
/**
80+
* @param string $value
81+
* @return string
82+
*/
83+
protected static function mb_ucfirst($value)
84+
{
85+
return
86+
\mb_strtoupper(\mb_substr($value, 0, 1))
87+
. \mb_substr($value, 1)
88+
;
89+
}
7490
}

Security/User/LDAPGroup.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"ext-ldap": "*",
1212
"php": ">=5.5",
1313
"symfony/ldap": "^3.4 || ^4 || ^5 || ^6",
14-
"mapbender/fom": "~3.1.7 || ^3.2.7"
14+
"mapbender/fom": "~3.1.12 || ^3.2.12"
1515
},
1616
"autoload": {
1717
"psr-4": {"Mapbender\\LDAPBundle\\": "."}

0 commit comments

Comments
 (0)