我一直在尝试使用Spring Boot制作一个应用程序,该应用程序使用Google作为登录的身份提供程序。
以下配置(使用Spring Security)似乎可以解决此问题:
@Configuration
@EnableOAuth2Sso
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**","/callback/", "/error**")
.permitAll()
.anyRequest()
.authenticated();
}
}
但是,我只想真正保护网站的一小部分(例如/ secured /路径下的所有内容)。
因此,我认为更改授权请求的antMatcher可以解决此问题:
...
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
antMatcher("/secured**")
.authorizeRequests()
...
当我尝试此操作时,应用程序仍将我重定向到/ login,但该页面上却显示了404,而不是将我重定向到google的服务器。
我当然可以将所有公共URL添加到permitAll antMatcher中,但是每次添加新的URL似乎都很麻烦。
我也不愿将所有公共事物放在/ public **路径上,因为它在url中看起来很奇怪
有人可以阐明这里发生的事情还是提供替代解决方案?
谢谢!