记住我已经生成了cookie,但是当我重新打开浏览器访问网站时,我重新进入了登录界面。
Java8,win10 chrome,spring-boot 2.1.2.RELEASE,spring sercurity 5.1.3 RELEASE
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Resource(name = "MyUserDetailsServiceImpl")
private UserDetailsService userDetailsService;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/login", "/static/**", "/test").permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/main")
.failureUrl("/login?failed")
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/login?logout")
.and()
.rememberMe()
.rememberMeParameter("loginkeeping")
.key("yeaGem")
.and()
.csrf()
.disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
}
@Bean
@Override
protected UserDetailsService userDetailsService() {
return userDetailsService;
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
@Service("MyUserDetailsServiceImpl")
public class UserDetailsServiceImpl implements UserDetailsService {
@Resource
private PasswordEncoder passwordEncoder;
@Resource
private CheckersRespository checkersRespository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Checkers checker = checkersRespository.getChecker(username);
return new User(username, passwordEncoder.encode(checker.getPin()),
AuthorityUtils.commaSeparatedStringToAuthorityList(""));
}
}
这是我的问题https://github.com/spring-projects/spring-security/issues/6450 尽管已关闭,但该问题尚未解决。它包含两个简单的视频和错误重复视频。您可以在此链接中查看问题的详细信息。