Bugfix for redirecting user to home page after login (#221)
https://jira.lyrasis.org/browse/VIVO-1736
This commit is contained in:
parent
193b38159a
commit
2ad521e9da
1 changed files with 10 additions and 25 deletions
|
@ -23,6 +23,7 @@ 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?
|
||||||
|
@ -76,7 +77,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 getApplicationHomePageUrl();
|
return UrlBuilder.getHomeUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoginPage(afterLoginPage)) {
|
if (isLoginPage(afterLoginPage)) {
|
||||||
|
@ -87,20 +88,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 getApplicationHomePageUrl();
|
return UrlBuilder.getHomeUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 getApplicationHomePageUrl();
|
return UrlBuilder.getHomeUrl();
|
||||||
} 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 getApplicationHomePageUrl();
|
return UrlBuilder.getHomeUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,10 +109,12 @@ public class LoginRedirector {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
DisplayMessage.setMessage(request, assembleWelcomeMessage());
|
DisplayMessage.setMessage(request, assembleWelcomeMessage());
|
||||||
response.sendRedirect(getRedirectionUriForLoggedInUser());
|
String redirectUrl = 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(getApplicationHomePageUrl());
|
response.sendRedirect(UrlBuilder.getHomeUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +146,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(getApplicationHomePageUrl());
|
response.sendRedirect(UrlBuilder.getHomeUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,22 +177,4 @@ 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue