このトピックは、CORBA ベースのプログラマチック・ログイン API を用いたプログラマチック・ログインの実行方法の例として使用します。
Common Object Request Broker Architecture (CORBA) アプリケーション・プログラミング・インターフェース (API) は、WebSphere Application Server for z/OS 環境ではサポートされません。 他の WebSphere Application Server 製品から WebSphere Application Server for z/OS へ移植するアプリケーションがある場合、セキュリティー API は、バージョン 6.0.x では非推奨であることに注意してください。 これらのアプリケーションを WebSphere Application Server for z/OS バージョン 6.0.x で使用する場合、Java Authentication and Authorization Service (JAAS) へのマイグレーションを行う必要があります。
WebSphere Application Server で提供される API は、標準 JAAS API と標準 JAAS インターフェースの製品インプリメンテーションの組み合わせです。
WebSphere Application Server for z/OS で提供されるサポート API は、 標準 JAAS API と、一部のマイナーな拡張機能を含む標準 JAAS インターフェースの製品インプリメンテーションの 組み合わせです。
次に示すのは要約のみです。 詳しくは、ご使用のプラットフォーム用の JAAS 資料 (http://www.ibm.com/developerworks/java/jdk/security/) を参照してください。
WebSphere Application Server は、クライアントおよび サーバー・サイド・ログインに LoginModules インプリメンテーションを提供します。詳しくは、 Java Authentication and Authorization Service のプログラマチック・ログインの構成 を参照してください。
アプリケーションは、WebSphere Application Server ログイン・モジュールの 明示的な呼び出しにより生成される対象を使用して、J2EE リソース・アクセスのための WSSubject.doAs メソッドを呼び出す必要があります。
以下の例では、アプリケーション・コードが、必須の Java 2 セキュリティー許可を与えられているものと想定します。詳しくは、Java Authentication and Authorization Service のプログラマチック・ログインの構成 、 システム・リソースおよび API の保護 (Java 2 セキュリティー) 、 および http://www.ibm.com/developerworks/java/jdk/security/ にある、JAAS の資料を参照してください。
public class TestClient { ... private void performLogin() { // Create a new JAAS LoginContext. javax.security.auth.login.LoginContext lc = null; try { // Use GUI prompt to gather the BasicAuth data. lc = new javax.security.auth.login.LoginContext("WSLogin", new com.ibm.websphere.security.auth.callback.WSGUICallbackHandlerImpl()); // create a LoginContext and specify a CallbackHandler implementation // CallbackHandler implementation determine how authentication data is collected // in this case, the authentication date is collected by login prompt // and pass to the authentication mechanism implemented by the LoginModule. } catch (javax.security.auth.login.LoginException e) { System.err.println("ERROR: failed to instantiate a LoginContext and the exception: " + e.getMessage()); e.printStackTrace(); // may be javax.security.auth.AuthPermission "createLoginContext" is not granted // to the application, or the JAAS Login Configuration is not defined. } if (lc != null) try { lc.login(); // perform login javax.security.auth.Subject s = lc.getSubject(); // get the authenticated subject // Invoke a J2EE resources using the authenticated subject com.ibm.websphere.security.auth.WSSubject.doAs(s, new java.security.PrivilegedAction() { public Object run() { try { bankAccount.deposit(100.00); // where bankAccount is an protected EJB } catch (Exception e) { System.out.println("ERROR: error while accessing EJB resource, exception: " + e.getMessage()); e.printStackTrace(); } return null; } } ); // Retrieve the name of the principal from the Subject // so we can tell the user that login succeeded, // should only be one WSPrincipal. java.util.Set ps = s.getPrincipals(com.ibm.websphere.security.auth.WSPrincipal.class); java.util.Iterator it = ps.iterator(); while (it.hasNext()) { com.ibm.websphere.security.auth.WSPrincipal p = (com.ibm.websphere.security.auth.WSPrincipal) it.next(); System.out.println("Principal: " + p.getName()); } } catch (javax.security.auth.login.LoginException e) { System.err.println("ERROR: login failed with exception: " + e.getMessage()); e.printStackTrace(); // login failed, might want to provide relogin logic } } ... }