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
@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 ?
CodePudding user response:
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