动态创建Authentication对象 博客分类: 原创 AcegiSecurity
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);