After the update from Spring Boot 2.7.4 to 3.0.4 i get following error message:
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>