How to allow “/api/**” through my basic auth config and into my oauth config in Spring Security

前端 未结 2 901
忘掉有多难
忘掉有多难 2020-12-21 17:52

I have an app that uses both Basic Auth and OAuth2.

Some URLs are authorized using Basic Auth and \"/api/**\" is authorized using OAuth2.

Currently, I have t

相关标签:
2条回答
  • 2020-12-21 18:44

    You should use Order(...) annotation on @Configuration classes. Make your OAuth2ServerConfig config first and serving only http.requestMatchers().antMatchers("/api/**") and make your WebSecurityConfig second (@Order(2)) without http.requestMatchers() to serve all rest URLs!

    See details on https://stackoverflow.com/a/44871933/173149

    0 讨论(0)
  • 2020-12-21 18:48

    You can use NegatedRequestMatcher:

    A RequestMatcher that will negate the RequestMatcher passed in. For example, if the RequestMatcher passed in returns true, NegatedRequestMatcher will return false. If the RequestMatcher passed in returns false, NegatedRequestMatcher will return true.

    0 讨论(0)
提交回复
热议问题