spring-security-demo icon indicating copy to clipboard operation
spring-security-demo copied to clipboard

只要请求没关闭,当前线程的任何地方都能注入HttpServletRequest

Open coderstory opened this issue 5 years ago • 0 comments
trafficstars

@Component public class myAuthenticationProvider extends DaoAuthenticationProvider { private HttpServletRequest request;

public myAuthenticationProvider(UserDetailsService userDetailsService, HttpServletRequest request, PasswordEncoder passwordEncoder) {
    this.request = request;
    // 注意是使用set
    this.setUserDetailsService(userDetailsService);
    this.setPasswordEncoder(passwordEncoder);
}

@Override
protected void additionalAuthenticationChecks(UserDetails userDetails,
                                              UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    super.additionalAuthenticationChecks(userDetails, authentication);
}

} 4.2章节里为什么搞得这么麻烦? P53页看的时候 就感觉不太对 不知道这些代码的内容是怎么来的。。。很多代码都是new对象而不是注入

coderstory avatar Dec 31 '19 11:12 coderstory