1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Allows user account and profile attributes to be automatically populated
|
6 |
|
|
* using tokens. Provides basic tokens for attributes returned by an LDAP
|
7 |
|
|
* server.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
/**
|
11 |
|
|
* Implements hook_menu().
|
12 |
|
|
*/
|
13 |
|
|
function cas_ldap_menu() {
|
14 |
|
|
$items['admin/config/people/cas/attributes/ldap'] = array(
|
15 |
|
|
'title' => 'LDAP Tokens',
|
16 |
|
|
'description' => 'Get a list of all available LDAP Tokens',
|
17 |
|
|
'page callback' => 'cas_ldap_list',
|
18 |
|
|
'access arguments' => array('administer cas'),
|
19 |
|
|
'file' => 'cas_ldap.admin.inc',
|
20 |
|
|
'type' => MENU_LOCAL_TASK,
|
21 |
|
|
'weight' => -8,
|
22 |
|
|
);
|
23 |
|
|
return $items;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* Administrative settings form.
|
28 |
|
|
*/
|
29 |
|
|
function cas_ldap_form_cas_attributes_admin_settings_alter(&$form, &$form_state, $form_id) {
|
30 |
|
|
|
31 |
|
|
$form['cas_attributes_ldap'] = array(
|
32 |
|
|
'#type' => 'fieldset',
|
33 |
|
|
'#title' => 'LDAP',
|
34 |
|
|
'#weight' => -8,
|
35 |
|
|
);
|
36 |
|
|
$ldap_servers = ldap_servers_get_servers(NULL, 'enabled');
|
37 |
|
|
$options = array();
|
38 |
|
|
if ($ldap_servers) {
|
39 |
|
|
foreach ($ldap_servers as $sid => $ldap_server) {
|
40 |
|
|
$options[$sid] = $ldap_server->name;
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
$form['cas_attributes_ldap']['cas_attributes_ldap_server'] = array(
|
44 |
|
|
'#type' => 'select',
|
45 |
|
|
'#title' => t('Server'),
|
46 |
|
|
'#default_value' => variable_get('cas_attributes_ldap_server', NULL),
|
47 |
|
|
'#options' => $options,
|
48 |
|
|
'#empty_option' => t('- Select a LDAP server -'),
|
49 |
|
|
'#description' => t('The LDAP server to query for LDAP attributes. <a href="@url">Configure servers</a>.', array('@url' => url('admin/config/people/ldap/servers'))),
|
50 |
|
|
);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* Returns an array containing LDAP attributes for the specified user.
|
55 |
|
|
*
|
56 |
|
|
* @param $name
|
57 |
|
|
*/
|
58 |
|
|
function cas_ldap_attributes($name) {
|
59 |
|
|
$attributes = &drupal_static(__FUNCTION__, array());
|
60 |
|
|
|
61 |
|
|
if (!isset($attributes[$name])) {
|
62 |
|
|
$attributes[$name] = _cas_ldap_attributes($name);
|
63 |
|
|
}
|
64 |
|
|
return $attributes[$name];
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
/**
|
68 |
|
|
* Look up the user attributes for the specified user.
|
69 |
|
|
*/
|
70 |
|
|
function _cas_ldap_attributes($name) {
|
71 |
|
|
$cas_attr_ldap_server = variable_get('cas_attributes_ldap_server', NULL);
|
72 |
|
|
|
73 |
|
|
if (empty($cas_attr_ldap_server)) {
|
74 |
|
|
// No CAS server configured.
|
75 |
|
|
return array();
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
$ldap_server = ldap_servers_get_servers($cas_attr_ldap_server, 'enabled', TRUE);
|
79 |
|
|
if (empty($ldap_server)) {
|
80 |
|
|
// We cannot load the server.
|
81 |
|
|
return;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
// Connect to the server and perform the lookup.
|
85 |
|
|
$ldap_server->connect();
|
86 |
|
|
$ldap_server->bind();
|
87 |
|
|
$result = $ldap_server->user_lookup($name);
|
88 |
|
|
return $result['attr'];
|
89 |
|
|
} |