zoukankan      html  css  js  c++  java
  • Spring Security Remember-Me

    引入POM

          <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
                <version>5.0.4.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-config</artifactId>
                <version>5.0.3.RELEASE</version>
            </dependency>
    

    html:

     <input type="checkbox" name="remember-me" checked value="true">
    

    配置:

    @Autowired  
    private DataSource dataSource;
    @Autowired
    private UserDetailService userDetailsService; @Override protected void configure(HttpSecurity http) throws Exception { http.rememberMe() .tokenRepository(persistentTokenRepository()) .userDetailsService(userDetailsService) //token "记住我"功能的token过期时间(秒) .tokenValiditySeconds(3600); }
    @Bean
    public PersistentTokenRepository persistentTokenRepository() { JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();        
        //第一次启动的时候需要手动创建Remember-Me的数据库表
        //jdbcTokenRepository.setCreateTableOnStartup(true);
        jdbcTokenRepository.setDataSource(dataSource); 

        return jdbcTokenRepository;
    }
  • 相关阅读:
    函数式编程
    scala 有 + 运算符吗?
    使用 Idea 打 scala程序的 jar 包
    相见恨晚的 scala
    半夜思考,为什么 String 具有不变性
    我的常用
    DataTable学习笔记
    Js 操作cookie
    嵌套的 ajax 请求
    Jquery插件收集【m了慢慢学】
  • 原文地址:https://www.cnblogs.com/cearnach/p/9090388.html
Copyright © 2011-2022 走看看