1
|
<?php
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
class LdapAuthorizationConsumerConf {
|
17
|
|
18
|
public $sid = NULL;
|
19
|
public $server;
|
20
|
public $consumerType = NULL;
|
21
|
public $consumerModule = NULL;
|
22
|
public $consumer = NULL;
|
23
|
public $inDatabase = FALSE;
|
24
|
public $numericConsumerConfId = NULL;
|
25
|
|
26
|
public $description = NULL;
|
27
|
public $status = NULL;
|
28
|
public $onlyApplyToLdapAuthenticated = TRUE;
|
29
|
|
30
|
public $useFirstAttrAsGroupId = FALSE;
|
31
|
|
32
|
public $mappings = array();
|
33
|
public $useMappingsAsFilter = TRUE;
|
34
|
|
35
|
public $synchToLdap = FALSE;
|
36
|
|
37
|
public $synchOnLogon = TRUE;
|
38
|
|
39
|
public $revokeLdapProvisioned = TRUE;
|
40
|
public $regrantLdapProvisioned = TRUE;
|
41
|
public $createConsumers = TRUE;
|
42
|
|
43
|
public $errorMsg = NULL;
|
44
|
public $hasError = FALSE;
|
45
|
public $errorName = NULL;
|
46
|
|
47
|
|
48
|
public function clearError() {
|
49
|
$this->hasError = FALSE;
|
50
|
$this->errorMsg = NULL;
|
51
|
$this->errorName = NULL;
|
52
|
}
|
53
|
|
54
|
|
55
|
|
56
|
function __construct(&$consumer, $_new = FALSE, $_sid = NULL) {
|
57
|
$this->consumer = $consumer;
|
58
|
$this->consumerType = $consumer->consumerType;
|
59
|
if ($_new) {
|
60
|
$this->inDatabase = FALSE;
|
61
|
}
|
62
|
else {
|
63
|
$this->inDatabase = TRUE;
|
64
|
$exists = $this->loadFromDb();
|
65
|
if (!$exists) {
|
66
|
watchdog('ldap_authorization', 'failed to load existing %consumer object', array('%consumer' => $consumer->consumerType), WATCHDOG_ERROR);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
|
71
|
}
|
72
|
|
73
|
protected function loadFromDb() {
|
74
|
if (module_exists('ctools')) {
|
75
|
ctools_include('export');
|
76
|
$result = ctools_export_load_object('ldap_authorization', 'names', array($this->consumerType));
|
77
|
|
78
|
|
79
|
$server_record = array_pop($result);
|
80
|
|
81
|
|
82
|
}
|
83
|
else {
|
84
|
$select = db_select('ldap_authorization', 'ldap_authorization');
|
85
|
$select->fields('ldap_authorization');
|
86
|
$select->condition('ldap_authorization.consumer_type', $this->consumerType);
|
87
|
$server_record = $select->execute()->fetchObject();
|
88
|
}
|
89
|
|
90
|
if (!$server_record) {
|
91
|
$this->inDatabase = FALSE;
|
92
|
return FALSE;
|
93
|
}
|
94
|
|
95
|
foreach ($this->field_to_properties_map() as $db_field_name => $property_name ) {
|
96
|
if (isset($server_record->$db_field_name)) {
|
97
|
if (in_array($db_field_name, $this->field_to_properties_serialized())) {
|
98
|
$this->{$property_name} = unserialize($server_record->$db_field_name);
|
99
|
}
|
100
|
else {
|
101
|
$this->{$property_name} = $server_record->$db_field_name;
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
$this->numericConsumerConfId = isset($server_record->numeric_consumer_conf_id)? $server_record->numeric_consumer_conf_id : NULL;
|
106
|
$this->server = ldap_servers_get_servers($this->sid, NULL, TRUE);
|
107
|
return TRUE;
|
108
|
|
109
|
}
|
110
|
|
111
|
|
112
|
public static function field_to_properties_map() {
|
113
|
return array(
|
114
|
'sid' => 'sid',
|
115
|
'consumer_type' => 'consumerType',
|
116
|
'numeric_consumer_conf_id' => 'numericConsumerConfId' ,
|
117
|
'status' => 'status',
|
118
|
'only_ldap_authenticated' => 'onlyApplyToLdapAuthenticated',
|
119
|
'use_first_attr_as_groupid' => 'useFirstAttrAsGroupId',
|
120
|
'mappings' => 'mappings',
|
121
|
'use_filter' => 'useMappingsAsFilter',
|
122
|
'synch_to_ldap' => 'synchToLdap',
|
123
|
'synch_on_logon' => 'synchOnLogon',
|
124
|
'regrant_ldap_provisioned' => 'regrantLdapProvisioned',
|
125
|
'revoke_ldap_provisioned' => 'revokeLdapProvisioned',
|
126
|
'create_consumers' => 'createConsumers',
|
127
|
);
|
128
|
}
|
129
|
|
130
|
public static function field_to_properties_serialized() {
|
131
|
return array('mappings');
|
132
|
}
|
133
|
|
134
|
|
135
|
|
136
|
|
137
|
function __destruct() {
|
138
|
|
139
|
}
|
140
|
|
141
|
protected $_sid;
|
142
|
protected $_new;
|
143
|
|
144
|
protected function linesToArray($lines) {
|
145
|
$lines = trim($lines);
|
146
|
|
147
|
if ($lines) {
|
148
|
$array = preg_split('/[\n\r]+/', $lines);
|
149
|
foreach ($array as $i => $value) {
|
150
|
$array[$i] = trim($value);
|
151
|
}
|
152
|
}
|
153
|
else {
|
154
|
$array = array();
|
155
|
}
|
156
|
return $array;
|
157
|
}
|
158
|
|
159
|
|
160
|
protected function pipeListToArray($mapping_list_txt, $make_item0_lowercase = FALSE) {
|
161
|
$result_array = array();
|
162
|
$mappings = preg_split('/[\n\r]+/', $mapping_list_txt);
|
163
|
foreach ($mappings as $line) {
|
164
|
if (count($mapping = explode('|', trim($line))) == 2) {
|
165
|
$item_0 = ($make_item0_lowercase) ? drupal_strtolower(trim($mapping[0])) : trim($mapping[0]);
|
166
|
$result_array[] = array($item_0, trim($mapping[1]));
|
167
|
}
|
168
|
}
|
169
|
return $result_array;
|
170
|
}
|
171
|
}
|