// log user in automatically
Authentication auth = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getConfirmPassword());
try {
ApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(getSession().getServletContext());
if (ctx != null) {
ProviderManager authenticationManager = (ProviderManager) ctx.getBean("authenticationManager");
SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthentication(auth));
}
} catch (NoSuchBeanDefinitionException n) {
// ignore, should only happen when testing
}
会出现异常:org.acegisecurity.BadCredentialsException: Bad credentials
修改代码成如下,问题解决
Authentication auth = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getConfirmPassword());
Authentication auth = new UsernamePasswordAuthenticationToken(
account.getAccountName(), account.getPassword( ),account.getAuthorities() );
SecurityContextHolder.getContext().setAuthentication(auth);