Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can not configure Keycloak 17 in spring boot app – elements [keycloak.keycloak.bearer-only] were left unbound

I need to disable login page Keycloak redirect in Spring Boot app, this are my configurations:

application.yml

server:
  port: 8091
  connection-timeout: 6000
keycloak:
  enabled: true
  bearer-only: true
  auth-server-url: http://localhost:8484/auth
  realm: test-realm
  resource: my-test-client
  keycloak.bearer-only: true
  use-resource-role-mappings: false

SecurityConfig

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@ComponentScan(basePackageClasses = KeycloakSecurityComponents.class)
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);

        http.cors().and().csrf().disable().sessionManagement().

                sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
                .antMatchers("/users/unprotected-data").permitAll()
                .antMatchers("/users/create").permitAll()
                .antMatchers("/users/signin").permitAll()
                .anyRequest().authenticated();

    }
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
        keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
        auth.authenticationProvider(keycloakAuthenticationProvider);
    }

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

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

    @Autowired
    public KeycloakClientRequestFactory keycloakClientRequestFactory;

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public KeycloakRestTemplate keycloakRestTemplate(){
        return new KeycloakRestTemplate(keycloakClientRequestFactory);
    }
}

but I have an error configuration message that KeycloakSpringBootProperties cannot bi binded to ConfigurationProperties:

Description:

Binding to target [Bindable@7bb35cc6 type = org.keycloak.adapters.springboot.KeycloakSpringBootProperties, value = 'provided', annotations = array<Annotation>[@org.springframework.boot.context.properties.ConfigurationProperties(ignoreInvalidFields=false, ignoreUnknownFields=false, prefix=keycloak, value=keycloak)]] failed:

    Property: keycloak.keycloak.bearer-only
    Value: true
    Origin: class path resource [application.yml] - 10:25
    Reason: The elements [keycloak.keycloak.bearer-only] were left unbound.

Action:

Update your application's configuration

What would be the right way to update configuration ?

>Solution :

As much as I know,

Its either keycloak.bearer-only: true or

keycloak:
bearer-only: true

Which are both equal.

But what your trying to do is keycloak.keycloak.bearer-only: true which is incorrect.

Here is an answer that might be helpful

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading