|
20 | 20 | */ |
21 | 21 | package eu.openanalytics.containerproxy.ui; |
22 | 22 |
|
23 | | -import javax.inject.Inject; |
24 | | -import javax.servlet.ServletException; |
25 | | -import javax.servlet.http.HttpServletRequest; |
26 | | -import javax.servlet.http.HttpServletResponse; |
27 | | - |
| 23 | +import eu.openanalytics.containerproxy.api.BaseController; |
28 | 24 | import eu.openanalytics.containerproxy.auth.IAuthenticationBackend; |
29 | 25 | import eu.openanalytics.containerproxy.auth.impl.OpenIDAuthenticationBackend; |
30 | 26 | import eu.openanalytics.containerproxy.auth.impl.SAMLAuthenticationBackend; |
31 | | -import eu.openanalytics.containerproxy.auth.impl.saml.SAMLConfiguration; |
32 | 27 | import org.springframework.core.env.Environment; |
33 | | -import org.springframework.http.HttpHeaders; |
34 | | -import org.springframework.http.MediaType; |
35 | 28 | import org.springframework.stereotype.Controller; |
36 | 29 | import org.springframework.ui.ModelMap; |
37 | 30 | import org.springframework.web.bind.annotation.RequestMapping; |
38 | 31 | import org.springframework.web.bind.annotation.RequestMethod; |
39 | | - |
40 | | -import eu.openanalytics.containerproxy.api.BaseController; |
41 | 32 | import org.springframework.web.bind.annotation.RequestParam; |
42 | 33 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
43 | 34 | import org.springframework.web.servlet.view.RedirectView; |
44 | 35 |
|
45 | | -import java.io.IOException; |
46 | | -import java.net.URLEncoder; |
47 | | -import java.nio.charset.StandardCharsets; |
| 36 | +import javax.inject.Inject; |
| 37 | +import javax.servlet.http.HttpServletRequest; |
48 | 38 | import java.util.Optional; |
49 | 39 |
|
50 | 40 | @Controller |
51 | 41 | public class AuthController extends BaseController { |
52 | 42 |
|
53 | 43 | public static final String AUTH_SUCCESS_URL = "/auth-success"; |
| 44 | + public static final String AUTH_SUCCESS_URL_SESSION_ATTR = "AUTH_SUCCESS_URL_SESSION_ATTR"; |
54 | 45 |
|
55 | 46 | @Inject |
56 | 47 | private Environment environment; |
@@ -79,9 +70,19 @@ public Object getLoginPage(@RequestParam Optional<String> error, ModelMap map) { |
79 | 70 | } |
80 | 71 |
|
81 | 72 | @RequestMapping(value = AUTH_SUCCESS_URL, method = RequestMethod.GET) |
82 | | - public String authSuccess(ModelMap map) { |
| 73 | + public String authSuccess(ModelMap map, HttpServletRequest request) { |
83 | 74 | prepareMap(map); |
84 | | - map.put("mainPage", ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString()); |
| 75 | + map.put("url", ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString()); // default url |
| 76 | + |
| 77 | + Object redirectUrl = request.getSession().getAttribute(AUTH_SUCCESS_URL_SESSION_ATTR); |
| 78 | + if (redirectUrl instanceof String) { |
| 79 | + request.getSession().removeAttribute(AUTH_SUCCESS_URL_SESSION_ATTR); |
| 80 | + String sRedirectUrl = (String) redirectUrl; |
| 81 | + // sanity check: does the redirect url start with the url of this current request |
| 82 | + if (sRedirectUrl.startsWith(ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString())) { |
| 83 | + map.put("url", redirectUrl); |
| 84 | + } |
| 85 | + } |
85 | 86 | return "auth-success"; |
86 | 87 | } |
87 | 88 |
|
|
0 commit comments