[VIVO-1736] - Bugfix for redirecting user to home page after login (#227)

* Add trailing slash to home page redirect if contextPath empty

* Add redirect path to debug log

* Remove outdated code comment
This commit is contained in:
Ben 2021-05-03 11:03:17 -06:00 committed by GitHub
parent cd437a503e
commit 71ca39d597
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -108,7 +108,9 @@ public class LoginRedirector {
throws IOException {
try {
DisplayMessage.setMessage(request, assembleWelcomeMessage());
response.sendRedirect(getRedirectionUriForLoggedInUser());
String redirectUrl = getRedirectionUriForLoggedInUser();
log.debug("Sending redirect to path: " + redirectUrl);
response.sendRedirect(redirectUrl);
} catch (IOException e) {
log.debug("Problem with re-direction", e);
response.sendRedirect(getApplicationHomePageUrl());
@ -175,21 +177,13 @@ public class LoginRedirector {
}
}
/**
* The application home page can be overridden by an attribute in the
* ServletContext. Further, it can either be an absolute URL, or it can be
* relative to the application. Weird.
*/
private String getApplicationHomePageUrl() {
String contextRedirect = (String) session.getServletContext()
.getAttribute("postLoginRequest");
if (contextRedirect != null) {
if (contextRedirect.indexOf(":") == -1) {
return request.getContextPath() + contextRedirect;
} else {
return contextRedirect;
}
String contextPath = request.getContextPath();
if (contextPath.equals("")) {
return "/";
}
else {
return contextPath;
}
return request.getContextPath();
}
}