diff --git a/core/src/main/java/hudson/security/AuthenticationProcessingFilter2.java b/core/src/main/java/hudson/security/AuthenticationProcessingFilter2.java index bd9dcb98a1..25688ff490 100644 --- a/core/src/main/java/hudson/security/AuthenticationProcessingFilter2.java +++ b/core/src/main/java/hudson/security/AuthenticationProcessingFilter2.java @@ -1,9 +1,12 @@ package hudson.security; import org.acegisecurity.ui.webapp.AuthenticationProcessingFilter; +import org.kohsuke.stapler.Stapler; import javax.servlet.http.HttpServletRequest; +import hudson.model.Hudson; + /** * {@link AuthenticationProcessingFilter} with a change for Hudson so that * we can pick up the hidden "from" form field defined in login.jelly @@ -16,11 +19,12 @@ public class AuthenticationProcessingFilter2 extends AuthenticationProcessingFil protected String determineTargetUrl(HttpServletRequest request) { String targetUrl = request.getParameter("from"); - if (targetUrl == null) { - targetUrl = getDefaultTargetUrl(); - } - - return targetUrl; + if (targetUrl == null) + return getDefaultTargetUrl(); + else + // URL returned from determineTargetUrl() is resolved against the context path, + // whereas the "from" URL is resolved against the top of the website, so adjust this. + return targetUrl.substring(request.getContextPath().length()); } }