Skip to content

Commit 0f1768a

Browse files
committed
Merge pull request 'Fix #23799: make sure OAuth filters don't eat POST body' (#17) from feature/23799 into develop
+1
2 parents 60ba181 + fd50a10 commit 0f1768a

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority;
5959

6060
import eu.openanalytics.containerproxy.auth.IAuthenticationBackend;
61+
import eu.openanalytics.containerproxy.security.FixedDefaultOAuth2AuthorizationRequestResolver;
6162
import eu.openanalytics.containerproxy.util.SessionHelper;
6263
import net.minidev.json.JSONArray;
6364
import net.minidev.json.parser.JSONParser;
@@ -86,7 +87,7 @@ public String getName() {
8687
public boolean hasAuthorization() {
8788
return true;
8889
}
89-
90+
9091
@Override
9192
public void configureHttpSecurity(HttpSecurity http, AuthorizedUrl anyRequestConfigurer) throws Exception {
9293
ClientRegistrationRepository clientRegistrationRepo = createClientRepo();
@@ -99,9 +100,13 @@ public void configureHttpSecurity(HttpSecurity http, AuthorizedUrl anyRequestCon
99100
.loginPage("/login")
100101
.clientRegistrationRepository(clientRegistrationRepo)
101102
.authorizedClientService(authorizedClientService)
103+
.authorizationEndpoint()
104+
.authorizationRequestResolver(new FixedDefaultOAuth2AuthorizationRequestResolver(clientRegistrationRepo, OAuth2AuthorizationRequestRedirectFilter.DEFAULT_AUTHORIZATION_REQUEST_BASE_URI))
105+
.and()
102106
.userInfoEndpoint()
103107
.userAuthoritiesMapper(createAuthoritiesMapper())
104108
.oidcUserService(createOidcUserService());
109+
105110
}
106111

107112
@Override
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* ContainerProxy
3+
*
4+
* Copyright (C) 2016-2020 Open Analytics
5+
*
6+
* ===========================================================================
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the Apache License as published by
10+
* The Apache Software Foundation, either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* Apache License for more details.
17+
*
18+
* You should have received a copy of the Apache License
19+
* along with this program. If not, see <http://www.apache.org/licenses/>
20+
*/
21+
package eu.openanalytics.containerproxy.security;
22+
23+
import javax.servlet.http.HttpServletRequest;
24+
25+
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
26+
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizationRequestResolver;
27+
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestResolver;
28+
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
29+
30+
/**
31+
* Disables the handling of OAuth on the `/app_direct` URL.
32+
* See issue #23799.
33+
*
34+
* Without this, the Filter will eat the body of the (POST) request. As a result Undertow will not be able
35+
* to proxy the request to the container.
36+
*/
37+
public class FixedDefaultOAuth2AuthorizationRequestResolver implements OAuth2AuthorizationRequestResolver {
38+
39+
private DefaultOAuth2AuthorizationRequestResolver delegate;
40+
41+
public FixedDefaultOAuth2AuthorizationRequestResolver(ClientRegistrationRepository clientRegistrationRepository, String authorizationRequestBaseUri) {
42+
delegate = new DefaultOAuth2AuthorizationRequestResolver(clientRegistrationRepository, authorizationRequestBaseUri);
43+
}
44+
45+
@Override
46+
public OAuth2AuthorizationRequest resolve(HttpServletRequest request) {
47+
if (request.getServletPath().startsWith("/app_direct")) {
48+
return null;
49+
}
50+
return delegate.resolve(request);
51+
}
52+
53+
@Override
54+
public OAuth2AuthorizationRequest resolve(HttpServletRequest request, String clientRegistrationId) {
55+
if (request.getServletPath().startsWith("/app_direct")) {
56+
return null;
57+
}
58+
return delegate.resolve(request, clientRegistrationId);
59+
}
60+
61+
}

0 commit comments

Comments
 (0)