|
30 | 30 | import javax.inject.Inject; |
31 | 31 | import javax.servlet.ServletException; |
32 | 32 |
|
| 33 | +import org.keycloak.OAuth2Constants; |
33 | 34 | import org.keycloak.adapters.AdapterDeploymentContext; |
34 | 35 | import org.keycloak.adapters.KeycloakConfigResolver; |
35 | 36 | import org.keycloak.adapters.KeycloakDeployment; |
|
43 | 44 | import org.keycloak.adapters.springsecurity.authentication.KeycloakLogoutHandler; |
44 | 45 | import org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticationProcessingFilter; |
45 | 46 | import org.keycloak.adapters.springsecurity.filter.KeycloakPreAuthActionsFilter; |
| 47 | +import org.keycloak.adapters.springsecurity.filter.QueryParamPresenceRequestMatcher; |
46 | 48 | import org.keycloak.adapters.springsecurity.management.HttpSessionManager; |
47 | 49 | import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; |
48 | 50 | import org.keycloak.representations.IDToken; |
|
63 | 65 | import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy; |
64 | 66 | import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; |
65 | 67 | import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; |
| 68 | +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
| 69 | +import org.springframework.security.web.util.matcher.OrRequestMatcher; |
| 70 | +import org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher; |
| 71 | +import org.springframework.security.web.util.matcher.RequestMatcher; |
66 | 72 | import org.springframework.stereotype.Component; |
67 | 73 |
|
68 | 74 | import eu.openanalytics.containerproxy.auth.IAuthenticationBackend; |
@@ -118,7 +124,17 @@ public String getLogoutSuccessURL() { |
118 | 124 | @Bean |
119 | 125 | @ConditionalOnProperty(name="proxy.authentication", havingValue="keycloak") |
120 | 126 | protected KeycloakAuthenticationProcessingFilter keycloakAuthenticationProcessingFilter() throws Exception { |
121 | | - KeycloakAuthenticationProcessingFilter filter = new KeycloakAuthenticationProcessingFilter(authenticationManager); |
| 127 | + // Possible solution for issue #21037, create a custom RequestMatcher that doesn't include a QueryParamPresenceRequestMatcher(OAuth2Constants.ACCESS_TOKEN) request matcher. |
| 128 | + // The QueryParamPresenceRequestMatcher(OAuth2Constants.ACCESS_TOKEN) caused the HTTP requests to be changed before they where processed. |
| 129 | + // Because the HTTP requests are adapted before they are processed, the requested failed to complete successfully and caused an io.undertow.server.TruncatedResponseException |
| 130 | + // If in the future we need a RequestMatcher for het ACCESS_TOKEN, we can implement one ourself |
| 131 | + RequestMatcher requestMatcher = |
| 132 | + new OrRequestMatcher( |
| 133 | + new AntPathRequestMatcher(KeycloakAuthenticationProcessingFilter.DEFAULT_LOGIN_URL), |
| 134 | + new RequestHeaderRequestMatcher(KeycloakAuthenticationProcessingFilter.AUTHORIZATION_HEADER) |
| 135 | + ); |
| 136 | + |
| 137 | + KeycloakAuthenticationProcessingFilter filter = new KeycloakAuthenticationProcessingFilter(authenticationManager, requestMatcher); |
122 | 138 | filter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy()); |
123 | 139 | // Fix: call afterPropertiesSet manually, because Spring doesn't invoke it for some reason. |
124 | 140 | filter.setApplicationContext(ctx); |
|
0 commit comments