Spring security with Oauth2 or Http-Basic authentication for the same resource

前端 未结 8 1190
南方客
南方客 2021-01-30 09:07

I\'m attempting to implement an API with resources that are protected by either Oauth2 OR Http-Basic authentication.

When I load the WebSecurityConfigurerAdapter which a

8条回答
  •  长情又很酷
    2021-01-30 09:36

    Can't provide you with complete example, but here's a hints to dig:

    Roughly, spring auth is just a combination of request filter that extract auth data from request (headers) and authentication manager that provides authentication object for that auth.

    So to get basic and oauth at the same url, you need 2 filters installed in filter chain BasicAuthenticationFilter and OAuth2AuthenticationProcessingFilter.

    I think the problem is that ConfiguringAdapters good for more simple confs as they tend to override each other. So as a first step try to move

    .httpBasic();
    

    call to ResourceServerConfiguration Note that you also need to provide 2 different auth managers: one for basic auth and one for oauth

提交回复
热议问题