国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Petstore源碼追蹤記(3)-商業(yè)邏輯處理(三)

2019-11-18 16:21:47
字體:
供稿:網(wǎng)友

  圖10 編譯成功畫面

重新部署
如:build deploy

圖11 部署成功畫面

現(xiàn)在我們可開啟瀏覽器,依上述流程重新執(zhí)行一次,當(dāng)進(jìn)入http://localhost:8080/petstore/index.jsp,觀察RI Console秀出
登入頁、登入失敗頁之URL:

圖12 登入頁、登入失敗頁之URL

從首頁點(diǎn)選使用者帳號(hào)瀏覽頁,RI Console秀出目的頁URL及找出customer.do為保護(hù)頁:

圖13 目的頁URL及找出customer.do為保護(hù)頁

第二階段

登入畫面(signon.screen)可從screendefinitions_en_US.xml找出內(nèi)容對應(yīng)檔案為signon.jsp,它源碼位置在petstore_home/src/apps/petstore/src/docroot,開啟它請看約53列:

<waf:form  name="existingcustomer" action="j_signon_check" method="POST">
    <table cellpadding="5" cellspacing="0" border="0">
     <tr>
      <td class="petstore" align="center" colspan="2">
       <b>Yes.</b>
      </td>
     </tr>
     <tr>
      <td class="petstore_form" align="right">
       <b>User Name:</b>
      </td>
      <td class="petstore_form">
      <c:choose>
      <c:when  test="${cookie['bp_signon'] != null && cookie['bp_signon']
!=''}">
       <waf:input CSSClass="petstore_form"
                             type="text"
                              size="15"
                           name="j_username"
                    validation="validation">
       <waf:value><c:out value="${cookie['bp_signon'].value}"/></waf:value>
      </waf:input>
     </td>
    </tr>
    <tr>
以下略...

這是一個(gè)典型的Web-Form輸入畫面,使用了JSTL及Petstore自已寫的自訂卷標(biāo)(Custom Tag),這些卷標(biāo)的用法不是本文的討論重點(diǎn),請讀者自行參閱相關(guān)文件、書籍,我們將焦點(diǎn)放在流程上,請注意上述的程序片段粗體部份,使用者將帳號(hào)(User Name)及密碼(PassWord)輸入后按登入(Sign In)鈕,服務(wù)器(Web Server)會(huì)將request傳送給” j_signon_check”這個(gè)奇怪的URL,我們再回到SignOnFilter,在初始的變量宣告上,可找到這個(gè)URL,約70列:

public static final String FORM_SIGNON_URL = "j_signon_check";

在doFilter()函式可發(fā)現(xiàn)下列程序接收Request進(jìn)行驗(yàn)證,順便加上偵察程序代碼(Debug code),方便待會(huì)程序驗(yàn)證:

//判斷使用者從登入畫面(signon.screen)進(jìn)行驗(yàn)證工作
if ((targetURL != null) && targetURL.equals(FORM_SIGNON_URL)) {
  System.out.    validateSignOn(request, response, chain);
    // jump out of this method
    return;
}
接著在validateSignON()函式進(jìn)行使用者驗(yàn)證工作,從Request取出使用者輸入的字段值,若使用者有勾選Remember My UserName(記住我的帳號(hào))功能,則產(chǎn)生Cookie記錄使用者帳號(hào),再來透過EJB tier從數(shù)據(jù)庫讀取資料進(jìn)行比對,驗(yàn)證成功則將使用者帳號(hào)(USER_NAME)及是否已登入(SIGNED_ON_USER)參數(shù)存入session,從Request取出目的URL(ORIGINAL_URL),將網(wǎng)頁轉(zhuǎn)導(dǎo)就會(huì)到達(dá)我們的目的地-使用者基本資料瀏覽畫面(customer.do)
;若驗(yàn)證有誤則將網(wǎng)頁轉(zhuǎn)導(dǎo)到登入失敗畫面(signon_error.screen)
,請讀者順便加上偵察程序代碼。


public  void validateSignOn(ServletRequest request, ServletResponse  response,
FilterChain chain) throws IOException, ServletException {
        //從Request取出使用者輸入的字段值
        // convert to a http servlet request for now
        HttpServletRequest hreq = (HttpServletRequest)request;
        HttpServletResponse hres = (HttpServletResponse)response;
        // get the user name
        String userName = hreq.getParameter(FORM_USER_NAME);
        // get the password
        String password = hreq.getParameter(FORM_PASSWORD);
        // check if the user wants userName set in cookie
        String rememberUserName =
     hreq.getParameter(REMEMBER_USERNAME);
        //若使用者有勾選Remember My User Name(記住我的帳號(hào))功能,則產(chǎn)生Cookie記錄使用者帳號(hào)
        if (rememberUserName != null) {
          // set a cookie with the username in it
          Cookie userNameCookie = new Cookie(COOKIE_NAME, userName);
          // set cookie to last for one month
          userNameCookie.setMaxAge(2678400);
          hres.addCookie(userNameCookie);
        } else {
            // see if the cookie exists and remove accordingly
            Cookie[] cookies = hreq.getCookies();
            if (cookies != null) {
                for (int loop=0; loop < cookies.length; loop++) {
                    if (cookies[loop].getName().equals(COOKIE_NAME)) {
                        cookies[loop].setMaxAge(0);
                        hres.addCookie(cookies[loop]);

                    }
                }
            }
        }
        //透過EJB從數(shù)據(jù)庫讀取資料進(jìn)行比對
        //validate against the registered users
        SignOnLocal signOn = getSignOnEjb();
    //請加入偵察程序代碼,方便稍候程序驗(yàn)證
    System.out.println("進(jìn)行EJB tier使用者驗(yàn)證");
        //帳號(hào)及密碼驗(yàn)證
        boolean authenticated = signOn.authenticate(userName, password);
        if (authenticated) {
            //驗(yàn)證成功則將使用者帳號(hào)(USER_NAME)及是否已登入(SIGNED_ON_USER)參數(shù)
存入Session
            // place a true boolean in the session
            if (hreq.getSession().getAttribute(USER_NAME) !
= null) {
                hreq.getSession().removeAttribute(USER_NAME);
            }
            hreq.getSession().setAttribute(USER_NAME, userName);
            // remove the sign on user key before putting it back in
            if (hreq.getSession().getAttribute(SIGNED_ON_USER) != null) {
                hreq.getSession().removeAttribute(SIGNED_ON_USER);
            }
            hreq.getSession().setAttribute(SIGNED_ON_USER, new Boolean(true));
//將網(wǎng)頁轉(zhuǎn)導(dǎo)就會(huì)到達(dá)我們的目的地-使用者基本資料瀏覽畫面(customer.do)
            // redirect to the original destination
            String targetURL =
(String)hreq.getSession().getAttribute(ORIGINAL_URL);
            hres.sendRedirect(targetURL);
            return;
        } else {
      //若驗(yàn)證有誤則將網(wǎng)頁轉(zhuǎn)導(dǎo)到登入失敗畫面(signon_error.screen)
            hres.sendRedirect(signOnErrorPage);
            return;
        }
     }

     //取得SignOn Local Stateless Session Bean Reference
     private SignOnLocal getSignOnEjb() throws ServletException {
         SignOnLocal signOn = null;
         try {
            InitialContext ic = new InitialContext();
            Object o = ic.lookup("java:comp/env/ejb/local/SignOn");
            SignOnLocalHome home =(SignOnLocalHome)o;
            signOn = home.create();
         } catch (javax.ejb.CreateException cx) {
             throw new ServletException("Failed to Create SignOn EJB: caught "
+ cx);

         } catch (javax.naming.NamingException nx) {
             throw new ServletException("Failed to Create SignOn EJB: caught "
+ nx);
        }
        return signOn;
     }

Object o = ic.lookup("java:comp/env/ejb/local/SignOn");

透過上述程序代碼可追縱SignOnEJB相關(guān)信息:

(出處:http://m.survivalescaperooms.com)



發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桐梓县| 昌宁县| 两当县| 台中市| 宁化县| 漳平市| 桑日县| 延安市| 奉贤区| 元江| 柳江县| 紫阳县| 太谷县| 龙游县| 太和县| 桑植县| 金沙县| 广州市| 嵩明县| 沙坪坝区| 满城县| 沂南县| 蕉岭县| 灌阳县| 永嘉县| 通州市| 定边县| 台南市| 双辽市| 大连市| 南漳县| 霍邱县| 阿荣旗| 彝良县| 阜城县| 岳普湖县| 车险| 玛多县| 张家口市| 北票市| 竹溪县|