Liberty サーバーで提供されている com.ibm.wsspi.security.authorization.jacc.ProviderService インターフェースを実装することによって、Java™ Platform,
Enterprise Edition (J2EE) アプリケーションのカスタム許可決定を行う JACC プロバイダーを開発できます。
始める前に
デフォルトで、アプリケーション・モジュールのロードは、アプリケーションへの要求が処理されるようになるまで据え置かれます。ただし、アプリケーション内のモジュール全体のセキュリティー制約は、アプリケーションの処理が準備できる前に処理される必要があります。モジュールのロードの据え置きは無効にされる必要があります。以下に、無効にする方法を示します。
- Web コンテナーの場合:
server.xml ファイル内に以下のエレメントが設定される必要があります。
<webContainer deferServletLoad="false"/>
- EJB コンテナーの場合:
server.xml ファイル内に以下のプロパティーが設定される必要があります。
<ejbContainer startEJBsAtAppStart="true"/>
注: 上記のエレメントが設定されていない場合、サーバー開始時にサード・パーティー JACC プロバイダーにセキュリティー制約情報が完全には伝搬されない可能性があります。その結果、サード・パーティー JACC プロバイダーが正しい許可決定を行えなくなることがあります。
このタスクについて
Java Authorization Contract for Containers 仕様 JSR 115 は許可プロバイダー用のインターフェースを定義しています。Liberty サーバーで、JACC プロバイダーをユーザー・フィーチャーとしてパッケージする必要があります。そのフィーチャーは com.ibm.wsspi.security.authorization.jacc.ProviderService インターフェースを実装する必要があります。
手順
- com.ibm.wsspi.security.authorization.jacc.ProviderService インターフェースを実装するサービスを提供する OSGi コンポーネントを作成します。
ProviderService インターフェースは、2 つのメソッドを定義します。1 つは、getPolicy メソッドです。これは、Liberty ランタイムが、java.security.Policy 抽象クラスを実装する Policy クラスのインスタンスを取得するために呼び出すメソッドです。もう 1 つは getPolicyConfigFactory メソッドです。これは、Liberty ランタイムが、javax.security.jacc.PolicyConfigurationFactory 抽象クラスを実装する PolicyConfigurationFactory クラスのインスタンスを取得するために呼び出すメソッドです。
以下の例では、OSGi 宣言型サービスのアノテーションが使用されています。
package com.mycompany.jacc;
import com.mycompany.jacc.MyAuthConfigProvider;
import com.ibm.wsspi.security.authorization.jacc.ProviderService;
import java.security.Policy;
import java.util.Map;
import javax.security.jacc.PolicyConfigurationFactory;
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.Deactivate;
// The property value of javax.security.jacc.policy.provider which defines the implementation class of Policy and
// javax.security.jacc.PolicyConfigurationFactory.provider which defines the implementation class of PolicyConfigurationFactory, are required for propagating the properties to the Liberty runtime.
@Component(service = ProviderService.class,
immediate = true,
property = {
"javax.security.jacc.policy.provider=com.myco.jacc.MyPolicy",
"javax.security.jacc.PolicyConfigurationFactory.provider="
+ "com.myco.jacc.MyFactoryImpl"
}
)
public class MyJaccProviderService implements ProviderService {
Map<String, String> configProps;
// This method called by the Liberty runtime
// to get an instance of Policy class
@Override
public Policy getPolicy() {
return new myPolicy();
}
// This method called by the Liberty runtime
// to get an instance of PolicyConfigurationFactory class
@Override
public PolicyConfigurationFactory getPolicyConfigurationFactory() {
ClassLoader cl = null;
PolicyConfigurationFactory pcf = null;
System.setProperty(
"javax.security.jacc.PolicyConfigurationFactory.provider",
"com.myco.jacc.MyFactoryImpl");
try {
cl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(
this.getClass().getClassLoader());
pcf = PolicyConfigurationFactory.getPolicyConfigurationFactory();
} catch (Exception e) {
return null;
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
return pcf;
}
@Activate
protected void activate(ComponentContext cc) {
// Read provider config properties here if needed,
// then pass them to the Provider ctor.
// This example reads the properties from the OSGi
// component definition.
configProps = (Map<String, String>) cc.getProperties();
}
@Deactivate
protected void deactivate(ComponentContext cc) {}
}
- このコンポーネントを、ユーザー・フィーチャーの一部である OSGi バンドルに、JACC プロバイダーと一緒にパッケージします。
- フィーチャーには、OSGi サブシステム・コンテンツ com.ibm.ws.javaee.jacc.1.5; version="[1,1.0.100)"; location:="dev/api/spec/" を組み込むようにしてください。
- フィーチャーがユーザー製品拡張ロケーションにインストールされた後、
そのフィーチャー名を指定して server.xml ファイル
を構成します。以下に例を示します。
<featureManager>
...
<feature>usr:myJaccProvider</feature>
</featureManager>