我正在尝试为Google OAuth2背后的应用程序配置Spring Security。
问题是我想通过Webhooks将来自Github和Bitbucket的某些API调用列入白名单,为此我编写了自定义身份验证提供程序。 我已经在春季安全链中添加了这些身份验证提供程序,但是这些调用似乎没有被调用。
对Google OAuth2的请求运行正常,我可以登录。但是,来自Github和Bitbucket的所有请求都将导致401,而不会影响身份验证提供程序。
这里真的需要一些帮助。
谢谢!
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private OAuth2UserServiceImpl oAuth2UserService;
@Autowired
private GithubIpAuthenticationProvider githubIpAuthenticationProvider;
@Autowired
private BitbucketIpAuthenticationProvider bitbucketIpAuthenticationProvider;
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/*/applications/*/webhooks/github")
.authenticated()
.and()
.authenticationProvider(githubIpAuthenticationProvider)
.authorizeRequests()
.antMatchers("/api/*/applications/*/webhooks/bitbucket")
.authenticated()
.and()
.authenticationProvider(bitbucketIpAuthenticationProvider)
.authorizeRequests()
.antMatchers("/api/**")
.authenticated()
.and()
.oauth2Login()
.userInfoEndpoint()
.userService(oAuth2UserService)
.and()
.and()
.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(
(a,b,c) -> {b.sendError(HttpServletResponse.SC_UNAUTHORIZED);}
)
.and()
.cors();
}
}