OiO.lk English java Spring error Caused by: java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of “Issuer-uri”
java

Spring error Caused by: java.lang.IllegalArgumentException: Unable to resolve Configuration with the provided Issuer of “Issuer-uri”


I have a keycloak instance running and that i access normally. All keycloak endpoints are running as they should. I tried connecting my Spring app to keycloak through the following

App.yaml :

(https://i.sstatic.net/tLXfhxyf.png)

SecurityConfig:

``@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http.csrf(csrf -> csrf.disable())
            .authorizeHttpRequests(auth -> auth
                    .requestMatchers("/public/**", "/oauth2/**", "/login/**").permitAll()
                    .anyRequest().authenticated()
            )
            .oauth2Login(oauth2 -> oauth2
                    .loginPage("/oauth2/authorization/keycloak")
                    .defaultSuccessUrl("/", true)
            )
            .logout(logout -> logout
                    .logoutSuccessUrl("/")
                    .permitAll()
            );

    return http.build();
}

@Bean
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
    return new NullAuthenticatedSessionStrategy();
}

@Bean
public OAuth2AuthorizedClientManager authorizedClientManager(
        ClientRegistrationRepository clientRegistrationRepository,
        OAuth2AuthorizedClientRepository authorizedClientRepository) {

    OAuth2AuthorizedClientProvider authorizedClientProvider =
            OAuth2AuthorizedClientProviderBuilder.builder()
                    .authorizationCode()
                    .refreshToken()
                    .build();

    DefaultOAuth2AuthorizedClientManager authorizedClientManager =
            new DefaultOAuth2AuthorizedClientManager(
                    clientRegistrationRepository, authorizedClientRepository);
    authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);

    return authorizedClientManager;
    }
}``

KeycloakConfig:

@Configuration
public class KeycloakConfig {

@Value("${spring.security.oauth2.client.provider.keycloak.issuer-uri}")
private String serverUrl;

@Value("${spring.security.oauth2.client.registration.keycloak.client-id}")
private String clientId;

@Value("${spring.security.oauth2.client.registration.keycloak.client-secret}")
private String clientSecret;

@Bean
public Keycloak keycloak() {
    return KeycloakBuilder.builder()
            .serverUrl("http://localhost:8080") // Remove realm from server URL
            .realm("FlowUsers")  // Hardcode realm or make it configurable if needed
            .clientId(clientId)
            .clientSecret(clientSecret)
            .grantType("client_credentials")
            .build();
}

}`

Yet i keep getting this error whenever I run the Spring app :
‘clientRegistrationRepository’ threw exception with message: Unable to resolve Configuration with the provided Issuer of "http://localhost:8080/realms/FlowUsers"

I tested Keycloak endpoints and they are returning the correct outputs, Double-checked every url in my yaml.



You need to sign in to view this answers

Exit mobile version