栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring Security03--自定义登录页面、接口、参数、记住我等功能

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Security03--自定义登录页面、接口、参数、记住我等功能

上一篇:https://blog.csdn.net/fengxianaa/article/details/124697101

5. 自定义登录页面

1. 准备登陆页面

static.zip地址:springsecurity学习使用的静态文件-Java文档类资源-CSDN下载

这个 static.zip 解压后是这样子的

里面的 login.html 就是我们的登陆页面

把 static 文件夹复制到 项目中的 resource 文件夹下

2. 修改 SecurityConfig

让 SecurityConfig 继承 WebSecurityConfigurerAdapter

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    
    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }
    @Override
    public void configure(WebSecurity web) throws Exception {
        // 静态资源不用验证
        web.ignoring().antMatchers("/js
@Bean
public JdbcTokenRepositoryImpl jdbcTokenRepositoryImpl() {
    JdbcTokenRepositoryImpl persistentTokenRepository = new JdbcTokenRepositoryImpl();
    persistentTokenRepository.setDataSource(dataSource);
    return persistentTokenRepository;
}
//configure 方法 增加
http.rememberMe()
    .tokenRepository(jdbcTokenRepositoryImpl()) // 配置token持久化仓库
    // .tokenValiditySeconds(3600) // 过期时间,单位为秒
    .userDetailsService(loginUserService); // 处理自动登录逻辑

登录成功后,数据库中的token

这样关闭浏览器后,再次访问就不用登录了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/877286.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号