Skip to content

Commit 1b5eb81

Browse files
105-be/user-is-not-registered-after-shibboleth-login (#281)
* firstname and lastname is not required for proper Shibboleth login. * Fixed IT to be failed if code is wrong
1 parent 7455b79 commit 1b5eb81

2 files changed

Lines changed: 7 additions & 26 deletions

File tree

dspace-api/src/main/java/org/dspace/authenticate/clarin/ClarinShibAuthentication.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ protected EPerson registerNewEPerson(Context context, HttpServletRequest request
706706
lname = shibheaders.get_single(lnameHeader);
707707
}
708708

709-
if (email == null || (fnameHeader != null && fname == null) || (lnameHeader != null && lname == null)) {
709+
if ( email == null && netid == null) {
710710
// We require that there be an email, first name, and last name. If we
711711
// don't have at least these three pieces of information then we fail.
712712
String message = "Unable to register new eperson because we are unable to find an email address along " +
@@ -715,22 +715,13 @@ protected EPerson registerNewEPerson(Context context, HttpServletRequest request
715715
message += " Email Header: '" + emailHeader + "'='" + email + "' \n";
716716
message += " First Name Header: '" + fnameHeader + "'='" + fname + "' \n";
717717
message += " Last Name Header: '" + lnameHeader + "'='" + lname + "'";
718-
log.error(message);
719-
718+
log.error( String.format(
719+
"Could not identify a user from [%s] - we have not received enough information " +
720+
"(email, netid, eppn, ...). \n\nDetails:\n%s\n\nHeaders received:\n%s",
721+
org, message, request.getHeaderNames().toString()) );
720722
return null; // TODO should this throw an exception?
721723
}
722724

723-
// Truncate values of parameters that are too big.
724-
if (fname != null && fname.length() > NAME_MAX_SIZE) {
725-
log.warn(
726-
"Truncating eperson's first name because it is longer than " + NAME_MAX_SIZE + ": '" + fname + "'");
727-
fname = fname.substring(0, NAME_MAX_SIZE);
728-
}
729-
if (lname != null && lname.length() > NAME_MAX_SIZE) {
730-
log.warn("Truncating eperson's last name because it is longer than " + NAME_MAX_SIZE + ": '" + lname + "'");
731-
lname = lname.substring(0, NAME_MAX_SIZE);
732-
}
733-
734725
// Turn off authorizations to create a new user
735726
context.turnOffAuthorisationSystem();
736727
EPerson eperson = ePersonService.create(context);

dspace-server-webapp/src/test/java/org/dspace/app/rest/security/ClarinShibbolethLoginFilterIT.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,13 @@ public void shouldReturnUserWithoutEmailException() throws Exception {
167167
public void userFillInEmailAndShouldBeRegisteredByVerificationToken() throws Exception {
168168
String netId = "123456";
169169
String email = "test@mail.epic";
170-
String firstname = "Test";
171-
String lastname = "Buddy";
172170
String idp = "Test Idp";
173171

174172
// Try to authenticate but the Shibboleth doesn't send the email in the header, so the user won't be registered
175173
// but the user will be redirected to the page where he will fill in the user email.
176174
getClient().perform(get("/api/authn/shibboleth")
177175
.header("Shib-Identity-Provider", idp)
178-
.header("SHIB-NETID", netId)
179-
.header("SHIB-GIVENNAME", firstname)
180-
.header("SHIB-SURNAME", lastname))
176+
.header("SHIB-NETID", netId))
181177
.andExpect(status().isFound())
182178
.andExpect(redirectedUrl("http://localhost:4000/login/auth-failed?netid=" + netId));
183179

@@ -201,8 +197,6 @@ public void userFillInEmailAndShouldBeRegisteredByVerificationToken() throws Exc
201197
EPerson ePerson = ePersonService.findByNetid(context, netId);
202198
assertTrue(Objects.nonNull(ePerson));
203199
assertEquals(ePerson.getEmail(), email);
204-
assertEquals(ePerson.getFirstName(), firstname);
205-
assertEquals(ePerson.getLastName(), lastname);
206200

207201
// The user is registered now log him
208202
getClient().perform(get("/api/authn/shibboleth")
@@ -215,17 +209,13 @@ public void userFillInEmailAndShouldBeRegisteredByVerificationToken() throws Exc
215209
getClient().perform(get("/api/authn/shibboleth")
216210
.header("Shib-Identity-Provider", idp)
217211
.header("SHIB-NETID", netId)
218-
.header("SHIB-GIVENNAME", firstname)
219-
.header("SHIB-SURNAME", lastname)
220212
.header("SHIB-MAIL", email))
221213
.andExpect(status().isFound());
222214

223215
// Try to sign in the user by the netid if the eperson exist
224216
getClient().perform(get("/api/authn/shibboleth")
225217
.header("Shib-Identity-Provider", idp)
226-
.header("SHIB-NETID", netId)
227-
.header("SHIB-GIVENNAME", firstname)
228-
.header("SHIB-SURNAME", lastname))
218+
.header("SHIB-NETID", netId))
229219
.andExpect(status().isFound());
230220

231221
// Delete created eperson - clean after the test

0 commit comments

Comments
 (0)