欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

动态创建Authentication对象 博客分类: 原创 AcegiSecurity

程序员文章站 2024-03-19 19:52:58
...

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

相关标签: Acegi Security