root / drupal7 / sites / all / modules / ldap / ldap_servers / ldap_servers.api.php @ fc2c1c7a
1 | 85ad3d82 | Assos Assos | <?php
|
---|---|---|---|
2 | |||
3 | /**
|
||
4 | * @file
|
||
5 | * Hooks provided by ldap_servers module
|
||
6 | */
|
||
7 | |||
8 | |||
9 | /**
|
||
10 | * Allows other modules to periodically affect an ldap associated user
|
||
11 | * or its corresponding ldap entry.
|
||
12 | *
|
||
13 | * when cron runs a batch of ldap associated drupal accounts
|
||
14 | * will be looked at and marked as tested. over the course
|
||
15 | * of time all ldap related users will be looked at
|
||
16 | *
|
||
17 | * Each module implementing this hook is responsible for
|
||
18 | * altering ldap entries and drupal user objects; simply
|
||
19 | * altering the variables will have no affect on the actual
|
||
20 | * ldap entry or drupal user
|
||
21 | */
|
||
22 | |||
23 | function hook_ldap_servers_user_cron(&$users) { |
||
24 | |||
25 | |||
26 | |||
27 | } |
||
28 | |||
29 | /**
|
||
30 | * helper hook to see if a batch of ldap users
|
||
31 | * needs to be queried
|
||
32 | *
|
||
33 | * if a module implements hook_ldap_servers_user_cron,
|
||
34 | * but currently does not need to process user cron batches,
|
||
35 | * it should return FALSE
|
||
36 | */
|
||
37 | |||
38 | function hook_ldap_servers_user_cron_needed() { |
||
39 | return TRUE; |
||
40 | } |
||
41 | |||
42 | /**
|
||
43 | * Allows other modules to alter ldap entry or perform other necessary
|
||
44 | * LDAP operations before entires are provisioned.
|
||
45 | * This should be invoked before provisioning ldap entries
|
||
46 | *
|
||
47 | * @param array $ldap_entries as array keyed on lowercase dn of entry with
|
||
48 | * value of array in format used in ldap_add or ldap_modify function
|
||
49 | * e.g.
|
||
50 | * $ldap_entries['cn=jkool,ou=guest accounts,dc=ad,dc=myuniversity,dc=edu'] = array(
|
||
51 | * "attribute1" => array("value"),
|
||
52 | * "attribute2" => array("value1", "value2"),
|
||
53 | * );
|
||
54 | *
|
||
55 | * @param LdapServer $ldap_server as ldap server configuration object that is
|
||
56 | * performing provisioning
|
||
57 | *
|
||
58 | * @param array $context with the following key/values:
|
||
59 | * 'action' => add|modify|delete
|
||
60 | *
|
||
61 | * 'corresponding_drupal_data' => if ldap entries have corresponding drupal objects, such
|
||
62 | * as ldap user entries and drupal user objects; ldap groups and drupal roles; etc
|
||
63 | * this will be array keyed on lowercase dn with values of objects
|
||
64 | * e.g.
|
||
65 | * $context['corresponding_drupal_data'] = array(
|
||
66 | * 'cn=jkool,ou=guest accounts,dc=ad,dc=myuniversity,dc=edu' => drupal user object1,
|
||
67 | * 'cn=jfun,ou=guest accounts,dc=ad,dc=myuniversity,dc=edu' => drupal user object2,
|
||
68 | * )
|
||
69 | *
|
||
70 | * 'corresponding_drupal_data_type' => 'user', 'role', etc.
|
||
71 | *
|
||
72 | * );
|
||
73 | */
|
||
74 | |||
75 | function hook_ldap_entry_pre_provision_alter(&$ldap_entries, $ldap_server, $context) { |
||
76 | |||
77 | |||
78 | |||
79 | } |
||
80 | |||
81 | /**
|
||
82 | * Allows modules to react to provisioning of ldap entries.
|
||
83 | *
|
||
84 | * This should be invoked after provisioning ldap entries
|
||
85 | *
|
||
86 | * -- same signature as hook_ldap_entry_pre_provision_alter with ldap entries not passed by reference
|
||
87 | * -- ldap entries are not queried after provisioning, so $ldap_entries are in form
|
||
88 | * hook_ldap_entry_pre_provision; not actual queryied ldap entries
|
||
89 | * -- if actual ldap entries are available after provisioning, they will be in
|
||
90 | * $context['provisioned_ldap_entries][<dn>] => ldap entry array in format of an ldap query
|
||
91 | * returned from ldap_get_entries() with 'count' keys
|
||
92 | */
|
||
93 | |||
94 | function hook_ldap_entry_post_provision(&$ldap_entries, $ldap_server, $context) { |
||
95 | |||
96 | |||
97 | |||
98 | } |
||
99 | |||
100 | |||
101 | |||
102 | /**
|
||
103 | * Perform alterations of ldap attributes before query is made.
|
||
104 | *
|
||
105 | * To avoid excessive attributes in an ldap query, modules should
|
||
106 | * alter attributes needed based on $op parameter
|
||
107 | *
|
||
108 | * @param array $attributes
|
||
109 | * array of attributes to be returned from ldap queries where:
|
||
110 | * - each key is ldap attribute name (e.g. mail, cn)
|
||
111 | * - each value is associative array of form:
|
||
112 | * - 'conversion' => NULL,
|
||
113 | * - 'values' => array(0 => 'john', 1 => 'johnny'))
|
||
114 | *
|
||
115 | * @param array $params context array with some or all of the following key/values
|
||
116 | * 'sid' => drupal account object,
|
||
117 | * 'ldap_context' => ,
|
||
118 | * 'direction' =>
|
||
119 | *
|
||
120 | */
|
||
121 | function hook_ldap_attributes_needed_alter(&$attributes, $params) { |
||
122 | |||
123 | $attributes['dn'] = ldap_servers_set_attribute_map(@$attributes['dn'], 'ldap_dn') ; |
||
124 | if ($params['sid']) { // puid attributes are server specific |
||
125 | $ldap_server = (is_object($params['sid'])) ? $params['sid'] : ldap_servers_get_servers($params['sid'], 'enabled', TRUE); |
||
126 | |||
127 | switch ($op) { |
||
128 | case 'user_insert': |
||
129 | case 'user_update': |
||
130 | if (!isset($attributes[$ldap_server->user_attr])) { |
||
131 | // don't provide attribute if it exists, unless you are adding data_type or value information
|
||
132 | // in that case, don't overwrite the whole array (see $ldap_server->mail_attr example below)
|
||
133 | $attributes[$ldap_server->user_attr] = ldap_servers_set_attribute_map(); |
||
134 | } |
||
135 | if (!isset($attributes[$ldap_server->mail_attr])) { |
||
136 | $attributes[$ldap_server->mail_attr] = ldap_servers_set_attribute_map(); // set default values for an attribute, force data_type |
||
137 | } |
||
138 | |||
139 | ldap_servers_token_extract_attributes($attributes, $ldap_server_obj->mail_template); |
||
140 | $attributes[$ldap_server->unique_persistent_attr] = ldap_servers_set_attribute_map(@$attributes[$ldap_server->unique_persistent_attr]); |
||
141 | |||
142 | break;
|
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | |||
147 | |||
148 | /**
|
||
149 | * Perform alterations of $ldap_user variable.
|
||
150 | *
|
||
151 | *
|
||
152 | * @param array $ldap_user see README.developers.txt for structure
|
||
153 | * @param array $params context array with some or all of the following key/values
|
||
154 | * 'account' => drupal account object,
|
||
155 | * 'ldap_context' => ,
|
||
156 | * 'module' => module calling alter, e.g. 'ldap_user',
|
||
157 | * 'function' => function calling alter, e.g. 'provisionLdapEntry'
|
||
158 | *
|
||
159 | */
|
||
160 | |||
161 | function hook_ldap_user_alter(&$ldap_entry, $params) { |
||
162 | |||
163 | |||
164 | } |
||
165 | |||
166 | /**
|
||
167 | * Allow the results from the ldap search answer to be modified
|
||
168 | * The query parameters are provided as context infomation
|
||
169 | * (readonly)
|
||
170 | *
|
||
171 | */
|
||
172 | function hook_ldap_server_search_results_alter(&$entries, $ldap_query_params) { |
||
173 | // look for a specific part of the $results array
|
||
174 | // and maybe change it
|
||
175 | } |
||
176 | |||
177 | /**
|
||
178 | * Allows other modules to transform the Drupal login username to an LDAP
|
||
179 | * UserName attribute.
|
||
180 | * Invoked in LdapServer::userUsernameToLdapNameTransform()
|
||
181 | *
|
||
182 | * @param $ldap_username
|
||
183 | * The ldap username that will be used for the AuthName attribute
|
||
184 | * @param $drupal_username
|
||
185 | * The Drupal user name
|
||
186 | * @param $context
|
||
187 | * An array of additional contextual information
|
||
188 | * - ldap_server: The LDAP server that is invoking the hook
|
||
189 | */
|
||
190 | function hook_user_ldap_servers_username_to_ldapname_alter(&$ldap_username, $drupal_username, $context) { |
||
191 | // Alter the name only if it has not been altered already, ie php eval code
|
||
192 | if ($ldap_username == $drupal_username) { |
||
193 | $authname = ldap_user_get_authname($ldap_username); |
||
194 | if (!empty($authname)) { |
||
195 | $ldap_username = $authname; |
||
196 | } |
||
197 | } |
||
198 | } |