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對象
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.