解决AppFuse 1.9.4 中的自动登录Bug [原创]

        // 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);

 

 

你可能感兴趣的:(Appfuse)