用于scala lift框架中的用户身份验证的示例

时间:2015-10-09 07:01:52

标签: scala lift

您好我是Lift框架的新手。

我想知道如何进行用户身份验证,就像我们以前在java servlet中所做的那样,我们用来检查用户是否已登录或重定向到登录页面。

我如何在电梯框架中做类似的事情?

以下是我在servlet过滤器中的示例代码,我想要一个等效的升力框架。

@Override
public void doFilter(ServletRequest req, ServletResponse res,
        FilterChain chain) throws IOException, ServletException {
        //This filter checks whether user has logged in if not redirect to him to single sign on page. 
        //If user has logged in already then we could get his information using Agent API

        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;

        Agent agent = new Agent(inputStream);
        String encodedSiteUrl = getUrl(request);
        request.getSession(true);

        Map<String,String> userInfo = agent.readToken(request); 

        if (userInfo != null) { //Check if used has logged in, if yes then get his id and save it in session
                String userid = (String)userInfo.get(Agent.TOKEN_SUBJECT);
                logger.info("Login Userid:" + userid);
                request.getSession().setAttribute("Username", userid);

         } else {//if user did not login the redirect to Single sign on page
                response.sendRedirect(ssoRediretURL + encodedSiteUrl);
         }

}

0 个答案:

没有答案