Skip to content

Commit

Permalink
Merge pull request #1861 from webanno/bugfix/1860-redirect-after-login
Browse files Browse the repository at this point in the history
#1860 Redirect to previous url after login does not work
  • Loading branch information
reckart authored Jan 19, 2021
2 parents 262e4a0 + 88840e5 commit 9a71cb8
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public LoginForm(String id)
@Override
protected void onSubmit()
{
String redirectUrl = getRedirectUrl();
AuthenticatedWebSession session = AuthenticatedWebSession.get();
if (session.signIn(username, password)) {
log.debug("Login successful");
Expand All @@ -187,27 +188,25 @@ protected void onSubmit()
.getRequest()).getContainerRequest().getSession(false);
sessionRegistry.registerNewSession(containerSession.getId(), username);
}
setDefaultResponsePageIfNecessary();
setDefaultResponsePageIfNecessary(redirectUrl);
}
else {
error("Login failed");
}
}

private void setDefaultResponsePageIfNecessary()
private void setDefaultResponsePageIfNecessary(String aRedirectUrl)
{
// This does not work because it was Spring Security that intercepted the access, not
// Wicket continueToOriginalDestination();

String redirectUrl = getRedirectUrl();

if (redirectUrl == null || redirectUrl.contains(".IBehaviorListener.")
|| redirectUrl.contains("-logoutPanel-")) {
if (aRedirectUrl == null || aRedirectUrl.contains(".IBehaviorListener.")
|| aRedirectUrl.contains("-logoutPanel-")) {
log.debug("Redirecting to welcome page");
setResponsePage(getApplication().getHomePage());
}
else {
log.debug("Redirecting to saved URL: [{}]", redirectUrl);
log.debug("Redirecting to saved URL: [{}]", aRedirectUrl);
if (isNotBlank(form.urlfragment) && form.urlfragment.startsWith("!")) {
Url url = Url.parse("http://dummy?" + form.urlfragment.substring(1));
UrlRequestParametersAdapter adapter = new UrlRequestParametersAdapter(url);
Expand All @@ -217,7 +216,7 @@ private void setDefaultResponsePageIfNecessary()
}
Session.get().setMetaData(SessionMetaData.LOGIN_URL_FRAGMENT_PARAMS, params);
}
throw new NonResettingRestartException(redirectUrl);
throw new NonResettingRestartException(aRedirectUrl);
}
}
}
Expand Down

0 comments on commit 9a71cb8

Please sign in to comment.