Commit 6d861f6189bd5eb8f28464bccd60da9d450ae8e4
1 parent
d03f61d3
Merged in from DEV trunk...
KTS-2266 "When adding a single user via authenticated source, you need to fill in the username manually and this breaks the Mass Import" Fixed. Added check for LDAP vs AD and created username based on 'givenname' if 'uid' is null in LDAP. The Jam 'uid' is always null but we can't assume all LDAP servers will return null for 'uid'. Also added a check for duplicate users when doing mass add of users from Authentication Source. Instead of failing or ignoring the user is created with '_DUPLICATE' appended so an admin can clean up afterwards. Committed By: Kevin Fourie Reviewed By: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7121 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
23 additions
and
1 deletions
plugins/ktstandard/ldap/ldapbaseauthenticationprovider.inc.php
| ... | ... | @@ -235,9 +235,16 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider { |
| 235 | 235 | ); |
| 236 | 236 | $this->oValidator->notError($aResults); |
| 237 | 237 | |
| 238 | + $sUserName = $aResults[$this->aAttributes[1]]; | |
| 239 | + // With LDAP, if the 'uid' is null then try using the 'givenname' instead. | |
| 240 | + // See activedirectoryauthenticationprovider.inc.php and ldapauthenticationprovider.inc.php for details. | |
| 241 | + if($this->sAuthenticatorClass == "KTLDAPAuthenticator" && empty($sUserName)) { | |
| 242 | + $sUserName = strtolower($aResults[$this->aAttributes[2]]); | |
| 243 | + } | |
| 244 | + | |
| 238 | 245 | $fields = array(); |
| 239 | 246 | $fields[] = new KTStaticTextWidget(_kt('LDAP DN'), _kt('The location of the user within the LDAP directory.'), 'dn', $id, $this->oPage); |
| 240 | - $fields[] = new KTStringWidget(_kt('Username'), sprintf(_kt('The username the user will enter to gain access to %s. e.g. <strong>jsmith</strong>'), APP_NAME), 'ldap_username', $aResults[$this->aAttributes[1]], $this->oPage, true); | |
| 247 | + $fields[] = new KTStringWidget(_kt('Username'), sprintf(_kt('The username the user will enter to gain access to %s. e.g. <strong>jsmith</strong>'), APP_NAME), 'ldap_username', $sUserName, $this->oPage, true); | |
| 241 | 248 | $fields[] = new KTStringWidget(_kt('Name'), _kt('The full name of the user. This is shown in reports and listings. e.g. <strong>John Smith</strong>'), 'name', $aResults[$this->aAttributes[0]], $this->oPage, true); |
| 242 | 249 | $fields[] = new KTStringWidget(_kt('Email Address'), _kt('The email address of the user. Notifications and alerts are mailed to this address if <strong>email notifications</strong> is set below. e.g. <strong>jsmith@acme.com</strong>'), 'email_address', $aResults[$this->aAttributes[4]], $this->oPage, false); |
| 243 | 250 | $fields[] = new KTCheckboxWidget(_kt('Email Notifications'), _kt('If this is specified then the user will have notifications sent to the email address entered above. If it is not set, then the user will only see notifications on the <strong>Dashboard</strong>'), 'email_notifications', true, $this->oPage, false); |
| ... | ... | @@ -307,14 +314,29 @@ class KTLDAPBaseAuthenticationProvider extends KTAuthenticationProvider { |
| 307 | 314 | $oSource =& KTAuthenticationSource::get($_REQUEST['source_id']); |
| 308 | 315 | $oAuthenticator = $this->getAuthenticator($oSource); |
| 309 | 316 | $aNames = array(); |
| 317 | + | |
| 310 | 318 | foreach ($aIds as $sId) { |
| 311 | 319 | $aResults = $oAuthenticator->getUser($sId); |
| 312 | 320 | $dn = $sId; |
| 313 | 321 | $sUserName = $aResults[$this->aAttributes[1]]; |
| 322 | + // With LDAP, if the 'uid' is null then try using the 'givenname' instead. | |
| 323 | + // See activedirectoryauthenticationprovider.inc.php and ldapauthenticationprovider.inc.php for details. | |
| 324 | + if($this->sAuthenticatorClass == "KTLDAPAuthenticator" && empty($sUserName)) { | |
| 325 | + $sUserName = strtolower($aResults[$this->aAttributes[2]]); | |
| 326 | + } | |
| 314 | 327 | $sName = $aResults[$this->aAttributes[0]]; |
| 315 | 328 | $sEmailAddress = $aResults[$this->aAttributes[4]]; |
| 316 | 329 | $sMobileNumber = $aResults[$this->aAttributes[5]]; |
| 317 | 330 | |
| 331 | + // If the user already exists append some text so the admin can see the duplicates. | |
| 332 | + $appending = true; | |
| 333 | + while($appending) { | |
| 334 | + if(!PEAR::isError(User::getByUserName($sUserName))) { | |
| 335 | + $sUserName = $sUserName . "_DUPLICATE"; | |
| 336 | + $appending = true; | |
| 337 | + } else $appending = false; | |
| 338 | + } | |
| 339 | + | |
| 318 | 340 | $oUser = User::createFromArray(array( |
| 319 | 341 | "Username" => $sUserName, |
| 320 | 342 | "Name" => $sName, | ... | ... |