この資料は、ログイン・モジュールからサブジェクトへのオブジェクトの追加方法を説明し、確実に Java オブジェクトが伝搬されるように、他のインフラストラクチャーの考慮事項を説明します。
public customLoginModule() { public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { } public boolean login() throws LoginException { // Construct callback for the WSTokenHolderCallback so that you // can determine if // your custom object has propagated Callback callbacks[] = new Callback[1]; callbacks[0] = new WSTokenHolderCallback("Authz Token List: "); try { _callbackHandler.handle(callbacks); } catch (Exception e) { throw new LoginException (e.getLocalizedMessage()); } // Checks to see if any information is propagated into this login List authzTokenList = ((WSTokenHolderCallback) callbacks[1]).getTokenHolderList(); if (authzTokenList != null) { for (int i = 0; i< authzTokenList.size(); i++) { TokenHolder tokenHolder = (TokenHolder)authzTokenList.get(i); // Look for your custom object. Make sure you use // "startsWith"because there is some data appended // to the end of the name indicating in which Subject // Set it belongs. Example from getName(): // "com.acme.CustomObject (1)". The class name is // generated at the sending side by calling the // object.getClass().getName() method. If this object // is deserialized by WebSphere Application Server, // then return it and you do not need to add it here. // Otherwise, you can add it below. // Note: If your class appears in this list and does // not use custom serialization (for example, an // implementation of the Token interface described in // the Propagation Token Framework), then WebSphere // Application Server automatically deserializes the // Java object for you. You might just return here if // it is found in the list. if (tokenHolder.getName().startsWith("com.acme.CustomObject")) return true; } } // If you get to this point, then your custom object has not propagated myCustomObject = new com.acme.CustomObject(); myCustomObject.put("mykey", "mydata"); } public boolean commit() throws LoginException { try { // Assigns a reference to a final variable so it can be used in // the doPrivileged block final com.acme.CustomObject myCustomObjectFinal = myCustomObject; // Prevents your applications from needing a JAAS getPrivateCredential // permission. java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction() { public Object run() throws java.lang.Exception { // Try not to add a null object to the Subject or an object // that already exists. if (myCustomObjectFinal != null && !subject.getPrivateCredentials().contains(myCustomObjectFinal)) { // This call requires a special Java 2 Security permission, // see the JAAS application programming interface (API) // documentation. subject.getPrivateCredentials().add(myCustomObjectFinal); } return null; } }); } catch (java.security.PrivilegedActionException e) { // Wraps the exception in a WSLoginFailedException java.lang.Throwable myException = e.getException(); throw new WSLoginFailedException (myException.getMessage(), myException); } } // Defines your login module variables com.acme.CustomObject myCustomObject = null; }
カスタム・オブジェクトの追加に慎重で、すべてのステップに従い、WebSphere Application Server が各ホップでオブジェクトをシリアライズおよびデシリアライズできることを確認している場合、 カスタム Java オブジェクトのみの使用で十分です。
カスタム・オブジェクトをサブジェクトに追加し、
WebSphere Application Server がオブジェクトを伝搬することを期待している場合、
そのカスタム・オブジェクトのクラス定義が、シリアライゼーションまたはデシリアライゼーションが
起こる可能性があるすべてのノード上の install_root/classes ディレクトリー
にあることを確認します。また、
Java クラス・バージョンが同じであることを検証します。
カスタム・オブジェクトをサブジェクトに追加し、
WebSphere Application Server がオブジェクトを伝搬することを期待している場合、
そのカスタム・オブジェクトのクラス定義が、シリアライゼーションまたはデシリアライゼーションが
起こる可能性があるすべてのノード上の profile_root/classes ディレクトリー
にあることを確認します。また、
Java クラス・バージョンが同じであることを検証します。
伝搬除外リストにカスタム・オブジェクトを追加することができますが、 副次作用に気を付ける必要があります。 WebSphere Application Server は、シングル・サインオン (SSO) トークンの 存続期間にローカル・キャッシュで不透明なトークン、またはシリアライズされたサブジェクト内容を保管します。 SSO トークンの存続期間 (デフォルトでは 2 時間) は、管理コンソールの SSO プロパティーで構成されます。 不透明なトークンに追加される情報は、除外リストにないオブジェクトのみを含みます。
認証キャッシュが SSO トークン・タイムアウトに一致していない場合は、認証キャッシュ・プロパティーを構成してください。 認証キャッシュの構成 を参照してください。認証キャッシュ・タイムアウト値を SSO トークン・タイムアウトと同じにすることをお勧めします。