SpringSecurity自动登录详解

前言

使用SpringSecurity管理用户的登录退出功能时,其底层就会按照SpringSecurity的机制进行会话的管理,有这么一种场景,登录的用户信息需要保留10天,这样的需求该怎么实现呢?

1、SpringSecurity登出功能

沿用之前的案例演示工程,只需要在config方法中做如下配置即可

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

        //登出配置
        http.logout().logoutUrl("/logout")
                .logoutSuccessUrl("/zcy/hello").permitAll();

        http.formLogin()
                .loginPage("/login.html")                       //自定义的登录界面
                .loginProcessingUrl("/user/login")              //登录提交的接口
                .defaultSuccessUrl("/zcy/index").permitAll()    //登录成功之后跳转的路径
                .and().authorizeRequests()
                .antMatchers("/","/zcy/hello","/user/login").permitAll()
                .anyRequest().authenticated()
                .and()
                .csrf()

猜你喜欢

转载自blog.csdn.net/zhangcongyi420/article/details/110704710