customPasswordEncryption プロバイダーの開発
Liberty サーバーで提供される com.ibm.wsspi.security.crypto.CustomPasswordEncryption インターフェースを実装することで、Java™ Platform, Enterprise Edition (J2EE) アプリケーションにカスタム許可決定を行うように customPasswordEncryption プロバイダーを開発することができます。
このタスクについて
注: 以下のオプションのステップは、コマンド・ライン・ユーティリティーをサポートするためのものです。プロバイダーの目的がサーバー・ランタイム環境のサポートのみであれば、これらのステップはスキップして構いません。
customPassworedEncryption プロバイダーは、次の 3 つのファイルで構成されます。
- OSGi バンドル・ファイル。実行可能プログラムが含まれます。
- フィーチャー・マニフェスト・ファイル。customPasswordEncryption プロバイダーのユーザー・フィーチャーを定義します。このファイルには、必須バンドルのロケーションとフィーチャーの属性、および (パッケージ化する場合は) 拡張マニフェスト・ファイルが含まれます。この情報はサーバーのランタイムが使用します。
- 拡張マニフェスト・ファイル。customPasswordEncryption プロバイダーの必須バンドル・ファイルと実装クラス名を定義します。このファイルはオプションであり、コマンド・ライン・ユーティリティーをサポートする上では必須です。
手順
- com.ibm.wsspi.security.crypto.CustomPasswordEncryption インターフェースを実装するサービスを提供する OSGi コンポーネントを作成します。
CustomPasswordEncryption インターフェースでは、3 つのメソッドが定義されています。 それらは、ストリングの暗号化解除のために Liberty サーバー・ランタイムが呼び出す decrypt、 ストリングの暗号化のために Liberty サーバー・ランタイムが呼び出す encrypt、 将来の使用のために予約された initialize です。
以下の例では、OSGi 宣言型サービスのアノテーションが使用されています。package com.mycompany.custom; import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.ConfigurationPolicy; import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Modified; import com.ibm.wsspi.security.crypto.CustomPasswordEncryption; import com.ibm.wsspi.security.crypto.EncryptedInfo; import com.ibm.wsspi.security.crypto.PasswordDecryptException; import com.ibm.wsspi.security.crypto.PasswordEncryptException; /** */ @Component(service = CustomPasswordEncryption.class, immediate = true, name = "com.mycompany.CustomPasswordEncryptionImpl", configurationPolicy = ConfigurationPolicy.OPTIONAL, property = { "someKey=someValue" }) public class CustomPasswordEncryptionImpl implements CustomPasswordEncryption { @Activate protected synchronized void activate(ComponentContext cc, Map<String, Object> props) { } @Modified protected synchronized void modify(Map<String, Object> props) { } @Deactivate protected void deactivate(ComponentContext cc) { } /** * The encrypt operation takes a UTF-8 encoded String in the form of a byte[]. * The byte[] is generated from String.getBytes("UTF-8"). An encrypted byte[] * is returned from the implementation in the EncryptedInfo object. * Additionally, a logically key alias is returned in EncryptedInfo so which * is passed back into the decrypt method to determine which key was used to * encrypt this password. The WebSphere Application Server runtime has no * knowledge of the algorithm or key used to encrypt the data. * * @param decrypted_bytes * @return com.ibm.wsspi.security.crypto.EncryptedInfo * @throws com.ibm.wsspi.security.crypto.PasswordEncryptException **/ @Override public EncryptedInfo encrypt(byte[] input) throws PasswordEncryptException { byte[] output = null; String key = null; try { : <do some encryption> : return new EncryptedInfo(output, key); } catch (Exception e) { throw new PasswordEncryptException("Exception is caught", e); } } /** * The decrypt operation takes the EncryptedInfo object containing a byte[] * and the logical key alias and converts it to the decrypted byte[]. The * WebSphere Application Server runtime will convert the byte[] to a String * using new String (byte[], "UTF-8"); * * @param info * @return byte[] * @throws PasswordEncryptException * @throws com.ibm.wsspi.security.crypto.PasswordDecryptException **/ @Override public byte[] decrypt(EncryptedInfo info) throws PasswordDecryptException { byte[] input = info.getEncryptedBytes(); String key = info.getKeyAlias(); byte[] output = null; try { : <do some decryption> : return output; } catch (Exception e) { throw new PasswordEncryptException("Exception is caught", e); } } /** * This is reserved for future use and is currently not called by the * WebSphere Application Server runtime. * * @param initialization_data **/ @SuppressWarnings("rawtypes") @Override public void initialize(Map initialization_data) {} }
- このコンポーネントを、ユーザー・フィーチャーの一部である OSGi バンドルにパッケージします。バンドルに OSGi サービス・マニフェストが含まれていることを確認してください。 以下の例は、OSGi サービス・マニフェストのコンテンツを示しています。
<?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.mycompany.custom.CustomPasswordEncryptionImpl" configuration-policy="optional" immediate="true" activate="activate" deactivate="deactivate" modified="modify"> <implementation class="com.mycompany.custom.CusomPasswordEncryptionImpl"/> <service> <provide interface="com.ibm.wsspi.security.crypto.CustomPasswordEncryption"/> </service> <property name="<someKey>" type="String" value="<someValue>"/> </scr:component>
- フィーチャー・マニフェスト・ファイルには、start-phase:="SERVICE_EARLY" を使用して OSGi サブシステム・コンテンツを必ず組み込んでください。このオプションのステップが完了すると、拡張マニフェスト・ファイルのロケーションが Subsystem-Content ヘッダー内に配置されます。 以下に例を示します。
Manifest-Version: 1.0 IBM-Feature-Version: 2 IBM-ShortName: customPasswordEncryption-1.0 Subsystem-Type: osgi.subsystem.feature Subsystem-Version: 1.0.0 Subsystem-ManifestVersion: 1.0 Subsystem-SymbolicName: customPasswordEncryption-1.0;visibility:=public Subsystem-Content: com.mycompany.custom; version="[1,1.0.100)"; start-phase:="SERVICE_EARLY", customEncryption.jar; type=file; \ location:="bin/tools/extensions/ws-customPasswordEncryption/customEncryption.jar” Subsystem-Description: MyCompany custom password encryption
- フィーチャーがユーザー製品拡張ロケーションにインストールされた後、
そのフィーチャー名を指定して server.xml ファイル
を構成します。
<featureManager> ... <feature>usr:customPasswordEncryption-1.0</feature> </featureManager>
サーバー・ランタイム環境用にインストールが正常終了したことを検証するため、 CWWKS1850I メッセージが message.log ファイルに記録されていることを確認します。
- オプション: 拡張マニフェスト・ファイルを作成します。このファイルは、customPasswordEncryption プロバイダーを SecurityUtility などのコマンド・ライン・ユーティリティーにプラグインするために必要です。拡張マニフェスト・ファイルは MANIFEST.MF ファイルを含む JAR ファイルです。拡張マニフェストの必須ヘッダーは次のとおりです。
- Require-Bundle: ロードされる必要のあるバンドルのリストを定義します。形式は、OSGi バンドルのマニフェスト・ファイルと同じです。
- IBM-ImplementationClass: com.ibm.wsspi.security.crypto.CustomPasswordEncryption インターフェースを実装した実装クラスを定義します。
以下に MANIFEST.MF のサンプル・ファイルを示します。
Require-Bundle: com.mycompany.custom; version="[1,1.0.100)"; location="usr/extension/lib" IBM-ImplementationClass: com.mycompany.custom.CusomPasswordEncryptionImpl
jar コマンドを使用して拡張マニフェスト・ファイルをパッケージ化します。以下に例を示します。jar cfm customEncryption.jar MANIFEST.MF
JAR ファイルを wlp/bin/tools/extensions/ws-customPasswordEncryption に配置します。 拡張マニフェスト・ファイルのロケーションが、フィーチャーのマニフェスト・ファイルの Subsystem-Content ヘッダー・セクション内にあることを確認します。
これらのファイルは、特定のディレクトリーにある必要があります。これらのファイルの関係を以下に示します。図 1. customPassworedEncryption プロバイダー・ファイル - オプション: ステップ 5 を完了した後、次のコマンド・ライン・ユーティリティー・コマンドを使用して、インストールが正常であったことを検証できます。
wlp/bin/securityUtility encode --listCustom
予期される出力は customPasswordEncryption の情報です。以下に例を示します。[{"name":"custom","featurename":"usr:customPasswordEncryption-1.0","description":"MyCompany custom password encryption"}]
必要なファイルがすべて存在し、それらのファイルの内容が正確であることを確認します。

ファイル名: twlp_developing_custom_passwd_encrypt.html