-1

I am trying to use keycloak springboot adapter. I want to make some endpoints with "/api" work with bearer only to true.

But I also want the endpoint "/login" to not be a bearer only endpoint and redirect the user to the keycloak OIDC login page if he is not authenticated.

How can I achieve that ?

All I have now is just bearer only for every endpoints in my application properties.

Thanks in advance for your answers :)

dur
  • 15,689
  • 25
  • 79
  • 125

1 Answers1

0

In web-security conf,

  • enable anonymous
  • in http-security ant-matchers, add an entry for your public routes with permitAll()
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.anonymous();
        http.authorizeRequests()
                .antMatchers("/login").permitAll()
                .anyRequest().authenticated();
        return http.build();
    }

PS

Keycloak spring adapters are deprecated

As an alternative, you can use:

ch4mp
  • 6,622
  • 6
  • 29
  • 49