柠檬网络安全配置定制



我在项目中使用 SpringLemon。我想自定义authorizeRequests方法,以便任何以"/xyz">开头的请求只能由经过身份验证的用户访问。("/xyz/abc",/xyz/def", "xyz/ghi/jkl">等( 为了做到这一点,我创建了自己的类扩展类LemonWebSecurityConfig并使其成为配置类。我已经覆盖了authorizeRequests方法,如下所示:

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

当我测试它时,它适用于那些"/xyz"URL(在没有身份验证的情况下得到 403(,"/api/core/context"给了我"200",但"/api/core/login"URL 总是给我 404。即使我不覆盖该方法并且只有空的配置类,它也响应 404authorizeRequests。 我错过了什么?

实际上我扩展了一个错误的类。 使用正确的类(如在柠檬演示-jpa中看到的那样(,它可以完美地工作:

@Component
public class MySecurityConfig extends LemonJpaSecurityConfig {
@Override
protected void authorizeRequests(HttpSecurity http) throws Exception {
http.authorizeRequests()
.mvcMatchers("/xyz/**").authenticated();
super.authorizeRequests(http);
}
}

最新更新