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

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 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?
  • ¥15 如何自动更换布娃娃图片上的衣服
  • ¥15 心理学eprime编程