雨随落花 2019-04-11 20:15 采纳率: 100%
浏览 2920
已采纳

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";
    }

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

  • 写回答

4条回答 默认 最新

  • 雨随落花 2019-04-12 10:47
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法