Skip to content

Commit 73ea707

Browse files
committed
Make AuthenticationManager available for Keycloak too
1 parent 119d110 commit 73ea707

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
5151
import org.springframework.context.ApplicationContext;
5252
import org.springframework.context.annotation.Bean;
53+
import org.springframework.context.annotation.Lazy;
5354
import org.springframework.core.env.Environment;
55+
import org.springframework.security.authentication.AuthenticationManager;
5456
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
5557
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5658
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@@ -85,7 +87,11 @@ public class KeycloakAuthenticationBackend implements IAuthenticationBackend {
8587

8688
@Inject
8789
ApplicationContext ctx;
88-
90+
91+
@Inject
92+
@Lazy
93+
AuthenticationManager authenticationManager;
94+
8995
@Override
9096
public String getName() {
9197
return NAME;
@@ -126,14 +132,14 @@ protected KeycloakAuthenticationProcessingFilter keycloakAuthenticationProcessin
126132
// Possible solution for issue #21037, create a custom RequestMatcher that doesn't include a QueryParamPresenceRequestMatcher(OAuth2Constants.ACCESS_TOKEN) request matcher.
127133
// The QueryParamPresenceRequestMatcher(OAuth2Constants.ACCESS_TOKEN) caused the HTTP requests to be changed before they where processed.
128134
// Because the HTTP requests are adapted before they are processed, the requested failed to complete successfully and caused an io.undertow.server.TruncatedResponseException
129-
// If in the future we need a RequestMatcher for het ACCESS_TOKEN, we can implement one ourself
135+
// If in the future we need a RequestMatcher for het ACCESS_TOKEN, we can implement one ourself
130136
RequestMatcher requestMatcher =
131137
new OrRequestMatcher(
132138
new AntPathRequestMatcher(KeycloakAuthenticationProcessingFilter.DEFAULT_LOGIN_URL),
133139
new RequestHeaderRequestMatcher(KeycloakAuthenticationProcessingFilter.AUTHORIZATION_HEADER)
134140
);
135-
136-
KeycloakAuthenticationProcessingFilter filter = new KeycloakAuthenticationProcessingFilter(webSecurityConfigurerAdapter.authenticationManagerBean(), requestMatcher);
141+
142+
KeycloakAuthenticationProcessingFilter filter = new KeycloakAuthenticationProcessingFilter(authenticationManager, requestMatcher);
137143
filter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy());
138144
// Fix: call afterPropertiesSet manually, because Spring doesn't invoke it for some reason.
139145
filter.setApplicationContext(ctx);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void init(AuthenticationManagerBuilder amb) throws Exception {
167167
}
168168

169169
@Bean(name="authenticationManager")
170-
@ConditionalOnExpression("'${proxy.authentication}' == 'kerberos' || '${proxy.authentication}' == 'saml'")
170+
@ConditionalOnExpression("'${proxy.authentication}' == 'kerberos' || '${proxy.authentication}' == 'saml' || '${proxy.authentication}' == 'keycloak'")
171171
@Override
172172
public AuthenticationManager authenticationManagerBean() throws Exception {
173173
return super.authenticationManagerBean();

0 commit comments

Comments
 (0)