44namespace Mapbender \LDAPBundle \Security \Provider ;
55
66
7+ use FOM \UserBundle \Component \DummyGroup ;
78use FOM \UserBundle \Component \Ldap \Client ;
89use Mapbender \LDAPBundle \Component \LdapClient ;
9- use Mapbender \LDAPBundle \Security \User \LDAPGroup ;
1010use Symfony \Component \Ldap \Entry ;
1111
1212class 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}
0 commit comments