Revert "Bugfix for redirecting user to home page after login (#221)"

This reverts commit 2ad521e9da.
This commit is contained in:
Brian Lowe 2021-04-06 20:21:51 +03:00 committed by GitHub
parent 2ad521e9da
commit def81c9013

View file

@ -23,7 +23,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers; import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.i18n.I18n; import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle; import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
/** /**
* A user has just completed the login process. What page do we direct them to? * A user has just completed the login process. What page do we direct them to?
@ -77,7 +76,7 @@ public class LoginRedirector {
if (!canSeeSiteAdminPage()) { if (!canSeeSiteAdminPage()) {
log.debug("User not recognized. Going to application home."); log.debug("User not recognized. Going to application home.");
return UrlBuilder.getHomeUrl(); return getApplicationHomePageUrl();
} }
if (isLoginPage(afterLoginPage)) { if (isLoginPage(afterLoginPage)) {
@ -88,20 +87,20 @@ public class LoginRedirector {
return afterLoginPage; return afterLoginPage;
} else { } else {
log.debug("Don't know what to do. Go home."); log.debug("Don't know what to do. Go home.");
return UrlBuilder.getHomeUrl(); return getApplicationHomePageUrl();
} }
} }
public String getRedirectionUriForCancellingUser() { public String getRedirectionUriForCancellingUser() {
if (isLoginPage(afterLoginPage)) { if (isLoginPage(afterLoginPage)) {
log.debug("Coming from /login. Going to home."); log.debug("Coming from /login. Going to home.");
return UrlBuilder.getHomeUrl(); return getApplicationHomePageUrl();
} else if (null != afterLoginPage) { } else if (null != afterLoginPage) {
log.debug("Returning to requested page: " + afterLoginPage); log.debug("Returning to requested page: " + afterLoginPage);
return afterLoginPage; return afterLoginPage;
} else { } else {
log.debug("Don't know what to do. Go home."); log.debug("Don't know what to do. Go home.");
return UrlBuilder.getHomeUrl(); return getApplicationHomePageUrl();
} }
} }
@ -109,12 +108,10 @@ public class LoginRedirector {
throws IOException { throws IOException {
try { try {
DisplayMessage.setMessage(request, assembleWelcomeMessage()); DisplayMessage.setMessage(request, assembleWelcomeMessage());
String redirectUrl = getRedirectionUriForLoggedInUser(); response.sendRedirect(getRedirectionUriForLoggedInUser());
log.debug("Sending redirect to path: " + redirectUrl);
response.sendRedirect(redirectUrl);
} catch (IOException e) { } catch (IOException e) {
log.debug("Problem with re-direction", e); log.debug("Problem with re-direction", e);
response.sendRedirect(UrlBuilder.getHomeUrl()); response.sendRedirect(getApplicationHomePageUrl());
} }
} }
@ -146,7 +143,7 @@ public class LoginRedirector {
response.sendRedirect(getRedirectionUriForCancellingUser()); response.sendRedirect(getRedirectionUriForCancellingUser());
} catch (IOException e) { } catch (IOException e) {
log.debug("Problem with re-direction", e); log.debug("Problem with re-direction", e);
response.sendRedirect(UrlBuilder.getHomeUrl()); response.sendRedirect(getApplicationHomePageUrl());
} }
} }
@ -177,4 +174,22 @@ public class LoginRedirector {
throw new IllegalStateException("No UTF-8 encoding? Really?", e); throw new IllegalStateException("No UTF-8 encoding? Really?", e);
} }
} }
/**
* 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;
}
}
return request.getContextPath();
}
} }