|
| 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