Skip to content

Commit aed75c9

Browse files
committed
Fix #30568: prevent going back to IDP page
1 parent 9a2ed52 commit aed75c9

6 files changed

Lines changed: 52 additions & 4 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/auth/impl/KeycloakAuthenticationBackend.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
import java.util.Map;
7878
import java.util.stream.Collectors;
7979

80+
import static eu.openanalytics.containerproxy.ui.AuthController.AUTH_SUCCESS_URL;
81+
8082
@Component
8183
public class KeycloakAuthenticationBackend implements IAuthenticationBackend {
8284

@@ -142,7 +144,7 @@ protected KeycloakAuthenticationProcessingFilter keycloakAuthenticationProcessin
142144
KeycloakAuthenticationProcessingFilter filter = new KeycloakAuthenticationProcessingFilter(authenticationManager, requestMatcher);
143145
filter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy());
144146
filter.setAuthenticationFailureHandler(keycloakAuthenticationFailureHandler());
145-
SimpleUrlAuthenticationSuccessHandler handler = new SimpleUrlAuthenticationSuccessHandler("/");
147+
SimpleUrlAuthenticationSuccessHandler handler = new SimpleUrlAuthenticationSuccessHandler(AUTH_SUCCESS_URL);
146148
handler.setAlwaysUseDefaultTargetUrl(true);
147149
filter.setAuthenticationSuccessHandler(handler);
148150
// Fix: call afterPropertiesSet manually, because Spring doesn't invoke it for some reason.

src/main/java/eu/openanalytics/containerproxy/auth/impl/OpenIDAuthenticationBackend.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import java.util.stream.Collectors;
7878

7979
import static eu.openanalytics.containerproxy.auth.impl.oidc.OpenIDConfiguration.REG_ID;
80+
import static eu.openanalytics.containerproxy.ui.AuthController.AUTH_SUCCESS_URL;
8081

8182
public class OpenIDAuthenticationBackend implements IAuthenticationBackend {
8283

@@ -119,7 +120,7 @@ public void configureHttpSecurity(HttpSecurity http, AuthorizedUrl anyRequestCon
119120
http
120121
.oauth2Login()
121122
.loginPage("/login")
122-
.defaultSuccessUrl("/", true)
123+
.defaultSuccessUrl(AUTH_SUCCESS_URL, true)
123124
.clientRegistrationRepository(clientRegistrationRepo)
124125
.authorizedClientService(oAuth2AuthorizedClientService)
125126
.authorizationEndpoint()

src/main/java/eu/openanalytics/containerproxy/auth/impl/SAMLAuthenticationBackend.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import static eu.openanalytics.containerproxy.auth.impl.saml.SAMLConfiguration.SAML_LOGOUT_SERVICE_LOCATION_PATH;
5656
import static eu.openanalytics.containerproxy.auth.impl.saml.SAMLConfiguration.SAML_LOGOUT_SERVICE_RESPONSE_LOCATION_PATH;
5757
import static eu.openanalytics.containerproxy.auth.impl.saml.SAMLConfiguration.SAML_SERVICE_LOCATION_PATH;
58+
import static eu.openanalytics.containerproxy.ui.AuthController.AUTH_SUCCESS_URL;
5859

5960
@Component
6061
@ConditionalOnProperty(name = "proxy.authentication", havingValue = "saml")
@@ -98,7 +99,7 @@ public void configureHttpSecurity(HttpSecurity http, AuthorizedUrl anyRequestCon
9899
.loginProcessingUrl(SAML_SERVICE_LOCATION_PATH)
99100
.authenticationManager(new ProviderManager(samlAuthenticationProvider))
100101
.failureHandler(failureHandler)
101-
.defaultSuccessUrl("/", true))
102+
.defaultSuccessUrl(AUTH_SUCCESS_URL, true))
102103
.saml2Logout(saml -> saml
103104
.logoutUrl(SAML_LOGOUT_SERVICE_LOCATION_PATH)
104105
.logoutResponse(r -> r.logoutUrl(SAML_LOGOUT_SERVICE_RESPONSE_LOCATION_PATH))

src/main/java/eu/openanalytics/containerproxy/security/WebSecurityConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.util.List;
7676
import java.util.Set;
7777

78+
import static eu.openanalytics.containerproxy.ui.AuthController.AUTH_SUCCESS_URL;
7879
import static eu.openanalytics.containerproxy.ui.TemplateResolverConfig.PROP_CORS_ALLOWED_ORIGINS;
7980

8081
@Configuration
@@ -232,7 +233,7 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Acc
232233
http
233234
.formLogin()
234235
.loginPage("/login")
235-
.defaultSuccessUrl("/", true)
236+
.defaultSuccessUrl(AUTH_SUCCESS_URL, true) // TODO
236237
.and()
237238
.logout()
238239
.logoutUrl(auth.getLogoutURL())

src/main/java/eu/openanalytics/containerproxy/ui/AuthController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
@Controller
5151
public class AuthController extends BaseController {
5252

53+
public static final String AUTH_SUCCESS_URL = "/auth-success";
54+
5355
@Inject
5456
private Environment environment;
5557

@@ -76,6 +78,13 @@ public Object getLoginPage(@RequestParam Optional<String> error, ModelMap map) {
7678
}
7779
}
7880

81+
@RequestMapping(value = AUTH_SUCCESS_URL, method = RequestMethod.GET)
82+
public String authSuccess(ModelMap map) {
83+
prepareMap(map);
84+
map.put("mainPage", ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString());
85+
return "auth-success";
86+
}
87+
7988
@RequestMapping(value = "/auth-error", method = RequestMethod.GET)
8089
public String getAuthErrorPage(ModelMap map) {
8190
prepareMap(map);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!--
2+
3+
ContainerProxy
4+
5+
Copyright (C) 2016-2023 Open Analytics
6+
7+
===========================================================================
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the Apache License as published by
11+
The Apache Software Foundation, either version 2 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
Apache License for more details.
18+
19+
You should have received a copy of the Apache License
20+
along with this program. If not, see <http://www.apache.org/licenses/>
21+
22+
-->
23+
<!DOCTYPE html>
24+
<html
25+
xmlns:th="http://www.thymeleaf.org">
26+
<head lang="en">
27+
<title th:text="${title}"></title>
28+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
29+
<script type="text/javascript" th:inline="javascript">
30+
history.pushState({}, "", new URL(location));
31+
window.location.href = [[${mainPage}]];
32+
</script>
33+
</head>
34+
</html>

0 commit comments

Comments
 (0)