- UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(userName, password);
- Authentication authentication=this.getAuthenticationManager().authenticate(authRequest);
- SecurityContextHolder.getContext().setAuthentication(authentication);
以上三行代码,实现了使用acegi保护的应用在用户登录后的自动登录功能.
其中:this.getAuthenticationManager()是acegi中配置的认证管理器,需要注入.