View Javadoc
1   package com.atlassian.refapp.auth.internal;
2   
3   import org.apache.commons.lang.StringUtils;
4   
5   import javax.servlet.http.HttpServletRequest;
6   import javax.servlet.http.HttpServletResponse;
7   import java.io.IOException;
8   
9   public class RedirectHelper {
10      public static void redirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
11          // An empty context path actually means a "/" is needed to work as a relative redirect
12          String location = StringUtils.isBlank(request.getContextPath()) ? "/" : request.getContextPath();
13  
14          String redirParam = request.getParameter("redir");
15          if (!StringUtils.isEmpty(redirParam)) {
16              if (redirParam.startsWith("http:") || redirParam.startsWith("https:")) {
17                  location = redirParam;
18              } else {
19                  if (!redirParam.startsWith("/")) {
20                      location += "/";
21                  }
22                  location += redirParam;
23              }
24          }
25  
26          response.sendRedirect(location);
27      }
28  
29  }