tfc2005

BlogJava 首页 新随笔 联系 聚合 管理
  8 Posts :: 0 Stories :: 2 Comments :: 0 Trackbacks
    Authorization authToken = SkinUtils.getUserAuthorization(request, response);
调用类SkinUtils中的静态方法getUserAuthorization(request, response)以返回代表用户权限的对象,那么让我们来看看getUserAuthorization(request, response):

getUserAuthorization(request, response):

public static Authorization getUserAuthorization

           (HttpServletRequest request, HttpServletResponse response)

   {

       HttpSession session = request.getSession();

       // Check 1: check for the Jive authentication token in the user's session.

       Authorization authToken = (Authorization)session.getAttribute(JIVE_AUTH_TOKEN);

       if (authToken != null) {

           return authToken;

       }

       // Check 2: check the jive cookie for username and password

       Cookie cookie = getCookie(request, JIVE_AUTOLOGIN_COOKIE);

       if (cookie != null) {

           try {

               // at this point, we found a cookie so grab the username and

               // password from it, create an authorization token and store

               // that in the session

               String[] values = decodePasswordCookie(cookie.getValue());

               String username = values[0];

               String password = values[1];

               // Try to validate the user based on the info from the cookie.

               // Catch any exceptions

               authToken = AuthorizationFactory.getAuthorization(username,password);

           }

           catch (Exception e) {}

           // put that token in the user's session:

           if (authToken != null) {

               session.setAttribute(JIVE_AUTH_TOKEN, authToken);

           }

           // return the authorization token

           return authToken;

       }

       return null;

   }


getUserAuthorization(request, response)中,首先从request中取得session,检查目前用户的session中是否存在JIVE_AUTH_TOKEN”,如果存在的话直接返回Authorization的对象authToken。不存在的话也有可能注册用户刚刚打开浏览器进入论坛(此时的注册用户以前曾经选择将用户信息保存在cookie中),还没有初始化;也有可能是匿名用户登陆,所以接下来程序分别对这两种情况进行处理。先处理用户为注册用户刚刚登陆,程序通过方法getCookie()取得用户客户端存放的cookie,并用decodePasswordCookie()对其进行一些解码的处理,处理完成后取得用户的用户名和密码,将其交给AuthorizationFactory的静态方法getAuthorization()以判别用户是否存在,并产生相应的权限对象,在接下来的代码中通过

if (authToken != null) {

                session.setAttribute(JIVE_AUTH_TOKEN, authToken);

}

判断此时authToken是否为null,不是的话将authToken放入session中,便于程序以后直接从session中取得。那么接下来的处理匿名用户登陆就更简单了,由于匿名用户登陆后Authorization的对象authToken一路为空,并且方法的三次判断都和它不沾边,所以直接返回null


posted on 2005-06-15 13:04 佟福春 阅读(296) 评论(0)  编辑  收藏 所属分类: jive学习

只有注册用户登录后才能发表评论。


网站导航: