1

Spring Boot 2.6.4

Loading Keycloak deployment from configuration file: ServletContext resource [/WEB-INF/keycloak.json]
Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'keycloakAuthenticationProcessingFilter' defined in class path resource [de/icod/blog/configuration/SecurityConfig.class]: Invocation of init method failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adapterDeploymentContext' defined in class path resource [de/icod/blog/configuration/SecurityConfig.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.keycloak.adapters.AdapterDeploymentContext]: Factory method 'adapterDeploymentContext' threw exception;
nested exception is java.io.FileNotFoundException: Unable to locate Keycloak configuration file: keycloak.json

I followed the documentation and copy pasted everything.

The error message says that it can't find /WEB-INF/keycloak.json. That is correct. I don't have a WEB-INF directory in the spring boot generated project. How can I change the location where keycloak-spring-security-adapter is looking for this file?

If I add the following to the SecurityConfig I'm getting a circular dependency error.

@Bean
public KeycloakConfigResolver keycloakConfigResolver() {
    return new KeycloakSpringBootConfigResolver();
}

I have also created <project_root>/WEB-INF/keycloak.json with the same error message.

I'm starting to wonder if Spring Security != Spring Boot Security.

Feedback: I have to say that the documentation isn't very good. For instance keycloak-spring-boot-starter doesn't explain how to get claims from a request. Just "securing" endpoints isn't enough. You also have to use that information somehow, maybe in an interceptor.

UPDATE: This question is "solved" for me, but the answer remains open and while I'm sure there is an answer to this question it's not an easy one.

2
  • This helped with how to get the claims. Ultimately I don't think there's an easy answer to this question. What I learned though is that keycloak-spring-boot-starter alone is enough but if you want all the additional features of spring security keycloak-spring-boot-starter is REQUIRED. When I put the above @Bean into a separate BeanConfig class the circular dependency issue was gone. So now it's working for me, but the question remains unanswered and will probably stay so, which is ok. Java and Spring/boot ecosystem is a mess for someone new or even semi new to the story. ty.
    – user17408941
    Mar 14, 2022 at 22:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy