WebApplicationContext webApplicationContext = WebApplicationContextUtils
.getWebApplicationContext(sc);
AuthenticationManager authenticationManager = (AuthenticationManager) webApplicationContext
.getBean("authenticationManager");
RememberMeServices rememberMeServices = (RememberMeServices) webApplicationContext
.getBean("rememberMeServices");
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
accountid, "");
HttpSession session = request.getSession();
session.setAttribute("ACEGI_SECURITY_LAST_USERNAME", accountid);
WebAuthenticationDetails webdetails = new WebAuthenticationDetails(
request);
auth.setDetails(webdetails);
Authentication tauth = authenticationManager.authenticate(auth);
SecurityContextHolder.getContext().setAuthentication(tauth);
rememberMeServices.loginSuccess(request, response, tauth);
动态创建Authentication对象
最新推荐文章于 2024-10-16 18:54:04 发布
本文详细介绍了使用Spring Security框架进行用户认证的过程。包括从获取WebApplicationContext到设置RememberMeServices及AuthenticationManager,再到创建UsernamePasswordAuthenticationToken,最后完成登录验证及Remember-Me服务的成功调用。
9842

被折叠的 条评论
为什么被折叠?



