0

After the update from Spring Boot 2.7.4 to 3.0.4 i get following error message:

enter image description here

Cannot invoke "org.keycloak.KeycloakPrincipal.getKeycloakSecurityContext()" because the return value of "jakarta.servlet.http.HttpServletRequest.getUserPrincipal()" is null

This is how my @SpringBootApplication class looks like:

@SpringBootApplication
public class App {

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

    @Bean
    @Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
    public AccessToken getAccessToken() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
        return ((KeycloakPrincipal) request.getUserPrincipal()).getKeycloakSecurityContext().getToken();
    }

}

And the entry of Keycloak starter in my pom.xml file:

        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-spring-boot-starter</artifactId>
        </dependency>
stylepatrick
  • 173
  • 2
  • 11
  • 1
    Does this answer your question? [Use Keycloak Spring Adapter with Spring Boot 3](https://stackoverflow.com/questions/74571191/use-keycloak-spring-adapter-with-spring-boot-3) – ch4mp Mar 17 '23 at 09:57

0 Answers0