Skip to content

Commit

Permalink
fixed JENKINS-12224: people redirection fails when Jenkins behind rev…
Browse files Browse the repository at this point in the history
…erse proxy
  • Loading branch information
mspring committed May 11, 2012
1 parent bca6dac commit 813d11b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
target/
mvn.out*
work/
.ws/
Expand Up @@ -66,19 +66,25 @@ public void init(FilterConfig fc) throws ServletException{
}

public void doFilter(ServletRequest req, ServletResponse rsp, FilterChain chain) throws IOException, ServletException{
String uri = ((HttpServletRequest)req).getRequestURI();

if ( !disabled && redirectTarget != null && redirectTarget.length() > 0 && uri.startsWith("/user/")){
String username = uri.substring(6);
if (username.endsWith("/")) username = username.substring(0,username.length()-1);
if (username.indexOf('/') < 0){
HttpServletResponse hrsp = (HttpServletResponse)rsp;
hrsp.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);

String newUri = redirectTarget.replace("${user}",username);
LOG.fine("redirecting to "+newUri);
hrsp.addHeader("Location",newUri);
return;
if ( !disabled && redirectTarget != null && redirectTarget.length() > 0){
HttpServletRequest hreq = (HttpServletRequest)req;
String uri = hreq.getRequestURI();

String ctxp = hreq.getContextPath();
int p = !uri.startsWith(ctxp)? 0 : ctxp.length();

if (uri.startsWith("/user/",p)){
String username = uri.substring(p+6);
if (username.endsWith("/")) username = username.substring(0,username.length()-1);
if (username.indexOf('/') < 0){
HttpServletResponse hrsp = (HttpServletResponse)rsp;
hrsp.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);

String newUri = redirectTarget.replace("${user}",username);
LOG.fine("redirecting to "+newUri);
hrsp.addHeader("Location",newUri);
return;
}
}
}

Expand Down

0 comments on commit 813d11b

Please sign in to comment.