1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class LDAPGroupMapping |
4
|
|
|
* |
5
|
|
|
* An individual mapping of an LDAP group to a SilverStripe {@link Group} |
6
|
|
|
*/ |
7
|
|
|
class LDAPGroupMapping extends DataObject |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var array |
11
|
|
|
*/ |
12
|
|
|
private static $db = [ |
|
|
|
|
13
|
|
|
'DN' => 'Text', // the DN value of the LDAP object in AD, e.g. CN=Users,DN=playpen,DN=local |
14
|
|
|
'Scope' => 'Enum("Subtree,OneLevel","Subtree")' // the scope of the mapping |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private static $has_one = [ |
|
|
|
|
21
|
|
|
'Group' => 'Group' |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
private static $summary_fields = [ |
|
|
|
|
28
|
|
|
'DN' |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private static $dependencies = [ |
|
|
|
|
35
|
|
|
'ldapService' => '%$LDAPService' |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
public function getCMSFields() |
39
|
|
|
{ |
40
|
|
|
$fields = parent::getCMSFields(); |
41
|
|
|
$fields->removeByName('DN'); |
42
|
|
|
|
43
|
|
|
$field = new DropdownField('DN', _t('LDAPGroupMapping.LDAPGROUP', 'LDAP Group')); |
44
|
|
|
$field->setEmptyString(_t('LDAPGroupMapping.SELECTONE', 'Select one')); |
45
|
|
|
$groups = $this->ldapService->getGroups(true, ['dn', 'name']); |
|
|
|
|
46
|
|
|
if ($groups) { |
47
|
|
|
foreach ($groups as $dn => $record) { |
48
|
|
|
$source[$dn] = sprintf('%s (%s)', $record['name'], $dn); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
asort($source); |
52
|
|
|
$field->setSource($source); |
53
|
|
|
$fields->addFieldToTab('Root.Main', $field); |
54
|
|
|
|
55
|
|
|
$fields->removeByName('Scope'); |
56
|
|
|
$fields->addFieldToTab( |
57
|
|
|
'Root.Main', |
58
|
|
|
new DropdownField('Scope', _t('LDAPGroupMapping.SCOPE', 'Scope'), [ |
59
|
|
|
'Subtree' => _t('LDAPGroupMapping.SUBTREE_DESCRIPTION', 'Users within this group and all nested groups within'), |
60
|
|
|
'OneLevel' => _t('LDAPGroupMapping.ONELEVEL_DESCRIPTION', 'Only users within this group'), |
61
|
|
|
]) |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
return $fields; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.