動態創建Authentication對象

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

發佈了22 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章