首页>代码>springboot+spring security通过内置方法rememberMe实现记住登录的实例>/hashing-remember-me/src/main/java/com/memorynotfound/spring/security/config/SecurityConfig.java
package com.memorynotfound.spring.security.config; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws Exception { web.ignoring() .antMatchers( "/js/**", "/css/**", "/img/**", "/webjars/**"); } @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and() .logout() .invalidateHttpSession(true) .clearAuthentication(true) .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .logoutSuccessUrl("/login?logout") .permitAll() .and() .rememberMe() .key("unique-and-secret") .rememberMeCookieName("remember-me-cookie-name") .tokenValiditySeconds(24 * 60 * 60); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser("zuidaima").password("111111").roles("USER"); } }


漫步的海星 LV4
2023年9月21日
lcqlcl LV11
2023年8月29日
ZhangZi123
2023年6月29日
暂无贡献等级
longyuan LV1
2023年6月27日
神龙摆尾无拘束 LV2
2023年3月17日
15578157792 LV7
2022年12月31日
80730176 LV7
2022年12月27日
zhenxingbei
2022年12月11日
暂无贡献等级
kevinxiao LV3
2022年12月7日
wwwwww1 LV12
2021年6月2日