BC4J JSP認証ログイン・ページの作成

プロバイダ・タイプがXMLで、BC4J Webアプリケーションでセキュリティを有効にする場合、HttpSessionコンテキストにユーザー資格証明をキャッシュするJSPページを作成できます。次のサンプルJSPページでは、HTML送信フォームを使用して、Webユーザーからの資格証明を問い合せます。

プロバイダ・タイプがLDAPの場合、OC4JとOracle9iAS JAASプロバイダを使用して、シングル・サインオン(SSO)とmod_ossoを統合します。この場合、BC4J JSPページを作成して、認証を提供することはできません。

注意: 次の例では、<jbo:ApplicationModule>データ・タグを更新して該当するアプリケーション・モジュールを参照し、<jsp:forward>タグを更新して該当する参照ページを参照する必要があります。



<%@ page contentType="text/html;charset=windows-1252"
    import="oracle.jbo.http.HttpContainer,oracle.jbo.JboContext"
%>
<%@ taglib uri="/webapp/DataTags.tld" prefix="jbo" %>
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
  <TITLE>Login</TITLE>
</HEAD>

<BODY>
  <%
  // If this is a post request then assume that it is the result
  // of a form submit. Attempt to login.
  if (request.getMethod().equalsIgnoreCase("POST"))
  {
     // Invalidate any previous "am" application SessionCookie
     // which may exist for this session.
     HttpContainer c = HttpContainer.getInstanceFromSession(session);
     c.setSessionCookie("am", null);

     // Cache the principal and credentials in the session.
     session.setAttribute(JboContext.SECURITY_PRINCIPAL, request.getParameter("username"));
     session.setAttribute(JboContext.SECURITY_CREDENTIALS, request.getParameter("password"));

     try
     {
  %>
        <!-- Use the ApplicationModule tag to force a connection attempt. -->
        <jbo:ApplicationModule
             id="am"
             configname="mypackage1.Mypackage1Module.Mypackage1ModuleLocal"
             releasemode="Stateful" />

        <!-- Immediately release the application module so that the release
         mode of this page does not interfere with the release mode of the
         page to which we are forwarding. The session cookie will remain
         authenticated, and since we are using pooling it should not consume
         significant CPU cycles in reacquiring an ApplicationModule instance.
         Stateful is also preferred because it does not incur additional
         cycles to reset the ApplicationModule state between this page and
         the page to which we are forwarding. -->
        <jbo:ReleasePageResources appid="am" />

        // If login is successful, then forward to the application entry point.
        <jsp:forward page="DeptView1_Browse.jsp" />
  <%
     }
     catch (oracle.jbo.JboException e)
     {
        // If login fails, then invalidate the session cookie that was
        // implicitly created by the ApplicationModule tag above.
        c.setSessionCookie("am", null);
  %>
        <h2>Login Failed. Please Try Again.</h2>
  <%
     }
  }
  %>
  <table width="300" border="0" cellspacing="2" cellpadding="2">
  <form method="post" action="Login.jsp" name="Login">
     <tr>
       <td align=right valign="middle"><span>Username&nbsp;&nbsp;</span>
       </td>
       <td align=left valign="top" colspan="2">
            <input name="username" size=15 maxlength="100">
</td> </tr> <tr> <td align=right valign="middle"><span>Password&nbsp;&nbsp;</span>
</td> <td align=left valign="top"> <input type=password name="password" size=15 maxlength="100">
</td> <td align="left" valign="middle" width="15%"> <input type="submit" value="Login"> </td> </tr> </form> </table> </BODY> </HTML>

送信時、JSPページは、資格証明をHttpSessionコンテキストにキャッシュします。次にJSPは、ApplicationModuleタグを宣言して、BC4Jで指定された資格証明を認証します。認証に失敗すると、ページには例外が表示されます。Webユーザーは、ここでもう一度資格証明を入力することができます。認証に成功すると、次のJSPページに進みます。この場合、サンプルのDeptView1_Browse.jspには、デフォルトのDEPT表の行が表示されます。


BC4Jクライアントでのセキュリティについて
Oracle9iAS JAASプロバイダの環境エントリについて
BC4J JSPログイン・ページについて

BC4J JSPクライアント用の認証の設定