柠檬 WebSecurityConfig 自定义

LemonWebSecurityConfig customization

我的项目使用 SpringLemon。我想自定义 authorizeRequests 方法,以便任何以 "/xyz" 开头的请求只能由经过身份验证的用户访问。 ("/xyz/abc"、/xyz/def"、"xyz/ghi/jkl" 等) 为了做到这一点,我做了自己的class扩展LemonWebSecurityConfigclass,并把它做成了一个配置class。我已经覆盖了 authorizeRequests 方法,看起来像这样:

@Override
    protected void authorizeRequests(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .mvcMatchers("/xyz/**").authenticated()
            .mvcMatchers("/**").permitAll();                  
    }

正如我测试的那样,它适用于那些“/xyz”URLs(未经身份验证获得 403),“/api/core/context”给了我“200”,但是“/api/core/login”URL 总是给了我 404。它以 404 响应,即使我不要覆盖 authorizeRequests 方法,我只有空配置 class。 我错过了什么?

其实我扩展错了class。使用正确的 class (如在 lemon-demo-jpa 中看到的那样)它完美地工作:

@Component
public class MySecurityConfig extends LemonJpaSecurityConfig {

    @Override
    protected void authorizeRequests(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .mvcMatchers("/xyz/**").authenticated();
        super.authorizeRequests(http);
    }
}