Révision 32700c57
Ajouté par Assos Assos il y a environ 5 ans
drupal7/sites/all/modules/ldap/ldap_user/LdapUserConf.class.php | ||
---|---|---|
3 | 3 |
/** |
4 | 4 |
* @file |
5 | 5 |
* This class represents a ldap_user module's configuration |
6 |
* It is extended by LdapUserConfAdmin for configuration and other admin functions |
|
6 |
* It is extended by LdapUserConfAdmin for configuration and other admin functions.
|
|
7 | 7 |
*/ |
8 | 8 |
|
9 |
require_once('ldap_user.module'); |
|
10 |
|
|
9 |
require_once 'ldap_user.module'; |
|
10 |
/** |
|
11 |
* |
|
12 |
*/ |
|
11 | 13 |
class LdapUserConf { |
12 | 14 |
|
13 | 15 |
/** |
14 |
* server providing Drupal account provisioning
|
|
16 |
* Server providing Drupal account provisioning.
|
|
15 | 17 |
* |
16 | 18 |
* @var string |
17 | 19 |
* |
... | ... | |
20 | 22 |
public $drupalAcctProvisionServer = LDAP_USER_NO_SERVER_SID; |
21 | 23 |
|
22 | 24 |
/** |
23 |
* server providing LDAP entry provisioning
|
|
25 |
* Server providing LDAP entry provisioning.
|
|
24 | 26 |
* |
25 | 27 |
* @var string |
26 | 28 |
* |
... | ... | |
33 | 35 |
* |
34 | 36 |
* @var array |
35 | 37 |
*/ |
36 |
public $provisionSidFromDirection = array(
|
|
38 |
public $provisionSidFromDirection = [
|
|
37 | 39 |
LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER => LDAP_USER_NO_SERVER_SID, |
38 | 40 |
LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY => LDAP_USER_NO_SERVER_SID, |
39 |
);
|
|
41 |
];
|
|
40 | 42 |
|
41 | 43 |
/** |
42 | 44 |
* Array of events that trigger provisioning of Drupal Accounts |
43 | 45 |
* Valid constants are: |
44 | 46 |
* LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE |
45 | 47 |
* LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE |
46 |
* LDAP_USER_DRUPAL_USER_PROV_ON_ALLOW_MANUAL_CREATE |
|
48 |
* LDAP_USER_DRUPAL_USER_PROV_ON_ALLOW_MANUAL_CREATE.
|
|
47 | 49 |
* |
48 | 50 |
* @var array |
49 | 51 |
*/ |
50 |
public $drupalAcctProvisionTriggers = array(LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE, LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE, LDAP_USER_DRUPAL_USER_PROV_ON_ALLOW_MANUAL_CREATE);
|
|
52 |
public $drupalAcctProvisionTriggers = [LDAP_USER_DRUPAL_USER_PROV_ON_AUTHENTICATE, LDAP_USER_DRUPAL_USER_PROV_ON_USER_UPDATE_CREATE, LDAP_USER_DRUPAL_USER_PROV_ON_ALLOW_MANUAL_CREATE];
|
|
51 | 53 |
|
52 | 54 |
/** |
53 | 55 |
* Array of events that trigger provisioning of LDAP Entries |
54 | 56 |
* Valid constants are: |
55 | 57 |
* LDAP_USER_LDAP_ENTRY_PROV_ON_USER_UPDATE_CREATE |
56 | 58 |
* LDAP_USER_LDAP_ENTRY_PROV_ON_AUTHENTICATE |
57 |
* LDAP_USER_LDAP_ENTRY_DELETE_ON_USER_DELETE |
|
59 |
* LDAP_USER_LDAP_ENTRY_DELETE_ON_USER_DELETE.
|
|
58 | 60 |
* |
59 | 61 |
* @var array |
60 | 62 |
*/ |
61 |
public $ldapEntryProvisionTriggers = array();
|
|
63 |
public $ldapEntryProvisionTriggers = [];
|
|
62 | 64 |
|
63 | 65 |
/** |
64 |
* server providing LDAP entry provisioning
|
|
66 |
* Server providing LDAP entry provisioning.
|
|
65 | 67 |
* |
66 | 68 |
* @var string |
67 | 69 |
* |
... | ... | |
81 | 83 |
public $accountsWithSameEmail = LDAP_USER_ACCOUNTS_WITH_SAME_EMAIL_DISABLED; |
82 | 84 |
|
83 | 85 |
/** |
84 |
* drupal account creation model
|
|
86 |
* Drupal account creation model.
|
|
85 | 87 |
* |
86 | 88 |
* @var int |
87 | 89 |
* LDAP_USER_ACCT_CREATION_LDAP_BEHAVIOR /admin/config/people/accounts/settings do not affect "LDAP Associated" Drupal accounts. |
... | ... | |
90 | 92 |
public $acctCreation = LDAP_USER_ACCT_CREATION_LDAP_BEHAVIOR_DEFAULT; |
91 | 93 |
|
92 | 94 |
/** |
93 |
* has current object been saved to the database? |
|
94 |
* |
|
95 |
* @var boolean |
|
95 |
* Has current object been saved to the database? |
|
96 | 96 |
* |
97 |
* @var bool |
|
97 | 98 |
*/ |
98 | 99 |
public $inDatabase = FALSE; |
99 | 100 |
|
100 | 101 |
/** |
101 |
* what to do when an ldap provisioned username conflicts with existing drupal user?
|
|
102 |
* What to do when an ldap provisioned username conflicts with existing drupal user?
|
|
102 | 103 |
* |
103 | 104 |
* @var int |
104 | 105 |
* LDAP_USER_CONFLICT_LOG - log the conflict |
105 | 106 |
* LDAP_USER_CONFLICT_RESOLVE - LDAP associate the existing drupal user |
106 |
* |
|
107 | 107 |
*/ |
108 | 108 |
public $manualAccountConflict = LDAP_USER_MANUAL_ACCT_CONFLICT_REJECT; |
109 | 109 |
|
110 |
public $setsLdapPassword = TRUE; // @todo default to FALSE and check for mapping to set to true |
|
110 |
/** |
|
111 |
* @todo default to FALSE and check for mapping to set to true |
|
112 |
*/ |
|
113 |
public $setsLdapPassword = TRUE; |
|
111 | 114 |
|
112 | 115 |
public $loginConflictResolve = FALSE; |
113 | 116 |
|
114 | 117 |
public $disableAdminPasswordField = FALSE; |
115 | 118 |
/** |
116 |
* array of field synch mappings provided by all modules (via hook_ldap_user_attrs_list_alter())
|
|
119 |
* Array of field synch mappings provided by all modules (via hook_ldap_user_attrs_list_alter())
|
|
117 | 120 |
* array of the form: array( |
118 | 121 |
* LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER | LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY => array( |
119 | 122 |
* <server_id> => array( |
... | ... | |
133 | 136 |
* ) |
134 | 137 |
* ) |
135 | 138 |
*/ |
136 |
public $synchMapping = NULL; // array of field synching directions for each operation. should include ldapUserSynchMappings |
|
137 |
// keyed on direction => property, ldap, or field token such as '[field.field_lname] with brackets in them. |
|
138 |
|
|
139 | 139 |
/** |
140 |
* synch mappings configured in ldap user module (not in other modules) |
|
141 |
* array of the form: array( |
|
142 |
LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER | LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY => array( |
|
143 |
'sid' => <server_id> (redundant) |
|
144 |
'ldap_attr' => e.g. [sn] |
|
145 |
'user_attr' => e.g. [field.field_user_lname] (when this value is set to 'user_tokens', 'user_tokens' value is used.) |
|
146 |
'user_tokens' => e.g. [field.field_user_lname], [field.field_user_fname] |
|
147 |
'convert' => 1|0 boolean indicating need to covert from binary |
|
148 |
'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER | LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY (redundant) |
|
149 |
'config_module' => 'ldap_user' |
|
150 |
'prov_module' => 'ldap_user' |
|
151 |
'enabled' => 1|0 boolean |
|
152 |
prov_events' => array( of LDAP_USER_EVENT_* constants indicating during which synch actions field should be synched) |
|
153 |
- four permutations available |
|
154 |
to ldap: LDAP_USER_EVENT_CREATE_LDAP_ENTRY, LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY, |
|
155 |
to drupal: LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER |
|
156 |
) |
|
157 |
) |
|
158 |
) |
|
159 |
*/ |
|
160 |
public $ldapUserSynchMappings = NULL; // |
|
161 |
// keyed on property, ldap, or field token such as '[field.field_lname] with brackets in them. |
|
140 |
* Array of field synching directions for each operation. should include ldapUserSynchMappings. |
|
141 |
*/ |
|
142 |
public $synchMapping = NULL; |
|
143 |
// Keyed on direction => property, ldap, or field token such as '[field.field_lname] with brackets in them. |
|
144 |
/** |
|
145 |
* Synch mappings configured in ldap user module (not in other modules) |
|
146 |
* array of the form: array( |
|
147 |
* LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER | LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY => array( |
|
148 |
* 'sid' => <server_id> (redundant) |
|
149 |
* 'ldap_attr' => e.g. [sn] |
|
150 |
* 'user_attr' => e.g. [field.field_user_lname] (when this value is set to 'user_tokens', 'user_tokens' value is used.) |
|
151 |
* 'user_tokens' => e.g. [field.field_user_lname], [field.field_user_fname] |
|
152 |
* 'convert' => 1|0 boolean indicating need to covert from binary |
|
153 |
* 'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER | LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY (redundant) |
|
154 |
* 'config_module' => 'ldap_user' |
|
155 |
* 'prov_module' => 'ldap_user' |
|
156 |
* 'enabled' => 1|0 boolean |
|
157 |
* prov_events' => array( of LDAP_USER_EVENT_* constants indicating during which synch actions field should be synched) |
|
158 |
* - four permutations available |
|
159 |
* to ldap: LDAP_USER_EVENT_CREATE_LDAP_ENTRY, LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY, |
|
160 |
* to drupal: LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER |
|
161 |
* ) |
|
162 |
* ) |
|
163 |
* ) |
|
164 |
*/ |
|
165 |
public $ldapUserSynchMappings = NULL; |
|
166 |
/** |
|
167 |
* Keyed on property, ldap, or field token such as '[field.field_lname] with brackets in them. |
|
168 |
*/ |
|
162 | 169 |
public $detailedWatchdog = FALSE; |
163 | 170 |
public $provisionsDrupalAccountsFromLdap = FALSE; |
164 | 171 |
public $provisionsLdapEntriesFromDrupalUsers = FALSE; |
165 | 172 |
|
166 |
// what should be done with ldap provisioned accounts that no longer have associated drupal accounts. |
|
173 |
/** |
|
174 |
* What should be done with ldap provisioned accounts that no longer have associated drupal accounts. |
|
175 |
*/ |
|
167 | 176 |
public $orphanedDrupalAcctBehavior = 'ldap_user_orphan_email'; |
168 |
/** options are partially derived from user module account cancel options: |
|
169 |
* |
|
170 |
'ldap_user_orphan_do_not_check' => Do not check for orphaned Drupal accounts.) |
|
171 |
'ldap_user_orphan_email' => Perform no action, but email list of orphaned accounts. (All the other options will send email summaries also.) |
|
172 |
'user_cancel_block' => Disable the account and keep its content. |
|
173 |
'user_cancel_block_unpublish' => Disable the account and unpublish its content. |
|
174 |
'user_cancel_reassign' => Delete the account and make its content belong to the Anonymous user. |
|
175 |
'user_cancel_delete' => Delete the account and its content. |
|
176 |
*/ |
|
177 |
/** |
|
178 |
* Options are partially derived from user module account cancel options:. |
|
179 |
* |
|
180 |
* 'ldap_user_orphan_do_not_check' => Do not check for orphaned Drupal accounts.) |
|
181 |
* 'ldap_user_orphan_email' => Perform no action, but email list of orphaned accounts. (All the other options will send email summaries also.) |
|
182 |
* 'user_cancel_block' => Disable the account and keep its content. |
|
183 |
* 'user_cancel_block_unpublish' => Disable the account and unpublish its content. |
|
184 |
* 'user_cancel_reassign' => Delete the account and make its content belong to the Anonymous user. |
|
185 |
* 'user_cancel_delete' => Delete the account and its content. |
|
186 |
*/ |
|
177 | 187 |
|
178 | 188 |
public $orphanedCheckQty = 100; |
179 | 189 |
|
180 |
// public $wsKey = NULL; |
|
181 |
// public $wsEnabled = 0; |
|
182 |
// public $wsUserIps = array(); |
|
183 |
|
|
184 |
public $provisionsLdapEvents = array(); |
|
185 |
public $provisionsDrupalEvents = array(); |
|
190 |
public $provisionsLdapEvents = []; |
|
191 |
public $provisionsDrupalEvents = []; |
|
186 | 192 |
|
187 |
public $saveable = array(
|
|
193 |
public $saveable = [
|
|
188 | 194 |
'drupalAcctProvisionServer', |
189 | 195 |
'ldapEntryProvisionServer', |
190 | 196 |
'drupalAcctProvisionTriggers', |
... | ... | |
197 | 203 |
'acctCreation', |
198 | 204 |
'ldapUserSynchMappings', |
199 | 205 |
'disableAdminPasswordField', |
200 |
); |
|
201 |
// 'wsKey','wsEnabled','wsUserIps', |
|
202 |
function __construct() { |
|
206 |
]; |
|
207 |
|
|
208 |
/** |
|
209 |
* |
|
210 |
*/ |
|
211 |
public function __construct() { |
|
203 | 212 |
$this->load(); |
204 | 213 |
|
205 | 214 |
$this->provisionSidFromDirection[LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER] = $this->drupalAcctProvisionServer; |
206 | 215 |
$this->provisionSidFromDirection[LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY] = $this->ldapEntryProvisionServer; |
207 | 216 |
|
208 |
$this->provisionsLdapEvents = array(
|
|
217 |
$this->provisionsLdapEvents = [
|
|
209 | 218 |
LDAP_USER_EVENT_CREATE_LDAP_ENTRY => t('On LDAP Entry Creation'), |
210 | 219 |
LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY => t('On Synch to LDAP Entry'), |
211 |
);
|
|
220 |
];
|
|
212 | 221 |
|
213 |
$this->provisionsDrupalEvents = array(
|
|
222 |
$this->provisionsDrupalEvents = [
|
|
214 | 223 |
LDAP_USER_EVENT_CREATE_DRUPAL_USER => t('On Drupal User Creation'), |
215 | 224 |
LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER => t('On Synch to Drupal User'), |
216 |
);
|
|
225 |
];
|
|
217 | 226 |
|
218 | 227 |
$this->provisionsDrupalAccountsFromLdap = ( |
219 | 228 |
$this->drupalAcctProvisionServer && |
... | ... | |
231 | 240 |
$this->detailedWatchdog = variable_get('ldap_help_watchdog_detail', 0); |
232 | 241 |
} |
233 | 242 |
|
234 |
function load() { |
|
243 |
/** |
|
244 |
* |
|
245 |
*/ |
|
246 |
public function load() { |
|
235 | 247 |
|
236 | 248 |
if ($saved = variable_get("ldap_user_conf", FALSE)) { |
237 | 249 |
$this->inDatabase = TRUE; |
... | ... | |
245 | 257 |
$this->inDatabase = FALSE; |
246 | 258 |
// By default this variable should be 0 if the "sharedemail" module |
247 | 259 |
// is not enabled, or 1 if the module is. |
248 |
$this->accountsWithSameEmail = (int)module_exists('sharedemail'); |
|
260 |
$this->accountsWithSameEmail = (int) module_exists('sharedemail');
|
|
249 | 261 |
} |
250 |
// determine account creation configuration
|
|
262 |
// Determine account creation configuration.
|
|
251 | 263 |
$user_register = variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL); |
252 | 264 |
if ($this->acctCreation == LDAP_USER_ACCT_CREATION_LDAP_BEHAVIOR_DEFAULT || $user_register == USER_REGISTER_VISITORS) { |
253 | 265 |
$this->createLDAPAccounts = TRUE; |
... | ... | |
264 | 276 |
} |
265 | 277 |
|
266 | 278 |
/** |
267 |
* Destructor Method |
|
279 |
* Destructor Method.
|
|
268 | 280 |
*/ |
269 |
function __destruct() { } |
|
270 |
|
|
281 |
public function __destruct() {} |
|
271 | 282 |
|
272 | 283 |
/** |
273 |
* Util to fetch mappings for a given direction |
|
284 |
* Util to fetch mappings for a given direction.
|
|
274 | 285 |
* |
275 | 286 |
* @param string $sid |
276 |
* The server id |
|
277 |
* @param string $direction LDAP_USER_PROV_DIRECTION_* constant |
|
287 |
* The server id. |
|
288 |
* @param string $direction |
|
289 |
* LDAP_USER_PROV_DIRECTION_* constant. |
|
278 | 290 |
* @param array $prov_events |
279 | 291 |
* |
280 |
* @return array/bool
|
|
292 |
* @return arraybool |
|
281 | 293 |
* Array of mappings (may be empty array) |
282 |
*/ |
|
294 |
*/
|
|
283 | 295 |
public function getSynchMappings($direction = LDAP_USER_PROV_DIRECTION_ALL, $prov_events = NULL) { |
284 | 296 |
if (!$prov_events) { |
285 | 297 |
$prov_events = ldap_user_all_events(); |
286 | 298 |
} |
287 | 299 |
|
288 |
$mappings = array();
|
|
300 |
$mappings = [];
|
|
289 | 301 |
if ($direction == LDAP_USER_PROV_DIRECTION_ALL) { |
290 |
$directions = array(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY);
|
|
302 |
$directions = [LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY];
|
|
291 | 303 |
} |
292 | 304 |
else { |
293 |
$directions = array($direction);
|
|
305 |
$directions = [$direction];
|
|
294 | 306 |
} |
295 | 307 |
foreach ($directions as $direction) { |
296 | 308 |
if (!empty($this->ldapUserSynchMappings[$direction])) { |
... | ... | |
307 | 319 |
return $mappings; |
308 | 320 |
} |
309 | 321 |
|
322 |
/** |
|
323 |
* |
|
324 |
*/ |
|
310 | 325 |
public function isDrupalAcctProvisionServer($sid) { |
311 | 326 |
if (!$sid || !$this->drupalAcctProvisionServer) { |
312 | 327 |
return FALSE; |
... | ... | |
319 | 334 |
} |
320 | 335 |
} |
321 | 336 |
|
337 |
/** |
|
338 |
* |
|
339 |
*/ |
|
322 | 340 |
public function isLdapEntryProvisionServer($sid) { |
323 | 341 |
if (!$sid || !$this->ldapEntryProvisionServer) { |
324 | 342 |
return FALSE; |
... | ... | |
334 | 352 |
/** |
335 | 353 |
* Util to fetch attributes required for this user conf, not other modules. |
336 | 354 |
* |
337 |
* @param enum $direction LDAP_USER_PROV_DIRECTION_* constants |
|
355 |
* @param enum $direction |
|
356 |
* LDAP_USER_PROV_DIRECTION_* constants. |
|
338 | 357 |
* @param string $ldap_context |
339 |
* |
|
340 |
*/ |
|
358 |
*/ |
|
341 | 359 |
public function getLdapUserRequiredAttributes($direction = LDAP_USER_PROV_DIRECTION_ALL, $ldap_context = NULL) { |
342 | 360 |
|
343 |
$attributes_map = array();
|
|
344 |
$required_attributes = array();
|
|
361 |
$attributes_map = [];
|
|
362 |
$required_attributes = [];
|
|
345 | 363 |
if ($this->drupalAcctProvisionServer) { |
346 | 364 |
$prov_events = $this->ldapContextToProvEvents($ldap_context); |
347 | 365 |
$attributes_map = $this->getSynchMappings($direction, $prov_events); |
348 |
$required_attributes = array();
|
|
366 |
$required_attributes = [];
|
|
349 | 367 |
foreach ($attributes_map as $detail) { |
350 | 368 |
if (count(array_intersect($prov_events, $detail['prov_events']))) { |
351 | 369 |
// Add the attribute to our array. |
... | ... | |
358 | 376 |
return $required_attributes; |
359 | 377 |
} |
360 | 378 |
|
361 |
/** |
|
362 |
* converts the more general ldap_context string to its associated ldap user event |
|
363 |
*/ |
|
364 |
|
|
379 |
/** |
|
380 |
* Converts the more general ldap_context string to its associated ldap user event. |
|
381 |
*/ |
|
365 | 382 |
public function ldapContextToProvEvents($ldap_context = NULL) { |
366 | 383 |
|
367 | 384 |
switch ($ldap_context) { |
368 | 385 |
|
369 | 386 |
case 'ldap_user_prov_to_drupal': |
370 |
$result = array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_LDAP_ASSOCIATE_DRUPAL_ACCT);
|
|
387 |
$result = [LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_LDAP_ASSOCIATE_DRUPAL_ACCT];
|
|
371 | 388 |
break; |
372 | 389 |
|
373 | 390 |
case 'ldap_user_prov_to_ldap': |
374 |
$result = array(LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY, LDAP_USER_EVENT_CREATE_LDAP_ENTRY);
|
|
391 |
$result = [LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY, LDAP_USER_EVENT_CREATE_LDAP_ENTRY];
|
|
375 | 392 |
break; |
376 | 393 |
|
377 | 394 |
default: |
... | ... | |
383 | 400 |
|
384 | 401 |
} |
385 | 402 |
|
386 |
|
|
387 |
/** |
|
388 |
* converts the more general ldap_context string to its associated ldap user prov direction |
|
389 |
*/ |
|
390 |
|
|
403 |
/** |
|
404 |
* Converts the more general ldap_context string to its associated ldap user prov direction. |
|
405 |
*/ |
|
391 | 406 |
public function ldapContextToProvDirection($ldap_context = NULL) { |
392 | 407 |
|
393 | 408 |
switch ($ldap_context) { |
... | ... | |
401 | 416 |
$result = LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY; |
402 | 417 |
break; |
403 | 418 |
|
404 |
// provisioning is can hapen in both directions in most contexts
|
|
419 |
// Provisioning is can hapen in both directions in most contexts.
|
|
405 | 420 |
case 'ldap_user_insert_drupal_user': |
406 | 421 |
case 'ldap_user_update_drupal_user': |
407 | 422 |
case 'ldap_authentication_authenticate': |
... | ... | |
419 | 434 |
} |
420 | 435 |
|
421 | 436 |
/** |
422 |
derive mapping array from ldap user configuration and other configurations. |
|
423 |
if this becomes a resource hungry function should be moved to ldap_user functions |
|
424 |
and stored with static variable. should be cached also. |
|
425 |
|
|
426 |
this should be cached and modules implementing ldap_user_synch_mapping_alter |
|
427 |
should know when to invalidate cache. |
|
437 |
* Derive mapping array from ldap user configuration and other configurations. |
|
438 |
* if this becomes a resource hungry function should be moved to ldap_user functions |
|
439 |
* and stored with static variable. should be cached also. |
|
440 |
* |
|
441 |
* This should be cached and modules implementing ldap_user_synch_mapping_alter |
|
442 |
* should know when to invalidate cache. |
|
443 |
*/ |
|
428 | 444 |
|
445 |
/** |
|
446 |
* @todo change default to false after development |
|
429 | 447 |
*/ |
448 |
public function setSynchMapping($reset = TRUE) { |
|
430 | 449 |
|
431 |
function setSynchMapping($reset = TRUE) { // @todo change default to false after development |
|
432 | 450 |
$synch_mapping_cache = cache_get('ldap_user_synch_mapping'); |
433 | 451 |
if (!$reset && $synch_mapping_cache) { |
434 | 452 |
$this->synchMapping = $synch_mapping_cache->data; |
435 | 453 |
} |
436 | 454 |
else { |
437 |
$available_user_attrs = array();
|
|
438 |
foreach (array(LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) as $direction) {
|
|
455 |
$available_user_attrs = [];
|
|
456 |
foreach ([LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY] as $direction) {
|
|
439 | 457 |
$sid = $this->provisionSidFromDirection[$direction]; |
440 |
$available_user_attrs[$direction] = array();
|
|
458 |
$available_user_attrs[$direction] = [];
|
|
441 | 459 |
$ldap_server = ($sid) ? ldap_servers_get_servers($sid, NULL, TRUE) : FALSE; |
442 | 460 |
|
443 |
$params = array(
|
|
461 |
$params = [
|
|
444 | 462 |
'ldap_server' => $ldap_server, |
445 | 463 |
'ldap_user_conf' => $this, |
446 | 464 |
'direction' => $direction, |
447 |
);
|
|
465 |
];
|
|
448 | 466 |
|
449 | 467 |
drupal_alter('ldap_user_attrs_list', $available_user_attrs[$direction], $params); |
450 | 468 |
} |
... | ... | |
455 | 473 |
} |
456 | 474 |
|
457 | 475 |
/** |
458 |
* given a $prov_event determine if ldap user configuration supports it.
|
|
459 |
* this is overall, not per field synching configuration |
|
476 |
* Given a $prov_event determine if ldap user configuration supports it.
|
|
477 |
* this is overall, not per field synching configuration.
|
|
460 | 478 |
* |
461 |
* @param enum $direction LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY |
|
479 |
* @param enum $direction |
|
480 |
* LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY. |
|
462 | 481 |
* |
463 | 482 |
* @param enum $prov_event |
464 | 483 |
* LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, LDAP_USER_EVENT_CREATE_DRUPAL_USER |
465 | 484 |
* LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY LDAP_USER_EVENT_CREATE_LDAP_ENTRY |
466 | 485 |
* LDAP_USER_EVENT_LDAP_ASSOCIATE_DRUPAL_ACCT |
467 |
* LDAP_USER_EVENT_ALL |
|
486 |
* LDAP_USER_EVENT_ALL. |
|
487 |
* |
|
488 |
* @param enum $action |
|
489 |
* 'synch', 'provision', 'delete_ldap_entry', 'delete_drupal_entry', 'cancel_drupal_entry'. |
|
468 | 490 |
* |
469 |
* @param enum $action 'synch', 'provision', 'delete_ldap_entry', 'delete_drupal_entry', 'cancel_drupal_entry' |
|
470 |
* @return boolean |
|
491 |
* @return bool |
|
471 | 492 |
*/ |
472 |
|
|
473 | 493 |
public function provisionEnabled($direction, $provision_trigger) { |
474 | 494 |
$result = FALSE; |
475 | 495 |
|
... | ... | |
495 | 515 |
return $result; |
496 | 516 |
} |
497 | 517 |
|
498 |
/** |
|
499 |
* given a drupal account, provision an ldap entry if none exists. if one exists do nothing
|
|
518 |
/**
|
|
519 |
* Given a drupal account, provision an ldap entry if none exists. if one exists do nothing.
|
|
500 | 520 |
* |
501 |
* @param object $account drupal account object with minimum of name property |
|
502 |
* @param array $ldap_user as prepopulated ldap entry. usually not provided |
|
521 |
* @param object $account |
|
522 |
* drupal account object with minimum of name property. |
|
523 |
* @param array $ldap_user |
|
524 |
* as prepopulated ldap entry. usually not provided. |
|
503 | 525 |
* |
504 | 526 |
* @return array of form: |
505 |
* array('status' => 'success', 'fail', or 'conflict'),
|
|
527 |
* array('status' => 'success', 'fail', or 'conflict'), |
|
506 | 528 |
* array('ldap_server' => ldap server object), |
507 | 529 |
* array('proposed' => proposed ldap entry), |
508 | 530 |
* array('existing' => existing ldap entry), |
509 | 531 |
* array('description' = > blah blah) |
510 |
* |
|
511 | 532 |
*/ |
512 |
|
|
513 | 533 |
public function provisionLdapEntry($account, $ldap_user = NULL, $test_query = FALSE) { |
514 |
$watchdog_tokens = array();
|
|
515 |
$result = array(
|
|
534 |
$watchdog_tokens = [];
|
|
535 |
$result = [
|
|
516 | 536 |
'status' => NULL, |
517 | 537 |
'ldap_server' => NULL, |
518 | 538 |
'proposed' => NULL, |
519 | 539 |
'existing' => NULL, |
520 | 540 |
'description' => NULL, |
521 |
);
|
|
541 |
];
|
|
522 | 542 |
|
523 | 543 |
if (is_scalar($account)) { |
524 | 544 |
$username = $account; |
... | ... | |
531 | 551 |
if (is_object($account) && property_exists($account, 'uid') && $account->uid == 1) { |
532 | 552 |
$result['status'] = 'fail'; |
533 | 553 |
$result['error_description'] = 'can not provision drupal user 1'; |
534 |
return $result; // do not provision or synch user 1 |
|
554 |
// Do not provision or synch user 1. |
|
555 |
return $result; |
|
535 | 556 |
} |
536 | 557 |
|
537 | 558 |
if ($account == FALSE || $account->uid == 0) { |
... | ... | |
547 | 568 |
} |
548 | 569 |
|
549 | 570 |
$ldap_server = ldap_servers_get_servers($this->ldapEntryProvisionServer, NULL, TRUE); |
550 |
$params = array(
|
|
571 |
$params = [
|
|
551 | 572 |
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY, |
552 |
'prov_events' => array(LDAP_USER_EVENT_CREATE_LDAP_ENTRY),
|
|
573 |
'prov_events' => [LDAP_USER_EVENT_CREATE_LDAP_ENTRY],
|
|
553 | 574 |
'module' => 'ldap_user', |
554 | 575 |
'function' => 'provisionLdapEntry', |
555 | 576 |
'include_count' => FALSE, |
556 |
);
|
|
577 |
];
|
|
557 | 578 |
|
558 | 579 |
list($proposed_ldap_entry, $error) = $this->drupalUserToLdapEntry($account, $ldap_server, $params, $ldap_user); |
559 | 580 |
$proposed_dn = (is_array($proposed_ldap_entry) && isset($proposed_ldap_entry['dn']) && $proposed_ldap_entry['dn']) ? $proposed_ldap_entry['dn'] : NULL; |
... | ... | |
586 | 607 |
$result['ldap_server'] = $ldap_server; |
587 | 608 |
} |
588 | 609 |
else { |
589 |
// stick $proposed_ldap_entry in $ldap_entries array for drupal_alter call
|
|
590 |
$ldap_entries = array($proposed_dn_lcase => $proposed_ldap_entry);
|
|
591 |
$context = array(
|
|
610 |
// Stick $proposed_ldap_entry in $ldap_entries array for drupal_alter call.
|
|
611 |
$ldap_entries = [$proposed_dn_lcase => $proposed_ldap_entry];
|
|
612 |
$context = [
|
|
592 | 613 |
'action' => 'add', |
593 |
'corresponding_drupal_data' => array($proposed_dn_lcase => $account),
|
|
614 |
'corresponding_drupal_data' => [$proposed_dn_lcase => $account],
|
|
594 | 615 |
'corresponding_drupal_data_type' => 'user', |
595 |
);
|
|
616 |
];
|
|
596 | 617 |
drupal_alter('ldap_entry_pre_provision', $ldap_entries, $ldap_server, $context); |
597 |
// remove altered $proposed_ldap_entry from $ldap_entries array
|
|
618 |
// Remove altered $proposed_ldap_entry from $ldap_entries array.
|
|
598 | 619 |
$proposed_ldap_entry = $ldap_entries[$proposed_dn_lcase]; |
599 | 620 |
|
600 | 621 |
$ldap_entry_created = $ldap_server->createLdapEntry($proposed_ldap_entry, $proposed_dn); |
... | ... | |
606 | 627 |
$result['created'] = $ldap_entry_created; |
607 | 628 |
$result['ldap_server'] = $ldap_server; |
608 | 629 |
|
609 |
// need to store <sid>|<dn> in ldap_user_prov_entries field, which may contain more than one
|
|
630 |
// Need to store <sid>|<dn> in ldap_user_prov_entries field, which may contain more than one.
|
|
610 | 631 |
$ldap_user_prov_entry = $ldap_server->sid . '|' . $proposed_ldap_entry['dn']; |
611 | 632 |
if (!isset($user_entity->ldap_user_prov_entries[LANGUAGE_NONE])) { |
612 |
$user_entity->ldap_user_prov_entries = array(LANGUAGE_NONE => array());
|
|
633 |
$user_entity->ldap_user_prov_entries = [LANGUAGE_NONE => []];
|
|
613 | 634 |
} |
614 | 635 |
$ldap_user_prov_entry_exists = FALSE; |
615 | 636 |
foreach ($user_entity->ldap_user_prov_entries[LANGUAGE_NONE] as $i => $field_value_instance) { |
... | ... | |
618 | 639 |
} |
619 | 640 |
} |
620 | 641 |
if (!$ldap_user_prov_entry_exists) { |
621 |
$user_entity->ldap_user_prov_entries[LANGUAGE_NONE][] = array(
|
|
642 |
$user_entity->ldap_user_prov_entries[LANGUAGE_NONE][] = [
|
|
622 | 643 |
'value' => $ldap_user_prov_entry, |
623 |
);
|
|
644 |
];
|
|
624 | 645 |
|
625 | 646 |
// Save the field without calling user_save() |
626 | 647 |
field_attach_presave('user', $user_entity); |
... | ... | |
637 | 658 |
} |
638 | 659 |
} |
639 | 660 |
|
640 |
$tokens = array(
|
|
661 |
$tokens = [
|
|
641 | 662 |
'%dn' => isset($result['proposed']['dn']) ? $result['proposed']['dn'] : NULL, |
642 | 663 |
'%sid' => (isset($result['ldap_server']) && $result['ldap_server']) ? $result['ldap_server']->sid : 0, |
643 | 664 |
'%username' => @$account->name, |
644 | 665 |
'%uid' => @$account->uid, |
645 | 666 |
'%description' => @$result['description'], |
646 |
);
|
|
667 |
];
|
|
647 | 668 |
if (!$test_query && isset($result['status'])) { |
648 | 669 |
if ($result['status'] == 'success') { |
649 | 670 |
if ($this->detailedWatchdog) { |
... | ... | |
662 | 683 |
return $result; |
663 | 684 |
} |
664 | 685 |
|
665 |
|
|
666 | 686 |
/** |
667 |
* given a drupal account, synch to related ldap entry
|
|
687 |
* Given a drupal account, synch to related ldap entry.
|
|
668 | 688 |
* |
669 |
* @param drupal user object $account. Drupal user object |
|
670 |
* @param array $user_edit. Edit array for user_save. generally null unless user account is being created or modified in same synching |
|
671 |
* @param array $ldap_user. current ldap data of user. @see README.developers.txt for structure |
|
689 |
* @param drupal user object $account |
|
690 |
* Drupal user object. |
|
691 |
* @param array $user_edit |
|
692 |
* Edit array for user_save. generally null unless user account is being created or modified in same synching. |
|
693 |
* @param array $ldap_user |
|
694 |
* current ldap data of user. @see README.developers.txt for structure. |
|
672 | 695 |
* |
673 | 696 |
* @return TRUE on success or FALSE on fail. |
674 | 697 |
*/ |
675 |
|
|
676 |
public function synchToLdapEntry($account, $user_edit = NULL, $ldap_user = array(), $test_query = FALSE) { |
|
698 |
public function synchToLdapEntry($account, $user_edit = NULL, $ldap_user = [], $test_query = FALSE) { |
|
677 | 699 |
|
678 | 700 |
if (is_object($account) && property_exists($account, 'uid') && $account->uid == 1) { |
679 |
return FALSE; // do not provision or synch user 1 |
|
701 |
// Do not provision or synch user 1. |
|
702 |
return FALSE; |
|
680 | 703 |
} |
681 | 704 |
|
682 |
$watchdog_tokens = array();
|
|
705 |
$watchdog_tokens = [];
|
|
683 | 706 |
$result = FALSE; |
684 | 707 |
$proposed_ldap_entry = FALSE; |
685 | 708 |
|
686 | 709 |
if ($this->ldapEntryProvisionServer) { |
687 | 710 |
$ldap_server = ldap_servers_get_servers($this->ldapEntryProvisionServer, NULL, TRUE); |
688 | 711 |
|
689 |
$params = array(
|
|
712 |
$params = [
|
|
690 | 713 |
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY, |
691 |
'prov_events' => array(LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY),
|
|
714 |
'prov_events' => [LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY],
|
|
692 | 715 |
'module' => 'ldap_user', |
693 | 716 |
'function' => 'synchToLdapEntry', |
694 | 717 |
'include_count' => FALSE, |
695 |
);
|
|
718 |
];
|
|
696 | 719 |
|
697 | 720 |
list($proposed_ldap_entry, $error) = $this->drupalUserToLdapEntry($account, $ldap_server, $params, $ldap_user); |
698 | 721 |
if ($error != LDAP_USER_PROV_RESULT_NO_ERROR) { |
... | ... | |
700 | 723 |
} |
701 | 724 |
elseif (is_array($proposed_ldap_entry) && isset($proposed_ldap_entry['dn'])) { |
702 | 725 |
$existing_ldap_entry = $ldap_server->dnExists($proposed_ldap_entry['dn'], 'ldap_entry'); |
703 |
$attributes = array(); // this array represents attributes to be modified; not comprehensive list of attributes |
|
726 |
// This array represents attributes to be modified; not comprehensive list of attributes. |
|
727 |
$attributes = []; |
|
704 | 728 |
foreach ($proposed_ldap_entry as $attr_name => $attr_values) { |
705 | 729 |
if ($attr_name != 'dn') { |
706 | 730 |
if (isset($attr_values['count'])) { |
... | ... | |
717 | 741 |
|
718 | 742 |
if ($test_query) { |
719 | 743 |
$proposed_ldap_entry = $attributes; |
720 |
$result = array(
|
|
744 |
$result = [
|
|
721 | 745 |
'proposed' => $proposed_ldap_entry, |
722 | 746 |
'server' => $ldap_server, |
723 |
);
|
|
747 |
];
|
|
724 | 748 |
} |
725 | 749 |
else { |
726 |
// stick $proposed_ldap_entry in $ldap_entries array for drupal_alter call
|
|
750 |
// Stick $proposed_ldap_entry in $ldap_entries array for drupal_alter call.
|
|
727 | 751 |
$proposed_dn_lcase = drupal_strtolower($proposed_ldap_entry['dn']); |
728 |
$ldap_entries = array($proposed_dn_lcase => $attributes);
|
|
729 |
$context = array(
|
|
752 |
$ldap_entries = [$proposed_dn_lcase => $attributes];
|
|
753 |
$context = [
|
|
730 | 754 |
'action' => 'update', |
731 |
'corresponding_drupal_data' => array($proposed_dn_lcase => $attributes),
|
|
755 |
'corresponding_drupal_data' => [$proposed_dn_lcase => $attributes],
|
|
732 | 756 |
'corresponding_drupal_data_type' => 'user', |
733 |
);
|
|
757 |
];
|
|
734 | 758 |
drupal_alter('ldap_entry_pre_provision', $ldap_entries, $ldap_server, $context); |
735 |
// remove altered $proposed_ldap_entry from $ldap_entries array
|
|
759 |
// Remove altered $proposed_ldap_entry from $ldap_entries array.
|
|
736 | 760 |
$attributes = $ldap_entries[$proposed_dn_lcase]; |
737 | 761 |
$result = $ldap_server->modifyLdapEntry($proposed_ldap_entry['dn'], $attributes); |
738 |
if ($result) { // success |
|
762 |
// Success. |
|
763 |
if ($result) { |
|
739 | 764 |
module_invoke_all('ldap_entry_post_provision', $ldap_entries, $ldap_server, $context); |
740 | 765 |
} |
741 | 766 |
} |
742 | 767 |
} |
743 |
else { // failed to get acceptable proposed ldap entry |
|
768 |
// Failed to get acceptable proposed ldap entry. |
|
769 |
else { |
|
744 | 770 |
$result = FALSE; |
745 | 771 |
} |
746 | 772 |
} |
747 | 773 |
|
748 |
$tokens = array(
|
|
774 |
$tokens = [
|
|
749 | 775 |
'%dn' => isset($proposed_ldap_entry['dn']) ? $proposed_ldap_entry['dn'] : NULL, |
750 | 776 |
'%sid' => $this->ldapEntryProvisionServer, |
751 | 777 |
'%username' => $account->name, |
752 | 778 |
'%uid' => ($test_query || !property_exists($account, 'uid')) ? '' : $account->uid, |
753 |
);
|
|
779 |
];
|
|
754 | 780 |
|
755 | 781 |
if ($result) { |
756 | 782 |
watchdog('ldap_user', 'LDAP entry on server %sid synched dn=%dn. username=%username, uid=%uid', $tokens, WATCHDOG_INFO); |
... | ... | |
764 | 790 |
} |
765 | 791 |
|
766 | 792 |
/** |
767 |
* given a drupal account, query ldap and get all user fields and create user account
|
|
793 |
* Given a drupal account, query ldap and get all user fields and create user account.
|
|
768 | 794 |
* |
769 |
* @param array $account drupal account array with minimum of name |
|
770 |
* @param array $user_edit drupal edit array in form user_save($account, $user_edit) would take, |
|
771 |
* generally empty unless overriding synchToDrupalAccount derived values |
|
772 |
* @param array $ldap_user as user's ldap entry. passed to avoid requerying ldap in cases where already present |
|
773 |
* @param boolean $save indicating if drupal user should be saved. generally depends on where function is called from. |
|
795 |
* @param array $account |
|
796 |
* drupal account array with minimum of name. |
|
797 |
* @param array $user_edit |
|
798 |
* drupal edit array in form user_save($account, $user_edit) would take, |
|
799 |
* generally empty unless overriding synchToDrupalAccount derived values. |
|
800 |
* @param array $ldap_user |
|
801 |
* as user's ldap entry. passed to avoid requerying ldap in cases where already present. |
|
802 |
* @param bool $save |
|
803 |
* indicating if drupal user should be saved. generally depends on where function is called from. |
|
774 | 804 |
* |
775 |
* @return result of user_save() function is $save is true, otherwise return TRUE |
|
805 |
* @return bool|object |
|
806 |
* Result of user_save() function is $save is true, otherwise return TRUE |
|
776 | 807 |
* $user_edit data returned by reference |
777 |
* |
|
778 | 808 |
*/ |
779 | 809 |
public function synchToDrupalAccount($drupal_user, &$user_edit, $prov_event = LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, $ldap_user = NULL, $save = FALSE) { |
780 | 810 |
|
781 |
$debug = array(
|
|
811 |
$debug = [
|
|
782 | 812 |
'account' => $drupal_user, |
783 | 813 |
'user_edit' => $user_edit, |
784 | 814 |
'ldap_user' => $ldap_user, |
785 |
);
|
|
815 |
];
|
|
786 | 816 |
|
787 | 817 |
if ( |
788 | 818 |
(!$ldap_user && !isset($drupal_user->name)) || |
789 | 819 |
(!$drupal_user && $save) || |
790 | 820 |
($ldap_user && !isset($ldap_user['sid'])) |
791 | 821 |
) { |
792 |
// should throw watchdog error also
|
|
822 |
// Should throw watchdog error also.
|
|
793 | 823 |
return FALSE; |
794 | 824 |
} |
795 | 825 |
|
... | ... | |
803 | 833 |
|
804 | 834 |
if ($this->drupalAcctProvisionServer) { |
805 | 835 |
$ldap_server = ldap_servers_get_servers($this->drupalAcctProvisionServer, NULL, TRUE); |
806 |
$this->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, array($prov_event));
|
|
836 |
$this->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, [$prov_event]);
|
|
807 | 837 |
} |
808 | 838 |
|
809 | 839 |
if ($save) { |
... | ... | |
816 | 846 |
} |
817 | 847 |
} |
818 | 848 |
|
819 |
|
|
820 | 849 |
/** |
821 |
* given a drupal account, delete user account |
|
850 |
* Given a drupal account, delete user account. |
|
851 |
* |
|
852 |
* @param string $username |
|
853 |
* drupal account name. |
|
822 | 854 |
* |
823 |
* @param string $username drupal account name |
|
824 | 855 |
* @return TRUE or FALSE. FALSE indicates failed or action not enabled in ldap user configuration |
825 | 856 |
*/ |
826 | 857 |
public function deleteDrupalAccount($username) { |
... | ... | |
835 | 866 |
} |
836 | 867 |
|
837 | 868 |
/** |
838 |
* given a drupal account, find the related ldap entry.
|
|
869 |
* Given a drupal account, find the related ldap entry.
|
|
839 | 870 |
* |
840 | 871 |
* @param drupal user object $account |
841 | 872 |
* |
... | ... | |
845 | 876 |
if (!$prov_events) { |
846 | 877 |
$prov_events = ldap_user_all_events(); |
847 | 878 |
} |
848 |
$sid = $this->ldapEntryProvisionServer; //
|
|
879 |
$sid = $this->ldapEntryProvisionServer; |
|
849 | 880 |
if (!$sid) { |
850 | 881 |
return FALSE; |
851 | 882 |
} |
852 |
// $user_entity->ldap_user_prov_entries, |
|
883 |
// $user_entity->ldap_user_prov_entries,.
|
|
853 | 884 |
$ldap_server = ldap_servers_get_servers($sid, NULL, TRUE); |
854 |
$params = array(
|
|
885 |
$params = [
|
|
855 | 886 |
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY, |
856 | 887 |
'prov_events' => $prov_events, |
857 | 888 |
'module' => 'ldap_user', |
858 | 889 |
'function' => 'getProvisionRelatedLdapEntry', |
859 | 890 |
'include_count' => FALSE, |
860 |
);
|
|
891 |
];
|
|
861 | 892 |
list($proposed_ldap_entry, $error) = $this->drupalUserToLdapEntry($account, $ldap_server, $params); |
862 | 893 |
if (!(is_array($proposed_ldap_entry) && isset($proposed_ldap_entry['dn']) && $proposed_ldap_entry['dn'])) { |
863 | 894 |
return FALSE; |
864 | 895 |
} |
865 |
$ldap_entry = $ldap_server->dnExists($proposed_ldap_entry['dn'], 'ldap_entry', array());
|
|
896 |
$ldap_entry = $ldap_server->dnExists($proposed_ldap_entry['dn'], 'ldap_entry', []);
|
|
866 | 897 |
return $ldap_entry; |
867 | 898 |
|
868 | 899 |
} |
869 | 900 |
|
870 | 901 |
/** |
871 |
* given a drupal account, delete ldap entry that was provisioned based on it
|
|
902 |
* Given a drupal account, delete ldap entry that was provisioned based on it
|
|
872 | 903 |
* normally this will be 0 or 1 entry, but the ldap_user_provisioned_ldap_entries |
873 |
* field attached to the user entity track each ldap entry provisioned |
|
904 |
* field attached to the user entity track each ldap entry provisioned. |
|
905 |
* |
|
906 |
* @param object $account |
|
907 |
* drupal account. |
|
874 | 908 |
* |
875 |
* @param object $account drupal account |
|
876 | 909 |
* @return TRUE or FALSE. FALSE indicates failed or action not enabled in ldap user configuration |
877 | 910 |
*/ |
878 | 911 |
public function deleteProvisionedLdapEntries($account) { |
879 |
// determine server that is associated with user |
|
880 |
|
|
912 |
// Determine server that is associated with user. |
|
881 | 913 |
$boolean_result = FALSE; |
882 | 914 |
if (isset($account->ldap_user_prov_entries[LANGUAGE_NONE][0])) { |
883 | 915 |
foreach ($account->ldap_user_prov_entries[LANGUAGE_NONE] as $i => $field_instance) { |
... | ... | |
888 | 920 |
$ldap_server = ldap_servers_get_servers($sid, NULL, TRUE); |
889 | 921 |
if (is_object($ldap_server) && $dn) { |
890 | 922 |
$boolean_result = $ldap_server->delete($dn); |
891 |
$tokens = array('%sid' => $sid, '%dn' => $dn, '%username' => $account->name, '%uid' => $account->uid);
|
|
923 |
$tokens = ['%sid' => $sid, '%dn' => $dn, '%username' => $account->name, '%uid' => $account->uid];
|
|
892 | 924 |
if ($boolean_result) { |
893 | 925 |
watchdog('ldap_user', 'LDAP entry on server %sid deleted dn=%dn. username=%username, uid=%uid', $tokens, WATCHDOG_INFO); |
894 | 926 |
} |
... | ... | |
906 | 938 |
|
907 | 939 |
} |
908 | 940 |
|
909 |
/** |
|
910 |
* populate ldap entry array for provisioning |
|
911 |
* |
|
912 |
* @param array $account drupal account |
|
913 |
* @param object $ldap_server |
|
914 |
* @param array $ldap_user ldap entry of user, returned by reference |
|
915 |
* @param array $params with the following key values: |
|
916 |
* 'ldap_context' => |
|
917 |
'module' => module calling function, e.g. 'ldap_user' |
|
918 |
'function' => function calling function, e.g. 'provisionLdapEntry' |
|
919 |
'include_count' => should 'count' array key be included |
|
920 |
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY || LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER |
|
921 |
* |
|
922 |
* @return array(ldap entry, $result) in ldap extension array format.!THIS IS NOT THE ACTUAL LDAP ENTRY |
|
923 |
*/ |
|
924 |
|
|
925 |
function drupalUserToLdapEntry($account, $ldap_server, $params, $ldap_user_entry = NULL) { |
|
941 |
/** |
|
942 |
* Populate ldap entry array for provisioning. |
|
943 |
* |
|
944 |
* @param array $account |
|
945 |
* drupal account. |
|
946 |
* @param \LdapServer $ldap_server |
|
947 |
* @param array $ldap_user |
|
948 |
* ldap entry of user, returned by reference. |
|
949 |
* @param array $params |
|
950 |
* with the following key values: |
|
951 |
* 'ldap_context' => |
|
952 |
* 'module' => module calling function, e.g. 'ldap_user' |
|
953 |
* 'function' => function calling function, e.g. 'provisionLdapEntry' |
|
954 |
* 'include_count' => should 'count' array key be included |
|
955 |
* 'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY || LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER. |
|
956 |
* |
|
957 |
* @return array(ldap entry, $result) in ldap extension array format.!THIS IS NOT THE ACTUAL LDAP ENTRY |
|
958 |
*/ |
|
959 |
public function drupalUserToLdapEntry($account, $ldap_server, $params, $ldap_user_entry = NULL) { |
|
926 | 960 |
$provision = (isset($params['function']) && $params['function'] == 'provisionLdapEntry'); |
927 | 961 |
$result = LDAP_USER_PROV_RESULT_NO_ERROR; |
928 | 962 |
if (!$ldap_user_entry) { |
929 |
$ldap_user_entry = array();
|
|
963 |
$ldap_user_entry = [];
|
|
930 | 964 |
} |
931 | 965 |
|
932 | 966 |
if (!is_object($account) || !is_object($ldap_server)) { |
933 |
return array(NULL, LDAP_USER_PROV_RESULT_BAD_PARAMS);
|
|
967 |
return [NULL, LDAP_USER_PROV_RESULT_BAD_PARAMS];
|
|
934 | 968 |
} |
935 |
$watchdog_tokens = array(
|
|
969 |
$watchdog_tokens = [
|
|
936 | 970 |
'%drupal_username' => $account->name, |
937 |
);
|
|
971 |
];
|
|
938 | 972 |
$include_count = (isset($params['include_count']) && $params['include_count']); |
939 | 973 |
|
940 | 974 |
$direction = isset($params['direction']) ? $params['direction'] : LDAP_USER_PROV_DIRECTION_ALL; |
... | ... | |
942 | 976 |
|
943 | 977 |
$mappings = $this->getSynchMappings($direction, $prov_events); |
944 | 978 |
foreach ($mappings as $field_key => $field_detail) { |
945 |
list($ldap_attr_name, $ordinal, $conversion) = ldap_servers_token_extract_parts($field_key, TRUE); //trim($field_key, '[]');
|
|
979 |
list($ldap_attr_name, $ordinal, $conversion) = ldap_servers_token_extract_parts($field_key, TRUE); |
|
946 | 980 |
$ordinal = (!$ordinal) ? 0 : $ordinal; |
947 |
if ($ldap_user_entry && isset($ldap_user_entry[$ldap_attr_name]) && is_array($ldap_user_entry[$ldap_attr_name]) && isset($ldap_user_entry[$ldap_attr_name][$ordinal]) ) { |
|
948 |
continue; // don't override values passed in; |
|
981 |
if ($ldap_user_entry && isset($ldap_user_entry[$ldap_attr_name]) && is_array($ldap_user_entry[$ldap_attr_name]) && isset($ldap_user_entry[$ldap_attr_name][$ordinal])) { |
|
982 |
// don't override values passed in. |
|
983 |
continue; |
|
949 | 984 |
} |
950 | 985 |
|
951 | 986 |
$synched = $this->isSynched($field_key, $params['prov_events'], LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY); |
... | ... | |
953 | 988 |
$token = ($field_detail['user_attr'] == 'user_tokens') ? $field_detail['user_tokens'] : $field_detail['user_attr']; |
954 | 989 |
$value = ldap_servers_token_replace($account, $token, 'user_account'); |
955 | 990 |
|
956 |
if (substr($token, 0, 10) == '[password.' && (!$value || $value == $token)) { // deal with empty/unresolved password |
|
991 |
// Deal with empty/unresolved password. |
|
992 |
if (substr($token, 0, 10) == '[password.' && (!$value || $value == $token)) { |
|
957 | 993 |
if (!$provision) { |
958 |
continue; //don't overwrite password on synch if no value provided |
|
994 |
// don't overwrite password on synch if no value provided. |
|
995 |
continue; |
|
959 | 996 |
} |
960 | 997 |
} |
961 | 998 |
|
... | ... | |
964 | 1001 |
} |
965 | 1002 |
elseif ($value) { |
966 | 1003 |
if (!isset($ldap_user_entry[$ldap_attr_name]) || !is_array($ldap_user_entry[$ldap_attr_name])) { |
967 |
$ldap_user_entry[$ldap_attr_name] = array();
|
|
1004 |
$ldap_user_entry[$ldap_attr_name] = [];
|
|
968 | 1005 |
} |
969 | 1006 |
$ldap_user_entry[$ldap_attr_name][$ordinal] = $value; |
970 | 1007 |
if ($include_count) { |
... | ... | |
983 | 1020 |
$params['account'] = $account; |
984 | 1021 |
drupal_alter('ldap_entry', $ldap_user_entry, $params); |
985 | 1022 |
|
986 |
return array($ldap_user_entry, $result);
|
|
1023 |
return [$ldap_user_entry, $result];
|
|
987 | 1024 |
|
988 | 1025 |
} |
989 | 1026 |
|
990 |
|
|
991 |
|
|
992 |
/** |
|
993 |
* given a drupal account, query ldap and get all user fields and save user account |
|
1027 |
/** |
|
1028 |
* Given a drupal account, query ldap and get all user fields and save user account |
|
994 | 1029 |
* (note: parameters are in odd order to match synchDrupalAccount handle) |
995 | 1030 |
* |
996 |
* @param array $account drupal account object or null |
|
997 |
* @param array $user_edit drupal edit array in form user_save($account, $user_edit) would take. |
|
998 |
* @param array $ldap_user as user's ldap entry. passed to avoid requerying ldap in cases where already present |
|
999 |
* @param boolean $save indicating if drupal user should be saved. generally depends on where function is called from and if the |
|
1031 |
* @param array $account |
|
1032 |
* drupal account object or null. |
|
1033 |
* @param array $user_edit |
|
1034 |
* drupal edit array in form user_save($account, $user_edit) would take. |
|
1035 |
* @param array $ldap_user |
|
1036 |
* as user's ldap entry. passed to avoid requerying ldap in cases where already present. |
|
1037 |
* @param bool $save |
|
1038 |
* indicating if drupal user should be saved. generally depends on where function is called from and if the. |
|
1000 | 1039 |
* |
1001 |
* @return result of user_save() function is $save is true, otherwise return TRUE on success or FALSE on any problem |
|
1002 |
* $user_edit data returned by reference |
|
1040 |
* @return bool |
|
1041 |
* Resultof user_save() function is $save is true, otherwise return TRUE on |
|
1042 |
* success or FALSE on any problem |
|
1003 | 1043 |
* |
1044 |
* $user_edit data returned by reference |
|
1004 | 1045 |
*/ |
1005 |
|
|
1006 | 1046 |
public function provisionDrupalAccount($account = FALSE, &$user_edit, $ldap_user = NULL, $save = TRUE) { |
1007 | 1047 |
|
1008 |
$watchdog_tokens = array();
|
|
1048 |
$watchdog_tokens = [];
|
|
1009 | 1049 |
/** |
1010 | 1050 |
* @todo |
1011 | 1051 |
* -- add error catching for conflicts, conflicts should be checked before calling this function. |
... | ... | |
1038 | 1078 |
$user_edit['name'] = $account->name; |
1039 | 1079 |
$watchdog_tokens['%username'] = $user_edit['name']; |
1040 | 1080 |
} |
1041 |
//When using the multi-domain last authentication option |
|
1042 |
//$ldap_server breaks beacause $this->drupalAcctProvisionServer is set on LDAP_USER_AUTH_SERVER_SID |
|
1043 |
//So we need to check it's not the case before using ldap_servers_get_servers
|
|
1081 |
// When using the multi-domain last authentication option
|
|
1082 |
// $ldap_server breaks beacause $this->drupalAcctProvisionServer is set on LDAP_USER_AUTH_SERVER_SID
|
|
1083 |
// So we need to check it's not the case before using ldap_servers_get_servers.
|
|
1044 | 1084 |
if ($this->drupalAcctProvisionServer && $this->drupalAcctProvisionServer != LDAP_USER_AUTH_SERVER_SID) { |
1045 | 1085 |
|
1046 |
$ldap_server = ldap_servers_get_servers($this->drupalAcctProvisionServer, 'enabled', TRUE); // $ldap_user['sid'] |
|
1086 |
/** @var \LdapServer $ldap_server */ |
|
1087 |
// $ldap_user['sid']. |
|
1088 |
$ldap_server = ldap_servers_get_servers($this->drupalAcctProvisionServer, 'enabled', TRUE); |
|
1047 | 1089 |
|
1048 |
$params = array(
|
|
1090 |
$params = [
|
|
1049 | 1091 |
'account' => $account, |
1050 | 1092 |
'user_edit' => $user_edit, |
1051 | 1093 |
'prov_event' => LDAP_USER_EVENT_CREATE_DRUPAL_USER, |
1052 | 1094 |
'module' => 'ldap_user', |
1053 | 1095 |
'function' => 'provisionDrupalAccount', |
1054 | 1096 |
'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, |
1055 |
);
|
|
1097 |
];
|
|
1056 | 1098 |
|
1057 | 1099 |
drupal_alter('ldap_entry', $ldap_user, $params); |
1058 | 1100 |
|
1059 |
// look for existing drupal account with same puid. if so update username and attempt to synch in current context
|
|
1101 |
// Look for existing drupal account with same puid. if so update username and attempt to synch in current context.
|
|
1060 | 1102 |
$puid = $ldap_server->userPuidFromLdapEntry($ldap_user['attr']); |
1061 |
$account2 = ($puid) ? $ldap_server->userUserEntityFromPuid($puid) : FALSE; |
|
1062 |
|
|
1063 |
if ($account2) { // synch drupal account, since drupal account exists |
|
1064 |
// 1. correct username and authmap |
|
1065 |
$this->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER)); |
|
1066 |
$account = user_save($account2, $user_edit, 'ldap_user'); |
|
1067 |
user_set_authmaps($account, array("authname_ldap_user" => $user_edit['name'])); |
|
1068 |
// 2. attempt synch if appropriate for current context |
|
1103 |
$existing_account_from_puid = ($puid) ? $ldap_server->userUserEntityFromPuid($puid) : FALSE; |
|
1104 |
|
|
1105 |
// Synch drupal account, since drupal account exists. |
|
1106 |
if ($existing_account_from_puid) { |
|
1107 |
// 1. correct username and authmap. |
|
1108 |
$this->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, [LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER]); |
|
1109 |
$account = user_save($existing_account_from_puid, $user_edit, 'ldap_user'); |
|
1110 |
user_set_authmaps($account, ["authname_ldap_user" => $user_edit['name']]); |
|
1111 |
// 2. attempt synch if appropriate for current context. |
|
1069 | 1112 |
if ($account) { |
1070 | 1113 |
$account = $this->synchToDrupalAccount($account, $user_edit, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, $ldap_user, TRUE); |
1071 | 1114 |
} |
1072 | 1115 |
return $account; |
1073 | 1116 |
} |
1074 |
else { // create drupal account |
|
1075 |
$this->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, array(LDAP_USER_EVENT_CREATE_DRUPAL_USER)); |
|
1117 |
// Create drupal account. |
|
1118 |
else { |
|
1119 |
$this->entryToUserEdit($ldap_user, $user_edit, $ldap_server, LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, [LDAP_USER_EVENT_CREATE_DRUPAL_USER]); |
|
1076 | 1120 |
if ($save) { |
1077 |
$watchdog_tokens = array('%drupal_username' => $user_edit['name']);
|
|
1121 |
$watchdog_tokens = ['%drupal_username' => $user_edit['name']];
|
|
1078 | 1122 |
if (empty($user_edit['name'])) { |
1079 | 1123 |
drupal_set_message(t('User account creation failed because of invalid, empty derived Drupal username.'), 'error'); |
1080 | 1124 |
watchdog('ldap_user', |
... | ... | |
1093 | 1137 |
); |
1094 | 1138 |
return FALSE; |
1095 | 1139 |
} |
1096 |
if(($this->accountsWithSameEmail == LDAP_USER_ACCOUNTS_WITH_SAME_EMAIL_DISABLED) && ($account_with_same_email = user_load_by_mail($user_edit['mail']))) { |
|
1140 |
if (($this->accountsWithSameEmail == LDAP_USER_ACCOUNTS_WITH_SAME_EMAIL_DISABLED) && ($account_with_same_email = user_load_by_mail($user_edit['mail']))) {
|
|
1097 | 1141 |
$watchdog_tokens['%email'] = $user_edit['mail']; |
1098 | 1142 |
$watchdog_tokens['%duplicate_name'] = $account_with_same_email->name; |
1099 | 1143 |
watchdog('ldap_user', 'LDAP user %drupal_username has email address |
... | ... | |
1106 | 1150 |
drupal_set_message(t('User account creation failed because of system problems.'), 'error'); |
1107 | 1151 |
} |
1108 | 1152 |
else { |
1109 |
user_set_authmaps($account, array('authname_ldap_user' => $account->name));
|
|
1153 |
user_set_authmaps($account, ['authname_ldap_user' => $account->name]);
|
|
1110 | 1154 |
ldap_user_ldap_provision_semaphore('drupal_created', 'set', $account->name); |
1111 | 1155 |
} |
1112 | 1156 |
return $account; |
... | ... | |
1117 | 1161 |
} |
1118 | 1162 |
|
1119 | 1163 |
/** |
1120 |
* set ldap associations of a drupal account by altering user fields
|
|
1164 |
* Set ldap associations of a drupal account by altering user fields.
|
|
1121 | 1165 |
* |
1122 | 1166 |
* @param string $drupal_username |
1123 | 1167 |
* |
1124 |
* @return boolean TRUE on success, FALSE on error or failure because of invalid user or ldap accounts
|
|
1125 |
* |
|
1168 |
* @return bool |
|
1169 |
* TRUE on success, FALSE on error or failure because of invalid user or ldap accounts
|
|
1126 | 1170 |
*/ |
1127 |
function ldapAssociateDrupalAccount($drupal_username) { |
|
1171 |
public function ldapAssociateDrupalAccount($drupal_username) {
|
|
1128 | 1172 |
|
1129 | 1173 |
if ($this->drupalAcctProvisionServer) { |
1130 |
$prov_events = array(LDAP_USER_EVENT_LDAP_ASSOCIATE_DRUPAL_ACCT); |
|
1131 |
$ldap_server = ldap_servers_get_servers($this->drupalAcctProvisionServer, 'enabled', TRUE); // $ldap_user['sid'] |
|
1174 |
$prov_events = [LDAP_USER_EVENT_LDAP_ASSOCIATE_DRUPAL_ACCT]; |
|
1175 |
// $ldap_user['sid']. |
|
1176 |
$ldap_server = ldap_servers_get_servers($this->drupalAcctProvisionServer, 'enabled', TRUE); |
|
1132 | 1177 |
$account = user_load_by_name($drupal_username); |
1133 | 1178 |
$ldap_user = ldap_servers_get_user_ldap_data($drupal_username, $this->drupalAcctProvisionServer, 'ldap_user_prov_to_drupal'); |
1134 | 1179 |
if (!$account) { |
1135 | 1180 |
watchdog( |
1136 | 1181 |
'ldap_user', |
1137 | 1182 |
'Failed to LDAP associate drupal account %drupal_username because account not found', |
1138 |
array('%drupal_username' => $drupal_username),
|
|
1183 |
['%drupal_username' => $drupal_username],
|
|
1139 | 1184 |
WATCHDOG_ERROR |
1140 | 1185 |
); |
1141 | 1186 |
return FALSE; |
... | ... | |
1144 | 1189 |
watchdog( |
1145 | 1190 |
'ldap_user', |
1146 | 1191 |
'Failed to LDAP associate drupal account %drupal_username because corresponding LDAP entry not found', |
1147 |
array('%drupal_username' => $drupal_username),
|
|
1192 |
['%drupal_username' => $drupal_username],
|
|
1148 | 1193 |
WATCHDOG_ERROR |
1149 | 1194 |
); |
1150 | 1195 |
return FALSE; |
1151 | 1196 |
} |
1152 | 1197 |
else { |
1153 |
$user_edit = array();
|
|
1154 |
$user_edit['data']['ldap_user']['init'] = array(
|
|
1198 |
$user_edit = [];
|
|
1199 |
$user_edit['data']['ldap_user']['init'] = [
|
|
1155 | 1200 |
'sid' => $ldap_user['sid'], |
1156 | 1201 |
'dn' => $ldap_user['dn'], |
1157 | 1202 |
'mail' => $account->mail, |
1158 |
);
|
|
1203 |
];
|
|
1159 | 1204 |
$ldap_user_puid = $ldap_server->userPuidFromLdapEntry($ldap_user['attr']); |
1160 | 1205 |
if ($ldap_user_puid) { |
1161 |
$user_edit['ldap_user_puid'][LANGUAGE_NONE][0]['value'] = $ldap_user_puid; //
|
|
1206 |
$user_edit['ldap_user_puid'][LANGUAGE_NONE][0]['value'] = $ldap_user_puid; |
|
1162 | 1207 |
} |
1163 | 1208 |
$user_edit['ldap_user_puid_property'][LANGUAGE_NONE][0]['value'] = $ldap_server->unique_persistent_attr; |
1164 | 1209 |
$user_edit['ldap_user_puid_sid'][LANGUAGE_NONE][0]['value'] = $ldap_server->sid; |
1165 | 1210 |
$user_edit['ldap_user_current_dn'][LANGUAGE_NONE][0]['value'] = $ldap_user['dn']; |
1166 | 1211 |
$account = user_save($account, $user_edit, 'ldap_user'); |
1167 |
return (boolean)$account; |
|
1212 |
return (boolean) $account;
|
|
1168 | 1213 |
} |
1169 | 1214 |
} |
1170 | 1215 |
else { |
... | ... | |
1172 | 1217 |
} |
1173 | 1218 |
} |
1174 | 1219 |
|
1175 |
/** populate $user edit array (used in hook_user_save, hook_user_update, etc) |
|
1176 |
* ... should not assume all attribues are present in ldap entry |
|
1220 |
/** |
|
1221 |
* Populate $user edit array (used in hook_user_save, hook_user_update, etc) |
|
1222 |
* ... should not assume all attribues are present in ldap entry. |
|
1177 | 1223 |
* |
1178 |
* @param array ldap entry $ldap_user |
|
1179 |
* @param array $edit see hook_user_save, hook_user_update, etc |
|
1180 |
* @param object $ldap_server |
|
1181 |
* @param enum $direction |
|
1224 |
* @param $ldap_user |
|
1225 |
* @param array $edit |
|
1226 |
* see hook_user_save, hook_user_update, etc. |
|
1227 |
* @param \LdapServer $ldap_server |
|
1228 |
* @param int $direction |
|
1182 | 1229 |
* @param array $prov_events |
1183 |
* |
|
1184 | 1230 |
*/ |
1231 |
public function entryToUserEdit($ldap_user, &$edit, $ldap_server, $direction = LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, $prov_events = NULL) { |
|
1185 | 1232 |
|
1186 |
function entryToUserEdit($ldap_user, &$edit, $ldap_server, $direction = LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER, $prov_events = NULL) { |
|
1187 |
|
|
1188 |
// need array of user fields and which direction and when they should be synched. |
|
1233 |
// Need array of user fields and which direction and when they should be synched. |
|
1189 | 1234 |
if (!$prov_events) { |
1190 | 1235 |
$prov_events = ldap_user_all_events(); |
1191 | 1236 |
} |
... | ... | |
1207 | 1252 |
$edit['mail'] = isset($edit['mail']) ? $edit['mail'] : $ldap_user['mail']; |
1208 | 1253 |
if (!isset($edit['pass'])) { |
1209 | 1254 |
$edit['pass'] = user_password(20); |
1210 |
watchdog('ldap_user', '20 character random password generated for the %username account that has been created.', array('%username' => $drupal_username), WATCHDOG_INFO);
|
|
1255 |
watchdog('ldap_user', '20 character random password generated for the %username account that has been created.', ['%username' => $drupal_username], WATCHDOG_INFO);
|
|
1211 | 1256 |
} |
1212 | 1257 |
$edit['init'] = isset($edit['init']) ? $edit['init'] : $edit['mail']; |
1213 | 1258 |
$edit['status'] = isset($edit['status']) ? $edit['status'] : 1; |
1214 | 1259 |
$edit['signature'] = isset($edit['signature']) ? $edit['signature'] : ''; |
1215 | 1260 |
|
1216 |
$edit['data']['ldap_user']['init'] = array(
|
|
1261 |
$edit['data']['ldap_user']['init'] = [
|
|
1217 | 1262 |
'sid' => $ldap_user['sid'], |
1218 | 1263 |
'dn' => $ldap_user['dn'], |
1219 | 1264 |
'mail' => $edit['mail'], |
1220 |
);
|
|
1265 |
];
|
|
1221 | 1266 |
} |
1222 | 1267 |
|
1223 | 1268 |
/* |
... | ... | |
1225 | 1270 |
* when syncing the profile. |
1226 | 1271 |
*/ |
1227 | 1272 |
if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER && in_array(LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER, $prov_events)) { |
1228 |
$edit['data']['ldap_user']['init'] = array(
|
|
1273 |
$edit['data']['ldap_user']['init'] = [
|
|
1229 | 1274 |
'sid' => $ldap_user['sid'], |
1230 | 1275 |
'dn' => $ldap_user['dn'], |
1231 | 1276 |
'mail' => isset($edit['mail']) && !empty($edit['mail']) ? $edit['mail'] : $ldap_user['mail'], |
1232 |
);
|
|
1277 |
];
|
|
1233 | 1278 |
} |
1234 | 1279 |
|
1235 | 1280 |
if ($this->isSynched('[property.picture]', $prov_events, $direction)) { |
... | ... | |
1237 | 1282 |
if ($picture) { |
1238 | 1283 |
if (in_array(LDAP_USER_EVENT_CREATE_DRUPAL_USER, $prov_events)) { |
1239 | 1284 |
$edit['picture'] = $picture->fid; |
1240 |
} else { |
|
1285 |
} |
|
1286 |
else { |
|
1241 | 1287 |
$edit['picture'] = $picture; |
1242 | 1288 |
} |
1243 | 1289 |
$edit['data']['ldap_user']['init']['thumb5md'] = $picture->md5Sum; |
... | ... | |
1250 | 1296 |
if ($this->isSynched('[field.ldap_user_puid]', $prov_events, $direction)) { |
1251 | 1297 |
$ldap_user_puid = $ldap_server->userPuidFromLdapEntry($ldap_user['attr']); |
1252 | 1298 |
if ($ldap_user_puid) { |
1253 |
$edit['ldap_user_puid'][LANGUAGE_NONE][0]['value'] = $ldap_user_puid; //
|
|
1299 |
$edit['ldap_user_puid'][LANGUAGE_NONE][0]['value'] = $ldap_user_puid; |
|
1254 | 1300 |
} |
1255 | 1301 |
} |
1256 | 1302 |
if ($this->isSynched('[field.ldap_user_puid_property]', $prov_events, $direction)) { |
... | ... | |
1266 | 1312 |
// Get any additional mappings. |
1267 | 1313 |
$mappings = $this->getSynchMappings($direction, $prov_events); |
1268 | 1314 |
|
1269 |
// Loop over the mappings.
|
|
1315 |
// Loop over the mappings. |
|
1270 | 1316 |
foreach ($mappings as $user_attr_key => $field_detail) { |
1271 | 1317 |
|
1272 |
// Make sure this mapping is relevant to the sync context.
|
|
1318 |
// Make sure this mapping is relevant to the sync context. |
|
1273 | 1319 |
if (!$this->isSynched($user_attr_key, $prov_events, $direction)) { |
1274 | 1320 |
continue; |
1275 | 1321 |
} |
1276 |
/**
|
|
1322 |
/** |
|
1277 | 1323 |
* if "convert from binary is selected" and no particular method is in token, |
1278 | 1324 |
* default to ldap_servers_binary() function |
1279 | 1325 |
*/ |
... | ... | |
1283 | 1329 |
$value = ldap_servers_token_replace($ldap_user['attr'], $field_detail['ldap_attr'], 'ldap_entry'); |
1284 | 1330 |
list($value_type, $value_name, $value_instance) = ldap_servers_parse_user_attr_name($user_attr_key); |
1285 | 1331 |
|
1286 |
// $value_instance not used, may have future use case |
|
1287 |
|
|
1332 |
// $value_instance not used, may have future use case. |
|
1288 | 1333 |
// Are we dealing with a field? |
1289 | 1334 |
if ($value_type == 'field') { |
1290 | 1335 |
// Field api field - first we get the field. |
... | ... | |
1292 | 1337 |
// Then the columns for the field in the schema. |
1293 | 1338 |
$columns = array_keys($field['columns']); |
1294 | 1339 |
// Then we convert the value into an array if it's scalar. |
1295 |
$values = $field['cardinality'] == 1 ? array($value) : (array) $value;
|
|
1340 |
$values = $field['cardinality'] == 1 ? [$value] : (array) $value;
|
|
1296 | 1341 |
|
1297 |
$items = array();
|
|
1342 |
$items = [];
|
|
1298 | 1343 |
// Loop over the values and set them in our $items array. |
1299 | 1344 |
foreach ($values as $delta => $value) { |
1300 | 1345 |
if (isset($value)) { |
... | ... | |
1313 | 1358 |
} |
1314 | 1359 |
|
1315 | 1360 |
// Allow other modules to have a say. |
1316 |
|
|
1317 | 1361 |
drupal_alter('ldap_user_edit_user', $edit, $ldap_user, $ldap_server, $prov_events); |
1318 |
if (isset($edit['name']) && $edit['name'] == '') { // don't let empty 'name' value pass for user |
|
1362 |
// don't let empty 'name' value pass for user. |
|
1363 |
if (isset($edit['name']) && $edit['name'] == '') { |
|
1319 | 1364 |
unset($edit['name']); |
1320 | 1365 |
} |
1321 | 1366 |
|
1322 | 1367 |
} |
1368 |
|
|
1323 | 1369 |
/** |
1324 |
* given configuration of synching, determine is a given synch should occur
|
|
1370 |
* Given configuration of synching, determine is a given synch should occur.
|
|
1325 | 1371 |
* |
1326 |
* @param string $attr_token e.g. [property.mail], [field.ldap_user_puid_property] |
|
1327 |
* @param object $ldap_server |
|
1328 |
* @param array $prov_events e.g. array(LDAP_USER_EVENT_CREATE_DRUPAL_USER). typically array with 1 element |
|
1329 |
* @param scalar $direction LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY |
|
1372 |
* @param string $attr_token |
|
1373 |
* e.g. [property.mail], [field.ldap_user_puid_property]. |
|
1374 |
* @param array $prov_events |
|
1375 |
* e.g. array(LDAP_USER_EVENT_CREATE_DRUPAL_USER). typically array with 1 |
|
1376 |
* element. |
|
1377 |
* @param scalar $direction |
|
1378 |
* LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or |
|
1379 |
* LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY. |
|
1380 |
* |
|
1381 |
* @return bool |
|
1330 | 1382 |
*/ |
1331 |
|
|
1332 | 1383 |
public function isSynched($attr_token, $prov_events, $direction) { |
1333 |
$result = (boolean)( |
|
1384 |
$result = (boolean) (
|
|
1334 | 1385 |
isset($this->synchMapping[$direction][$attr_token]['prov_events']) && |
1335 | 1386 |
count(array_intersect($prov_events, $this->synchMapping[$direction][$attr_token]['prov_events'])) |
1336 | 1387 |
); |
Formats disponibles : Unified diff
Weekly update of contrib modules