@@ -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