18
18
limitations under the License.
19
19
=========================================================================*/
20
20
21
- /** Notification manager for the ldap module */
21
+ /**
22
+ * Notification manager for the ldap module
23
+ *
24
+ * @property Ldap_UserModel $Ldap_User
25
+ */
22
26
class Ldap_Notification extends MIDAS_Notification
23
27
{
24
- public $ _models = array ('User ' );
28
+ public $ _models = array ('Setting ' , ' User ' );
25
29
public $ _moduleModels = array ('User ' );
26
30
public $ moduleName = 'ldap ' ;
27
31
@@ -83,12 +87,12 @@ public function userSettingsChanged($params)
83
87
84
88
$ ldapUser = $ this ->Ldap_User ->getByUser ($ user );
85
89
if ($ ldapUser ) {
86
- if ($ ldapLogin == '' ) {
90
+ if (empty ( $ ldapLogin) ) {
87
91
$ this ->Ldap_User ->delete ($ ldapUser );
88
92
} else {
89
93
$ ldapUser ->setLogin ($ ldapLogin );
90
94
}
91
- } elseif ($ ldapLogin != '' ) {
95
+ } elseif (! empty ( $ ldapLogin) ) {
92
96
$ ldapUserDao = MidasLoader::newDao ('UserDao ' , 'ldap ' );
93
97
$ ldapUserDao ->setUserId ($ user ->getKey ());
94
98
$ ldapUserDao ->setLogin ($ ldapLogin );
@@ -102,37 +106,36 @@ public function userSettingsChanged($params)
102
106
/** generate admin Dashboard information */
103
107
public function getDashboard ()
104
108
{
105
- $ config = Zend_Registry::get ('configsModules ' );
106
- $ hostname = $ config ['ldap ' ]->ldap ->hostname ;
107
- $ port = (int ) $ config ['ldap ' ]->ldap ->port ;
108
- $ proxybasedn = $ config ['ldap ' ]->ldap ->proxyBasedn ;
109
- $ protocolVersion = $ config ['ldap ' ]->ldap ->protocolVersion ;
110
- $ backupServer = $ config ['ldap ' ]->ldap ->backup ;
111
- $ bindn = $ config ['ldap ' ]->ldap ->bindn ;
112
- $ bindpw = $ config ['ldap ' ]->ldap ->bindpw ;
113
- $ proxyPassword = $ config ['ldap ' ]->ldap ->proxyPassword ;
114
-
115
- $ ldap = ldap_connect ($ hostname , $ port );
109
+ $ hostName = $ this ->Setting ->getValueByName (LDAP_HOST_NAME_KEY , $ this ->moduleName );
110
+ $ port = (int ) $ this ->Setting ->getValueByName (LDAP_PORT_KEY , $ this ->moduleName );
111
+ $ proxyBaseDn = $ this ->Setting ->getValueByName (LDAP_PROXY_BASE_DN_KEY , $ this ->moduleName );
112
+ $ protocolVersion = $ this ->Setting ->getValueByName (LDAP_PROTOCOL_VERSION_KEY , $ this ->moduleName );
113
+ $ backupServer = $ this ->Setting ->getValueByName (LDAP_BACKUP_SERVER_KEY , $ this ->moduleName );
114
+ $ bindRdn = $ this ->Setting ->getValueByName (LDAP_BIND_RDN_KEY , $ this ->moduleName );
115
+ $ bindPassword = $ this ->Setting ->getValueByName (LDAP_BIND_PASSWORD_KEY , $ this ->moduleName );
116
+ $ proxyPassword = $ this ->Setting ->getValueByName (LDAP_PROXY_PASSWORD_KEY , $ this ->moduleName );
117
+
118
+ $ ldap = ldap_connect ($ hostName , $ port );
116
119
ldap_set_option ($ ldap , LDAP_OPT_PROTOCOL_VERSION , $ protocolVersion );
117
120
118
121
$ server = false ;
119
122
$ backup = false ;
120
123
121
124
if (isset ($ ldap ) && $ ldap !== false ) {
122
- if ($ proxybasedn != '' ) {
123
- ldap_bind ($ ldap , $ proxybasedn , $ proxyPassword );
125
+ if ($ proxyBaseDn != '' ) {
126
+ ldap_bind ($ ldap , $ proxyBaseDn , $ proxyPassword );
124
127
}
125
128
126
- $ ldapbind = ldap_bind ($ ldap , $ bindn , $ bindpw );
127
- if ($ ldapbind != false ) {
129
+ $ ldapBind = ldap_bind ($ ldap , $ bindRdn , $ bindPassword );
130
+ if ($ ldapBind != false ) {
128
131
$ server = true ;
129
132
}
130
133
131
134
if (!empty ($ backupServer )) {
132
135
$ ldap = ldap_connect ($ backupServer );
133
136
ldap_set_option ($ ldap , LDAP_OPT_PROTOCOL_VERSION , $ protocolVersion );
134
- $ ldapbind = ldap_bind ($ ldap , $ bindn , $ bindpw );
135
- if ($ ldapbind != false ) {
137
+ $ ldapBind = ldap_bind ($ ldap , $ bindRdn , $ bindPassword );
138
+ if ($ ldapBind != false ) {
136
139
$ backup = true ;
137
140
}
138
141
}
@@ -172,53 +175,52 @@ public function ldapLogin($params)
172
175
$ email = $ params ['email ' ];
173
176
$ password = $ params ['password ' ];
174
177
175
- $ config = Zend_Registry::get ('configsModules ' );
176
- $ baseDn = $ config ['ldap ' ]->ldap ->basedn ;
177
- $ hostname = $ config ['ldap ' ]->ldap ->hostname ;
178
- $ port = (int ) $ config ['ldap ' ]->ldap ->port ;
179
- $ protocolVersion = $ config ['ldap ' ]->ldap ->protocolVersion ;
180
- $ autoAddUnknownUser = $ config ['ldap ' ]->ldap ->autoAddUnknownUser ;
181
- $ searchTerm = $ config ['ldap ' ]->ldap ->search ;
182
- $ useActiveDirectory = $ config ['ldap ' ]->ldap ->useActiveDirectory ;
183
- $ proxybasedn = $ config ['ldap ' ]->ldap ->proxyBasedn ;
184
- $ backup = $ config ['ldap ' ]->ldap ->backup ;
185
- $ bindn = $ config ['ldap ' ]->ldap ->bindn ;
186
- $ bindpw = $ config ['ldap ' ]->ldap ->bindpw ;
187
- $ proxyPassword = $ config ['ldap ' ]->ldap ->proxyPassword ;
178
+ $ hostName = $ this ->Setting ->getValueByName (LDAP_HOST_NAME_KEY , $ this ->moduleName );
179
+ $ port = (int ) $ this ->Setting ->getValueByName (LDAP_PORT_KEY , $ this ->moduleName );
180
+ $ proxyBaseDn = $ this ->Setting ->getValueByName (LDAP_PROXY_BASE_DN_KEY , $ this ->moduleName );
181
+ $ protocolVersion = $ this ->Setting ->getValueByName (LDAP_PROTOCOL_VERSION_KEY , $ this ->moduleName );
182
+ $ backupServer = $ this ->Setting ->getValueByName (LDAP_BACKUP_SERVER_KEY , $ this ->moduleName );
183
+ $ bindRdn = $ this ->Setting ->getValueByName (LDAP_BIND_RDN_KEY , $ this ->moduleName );
184
+ $ bindPassword = $ this ->Setting ->getValueByName (LDAP_BIND_PASSWORD_KEY , $ this ->moduleName );
185
+ $ proxyPassword = $ this ->Setting ->getValueByName (LDAP_PROXY_PASSWORD_KEY , $ this ->moduleName );
186
+ $ baseDn = $ this ->Setting ->getValueByName (LDAP_BASE_DN_KEY , $ this ->moduleName );
187
+ $ autoAddUnknownUser = $ this ->Setting ->getValueByName (LDAP_AUTO_ADD_UNKNOWN_USER_KEY , $ this ->moduleName );
188
+ $ searchTerm = $ this ->Setting ->getValueByName (LDAP_SEARCH_TERM_KEY , $ this ->moduleName );
189
+ $ useActiveDirectory = $ this ->Setting ->getValueByName (LDAP_USE_ACTIVE_DIRECTORY_KEY , $ this ->moduleName );
188
190
189
191
if ($ searchTerm == 'uid ' ) {
190
192
$ atCharPos = strpos ($ email , '@ ' );
191
193
if ($ atCharPos === false ) {
192
- $ ldapsearch = 'uid= ' .$ email ;
194
+ $ ldapSearch = 'uid= ' .$ email ;
193
195
} else {
194
- $ ldapsearch = 'uid= ' .substr ($ email , 0 , $ atCharPos );
196
+ $ ldapSearch = 'uid= ' .substr ($ email , 0 , $ atCharPos );
195
197
}
196
198
} else {
197
- $ ldapsearch = $ searchTerm .'= ' .$ email ;
199
+ $ ldapSearch = $ searchTerm .'= ' .$ email ;
198
200
}
199
201
200
- $ ldap = ldap_connect ($ hostname , $ port );
202
+ $ ldap = ldap_connect ($ hostName , $ port );
201
203
202
204
if ($ ldap !== false ) {
203
205
ldap_set_option ($ ldap , LDAP_OPT_PROTOCOL_VERSION , $ protocolVersion );
204
206
if ($ useActiveDirectory ) {
205
207
ldap_set_option ($ ldap , LDAP_OPT_REFERRALS , 0 );
206
208
}
207
- if ($ proxybasedn != '' ) {
208
- $ proxybind = ldap_bind ($ ldap , $ proxybasedn , $ proxyPassword );
209
- if (!$ proxybind ) {
209
+ if ($ proxyBaseDn != '' ) {
210
+ $ proxyBind = ldap_bind ($ ldap , $ proxyBaseDn , $ proxyPassword );
211
+ if (!$ proxyBind ) {
210
212
throw new Zend_Exception ('Cannot bind proxy ' );
211
213
}
212
214
}
213
215
214
- $ ldapbind = ldap_bind ($ ldap , $ bindn , $ bindpw );
215
- if (!$ ldapbind && $ backup ) {
216
- $ ldap = ldap_connect ($ backup );
217
- ldap_bind ($ ldap , $ bindn , $ bindpw );
216
+ $ ldapBind = ldap_bind ($ ldap , $ bindRdn , $ bindPassword );
217
+ if (!$ ldapBind && $ backupServer ) {
218
+ $ ldap = ldap_connect ($ backupServer );
219
+ ldap_bind ($ ldap , $ bindRdn , $ bindPassword );
218
220
}
219
221
220
222
// do an ldap search for the specified user
221
- $ result = ldap_search ($ ldap , $ baseDn , $ ldapsearch , array ('uid ' , 'cn ' , 'mail ' ));
223
+ $ result = ldap_search ($ ldap , $ baseDn , $ ldapSearch , array ('uid ' , 'cn ' , 'mail ' ));
222
224
$ someone = false ;
223
225
if ($ result != 0 ) {
224
226
$ entries = ldap_get_entries ($ ldap , $ result );
@@ -237,8 +239,8 @@ public function ldapLogin($params)
237
239
$ someone = $ someone ->getUser ();
238
240
} elseif ($ autoAddUnknownUser ) {
239
241
// If the user doesn't exist we add it
240
- $ givenname = $ entries [0 ]['cn ' ][0 ];
241
- if (!isset ($ givenname )) {
242
+ $ givenName = $ entries [0 ]['cn ' ][0 ];
243
+ if (!isset ($ givenName )) {
242
244
throw new Zend_Exception (
243
245
'No common name (cn) set in LDAP, cannot register user into Midas '
244
246
);
@@ -253,24 +255,24 @@ public function ldapLogin($params)
253
255
}
254
256
}
255
257
256
- $ names = explode (' ' , $ givenname );
257
- $ firstname = ' ' ;
258
+ $ names = explode (' ' , $ givenName );
259
+ $ firstName = ' ' ;
258
260
$ namesCount = count ($ names );
259
261
if ($ namesCount > 1 ) {
260
- $ firstname = $ names [0 ];
261
- $ lastname = $ names [1 ];
262
+ $ firstName = $ names [0 ];
263
+ $ lastName = $ names [1 ];
262
264
for ($ i = 2 ; $ i < $ namesCount ; $ i ++) {
263
- $ lastname .= ' ' .$ names [$ i ];
265
+ $ lastName .= ' ' .$ names [$ i ];
264
266
}
265
267
} else {
266
- $ lastname = $ names [0 ];
268
+ $ lastName = $ names [0 ];
267
269
}
268
270
$ someone = $ this ->Ldap_User ->createLdapUser (
269
271
$ ldapEmail ,
270
272
$ email ,
271
273
$ password ,
272
- $ firstname ,
273
- $ lastname
274
+ $ firstName ,
275
+ $ lastName
274
276
);
275
277
$ someone = $ someone ->getUser (); // convert to core user dao
276
278
}
@@ -285,7 +287,7 @@ public function ldapLogin($params)
285
287
286
288
return $ someone ;
287
289
} else {
288
- throw new Zend_Exception ('Could not connect to LDAP at ' .$ hostname );
290
+ throw new Zend_Exception ('Could not connect to LDAP at ' .$ hostName );
289
291
}
290
292
}
291
293
@@ -306,13 +308,12 @@ public function handleResetPassword($params)
306
308
{
307
309
$ ldapUser = $ this ->Ldap_User ->getByUser ($ params ['user ' ]);
308
310
if ($ ldapUser !== false ) {
309
- $ config = Zend_Registry::get ('configsModules ' );
310
- $ ldapServer = $ config ['ldap ' ]->ldap ->hostname ;
311
+ $ hostName = $ this ->Setting ->getValueByName (LDAP_HOST_NAME_KEY , $ this ->moduleName );
311
312
$ email = $ params ['user ' ]->getEmail ();
312
313
$ subject = "Password Request " ;
313
314
$ body = "You have requested a new password for Midas Platform.<br/><br/> " ;
314
315
$ body .= "We could not fulfill this request because your user account is managed by an external LDAP server.<br/><br/> " ;
315
- $ body .= "Please contact the administrator of the LDAP server at <b> " .$ ldapServer ."</b> to have your password changed. " ;
316
+ $ body .= "Please contact the administrator of the LDAP server at <b> " .$ hostName ."</b> to have your password changed. " ;
316
317
$ result = Zend_Registry::get ('notifier ' )->callback (
317
318
'CALLBACK_CORE_SEND_MAIL_MESSAGE ' ,
318
319
array (
0 commit comments