代码之家  ›  专栏  ›  技术社区  ›  Andrea Girardi

${_csrf.令牌}在jsp上使用spring安全性总是空的

  •  0
  • Andrea Girardi  · 技术社区  · 6 年前

    我正在开发一个遗留的Spring MVC应用程序,我需要将\u csrf令牌传递给javascript,但是在引入Spring安全性(特别是auth0用户身份验证)之后,这两行总是空的:

    <meta name="_csrf" content="${_csrf.token}"/>
    <meta name="_csrf_header" content="${_csrf.headerName}"/>
    

    这就是我如何重写configure(HttpSecurity http):

    @Configuration
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    @PropertySources(@PropertySource("classpath:auth0.properties"))
    @Order(-2 /* SecurityProperties.ACCESS_OVERRIDE_ORDER */)
    public class AppConfig extends WebSecurityConfigurerAdapter {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
    
            http.authorizeRequests() 
                .antMatchers("/download/**", "/resources/**", "/plugins/**", "/js/**", "/css/**", "/colors/**", "/callback", "/login", "/loggedout").permitAll()
                .antMatchers("/**").authenticated()
                .and()
                .logout().permitAll();
        }
    
    }
    

    我已经移除了 委派过滤代理 从网站.xml因为它应该扩展 Web安全配置适配器 ${_csrf.parameterName} and ${_csrf.token} return null 我应该重新添加,但是如果我添加了,我会得到一个启动错误(缺少springSecurityFilterChain)。

    所以,问题是,如果我实现了WebSecurityConfigurerAdapter并且没有禁用csrf,为什么我的令牌是空的?

    0 回复  |  直到 6 年前