SpringBoot+Security登出无法跳转指定页面

使用SpringBoot 2.1.3 +SpringSecurity,按照网上教程设置logoutSuccessUrl为跳转的index路径,但是无法正常跳转,根据查看,页面发起请求/logout随后转向/index,但又被重定向至/login,截图如下
图片说明
WebSecurityConfig配置如下

@Override
    protected void configure(HttpSecurity http) throws Exception {
        //允许基于HttpServletRequest使用限制访问
        http.authorizeRequests()
                //不需要身份验证
                .antMatchers("/js/**","/css/**","**/images/**","/fonts/**","/doc/**","/static/**").permitAll()
                .antMatchers("/login.html","/login").permitAll()
                .antMatchers("/index","/","/index.html").permitAll()
                .antMatchers("/register/**","/register.html").permitAll()
                .antMatchers("/developer_center/**","/price_list/**").permitAll()
                .antMatchers("/contact","/contact.html").permitAll()
                .anyRequest().authenticated()
                //自定义登陆界面
                .and().formLogin()
                .loginPage("/login").permitAll()
                .loginProcessingUrl("/login")
                .failureUrl("/login?error=1")
                .permitAll().defaultSuccessUrl("/index")
                .and().logout().logoutUrl("/logout").logoutSuccessUrl("/index")
                .and().headers().frameOptions().disable()
                .and().exceptionHandling().accessDeniedPage("/login")
                .and().httpBasic()
                .and().sessionManagement().invalidSessionUrl("/login")
                .and().rememberMe()
                .and().csrf().disable();
    }

Controller中的Index请求如下:

@RequestMapping(value = {"index",""},method = RequestMethod.GET)
    public String getIndexHTML(HttpServletRequest httpServletRequest){
        HttpSession httpSession = httpServletRequest.getSession(true);
        if (httpSession.getAttribute("company_email")==null){
            httpSession.setAttribute("company_serial_number",companyConfig.getSerial_number());
            httpSession.setAttribute("company_email",companyConfig.getEmail());
        }
        if(iAuthenticationFacade.getAuthentication().getName()!="anonymousUser") {
                httpSession.setAttribute("flag",1);
                httpSession.setAttribute("userinfo",userMapper.findByLoginName(iAuthenticationFacade.getAuthentication().getName()));
        }
        else
            httpSession.setAttribute("flag",0);
        return "index";
    }

跪求高人指点一二,谢谢!

我知道了。。。logout以后会失效session然后走到invalidSessionUrl也就是/login

你index 不是需要登录才能进去吗

今天出现与你一样的问题。仔细看了,才发现是 /logout 没有授权,所以 /logout 时,就跳转到 /login 页面中去了。
处理方法1:在 .antMatchers("/login.html","/login").permitAll() 中,添加 一个 “/logout" 就可以了。
处理方法2:在 .and().logout().logoutUrl("/logout").logoutSuccessUrl("/index") 后面不回一个 .permitAll() 也可以。

//授权
@Override
protected void configure(HttpSecurity http) throws Exception {

    //首页所有可用访问,功能页只能有对应权限的人才能访问
    http.authorizeRequests()
                .antMatchers("/","/logout").permitAll()
                .antMatchers("/level1/**").hasRole("vip1")
                .antMatchers("/level2/**").hasRole("vip2")
                .antMatchers("/level3/**").hasRole("vip3");

    //没有权限默认到登录页面
    http.formLogin()
                .loginPage("/usr/login").permitAll();

            //开启注销功能
    http.logout().logoutUrl("/logout").logoutSuccessUrl("/index").permitAll();
}

我的授权了还是不能登出???,有人知道啥原因嘛?

注销 这是注销按钮的