Web 認証用の Java Authentication and Authorization Service プログラミング・モデルの使用
WebSphere® Application Server では、Java™ Platform, Enterprise Edition (Java EE) 宣言セキュリティー・モデルをサポートしています。 Java EE デプロイメント記述子を使用して、認証およびアクセス制御ポリシーを定義できます。 カスタム・ログイン・モジュールをさらに積み重ね、WebSphere Application Server 認証メカニズムをカスタマイズできます。
始める前に
このタスクについて
Lightweight Third-Party Authentication (LTPA) メカニズムのシングル・サインオン (SSO) オプションが使用可能な場合、 Web クライアント・ログイン・セッションは、ログインの成功後、LTPA SSO トークン Cookie によりトラッキングされます。 ログアウト時には、このトークンは削除されてログイン・セッションは終了しますが、 サーバー・サイドのサブジェクトは削除されません。 宣言セキュリティー・モデルを使用する場合、WebSphere Application Server の Web コンテナーにより、クライアント認証およびログイン・セッション管理が自動的に実行されます。 Java EE セキュリティー制約なしでログイン・ページを設定し、最初にそのログイン・ページにクライアント要求を送信することにより、アプリケーション・コードで認証を実行できます。 ログイン・ページは、Java Authentication and Authorization Service (JAAS) プログラミング・モデルを使用して、認証を実行することができます。 WebSphere Application Server Web ログイン・モジュールを使用可能に設定し、SSO Cookie を生成するには、以下のステップを実行します。
手順
例
認証を実行するには、以下のコード例を使用してください。

Suppose you wrote a LoginServlet.java:
Import com.ibm.wsspi.security.auth.callback.WSCallbackHandlerFactory;
Import com.ibm.websphere.security.auth.WSSubject;
public Object login(HttpServletRequest req, HttpServletResponse res)
throws ServletException {
PrintWriter out = null;
try {
out = res.getWriter();
res.setContentType("text/html");
} catch (java.io.IOException e){
// Error handling
}
Subject subject = null;
try {
LoginContext lc = new LoginContext("system.Your_login_configuration",
WSCallbackHandlerFactory.getInstance().getCallbackHandler(
userid, null, password, req, res, null));
lc.login();
subject = lc.getSubject();
WSSubject.setRunAsSubject(subject);
} catch(Exception e) {
// catch all possible exceptions if you want or handle them separately
out.println("Exception in LoginContext login + Exception = " +
e.getMessage());
throw new ServletException(e.getMessage());
}
The following is sample code to revoke the SSO cookies upon a programming logout:
The LogoutServlet.java:
public void logout(HttpServletRequest req, HttpServletResponse res,
Object retCreds) throws ServletException {
PrintWriter out =null;
try {
out = res.getWriter();
res.setContentType("text/html");
} catch (java.io.IOException e){
// Error Handling
}
try {
WSSecurityHelper.revokeSSOCookies(req, res);
} catch(Exception e) {
// catch all possible exceptions if you want or handle them separately
out.println("JAASLogoutServlet: logout Exception = " + e.getMessage());
throw new ServletException(e);
}
}