Skip to content

Commit 8d9191b

Browse files
authored
Merge pull request DSpace#11331 from dataquest-dev/ldap-no-email-fix-main
LDAP Authentication fails when user has no email despite netid_email_domain configuration
2 parents 0968714 + 6a10ba7 commit 8d9191b

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

dspace-api/src/main/java/org/dspace/authenticate/LDAPAuthentication.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public int authenticate(Context context,
325325
log.info(LogHelper.getHeader(context,
326326
"type=ldap-login", "type=ldap_but_already_email"));
327327
context.turnOffAuthorisationSystem();
328-
setEpersonAttributes(context, eperson, ldap, Optional.of(netid));
328+
setEpersonAttributes(context, eperson, ldap, Optional.of(netid), email);
329329
ePersonService.update(context, eperson);
330330
context.dispatchEvents();
331331
context.restoreAuthSystemState();
@@ -342,7 +342,7 @@ public int authenticate(Context context,
342342
try {
343343
context.turnOffAuthorisationSystem();
344344
eperson = ePersonService.create(context);
345-
setEpersonAttributes(context, eperson, ldap, Optional.of(netid));
345+
setEpersonAttributes(context, eperson, ldap, Optional.of(netid), email);
346346
eperson.setCanLogIn(true);
347347
authenticationService.initEPerson(context, request, eperson);
348348
ePersonService.update(context, eperson);
@@ -384,11 +384,24 @@ public int authenticate(Context context,
384384
* Update eperson's attributes
385385
*/
386386
private void setEpersonAttributes(Context context, EPerson eperson, SpeakerToLDAP ldap, Optional<String> netid)
387-
throws SQLException {
387+
throws SQLException {
388+
setEpersonAttributes(context, eperson, ldap, netid, null);
389+
}
388390

391+
/**
392+
* Update eperson's attributes
393+
*/
394+
private void setEpersonAttributes(Context context, EPerson eperson, SpeakerToLDAP ldap, Optional<String> netid,
395+
String email)
396+
throws SQLException {
397+
398+
// Set email address: first try LDAP email, then fallback to provided email parameter
389399
if (StringUtils.isNotEmpty(ldap.ldapEmail)) {
390400
eperson.setEmail(ldap.ldapEmail);
401+
} else if (StringUtils.isNotEmpty(email)) {
402+
eperson.setEmail(email);
391403
}
404+
392405
if (StringUtils.isNotEmpty(ldap.ldapGivenName)) {
393406
eperson.setFirstName(context, ldap.ldapGivenName);
394407
}

0 commit comments

Comments
 (0)