Spring安全性:使用formLogin配置JWT

Spring安全性:使用formLogin配置JWT,spring,spring-security,Spring,Spring Security,我正在尝试使用formLogin身份验证配置JWT筛选器。 (我的服务器服务于UI客户端(这就是为什么我需要formLogin),我还公开了Rest端点(由JWT进行身份验证)。 目前我的JWT正在工作,但我的角色(anyRole)似乎不工作 以下是我的配置方法: 登录后->如果我试图到达/kuku路径-我得到302并再次登录页面 如果我在删除addFilterBefore->我的角色工作正常 protected void configure(HttpSecurity http) throws

我正在尝试使用formLogin身份验证配置JWT筛选器。 (我的服务器服务于UI客户端(这就是为什么我需要formLogin),我还公开了Rest端点(由JWT进行身份验证)。 目前我的JWT正在工作,但我的角色(anyRole)似乎不工作

以下是我的配置方法: 登录后->如果我试图到达/kuku路径-我得到302并再次登录页面

如果我在删除addFilterBefore->我的角色工作正常

protected void configure(HttpSecurity http) throws Exception {

    http.
            authorizeRequests()
            .antMatchers("/login").permitAll()
            .antMatchers("/").hasRole("ADMIN")
            .antMatchers("/kuku/**").hasRole("ADMIN")
            .anyRequest()
            .authenticated()
            .and()
            .formLogin().defaultSuccessUrl("/inital.html", true)
    ;


    http.addFilterBefore(new JwtFilter(), UsernamePasswordAuthenticationFilter.class);



    
        @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    String userName = "Admin"; // currently due to Vault IMPL - this  input is hardcoded .
    String password ="Admin"
    auth.inMemoryAuthentication()
            .withUser(userName).password(passwordEncoder().encode(password))
            .roles("ADMIN");
}
尝试将csrf().disable()添加到您的configure(http)方法中。这在我的配置与您的配置类似的情况下有效。不过,我建议搜索此配置是否安全,因为这会禁用内置的csrf保护