この章では、カスタム・アサーションの作成方法を説明します。この章の内容は次のとおりです。
「事前定義済アサーション・テンプレート」に定義されている事前定義済アサーション・テンプレートがニーズに一致しない場合は、独自のカスタム・アサーションを作成できます。
カスタム・アサーションを作成するには、次のファイルを作成する必要があります。
カスタム・アサーション・クラス: Javaクラスとその解析および強制ロジックを実装します。
カスタム・ポリシー・ファイル: カスタム・アサーションのバインディングの定義と構成ができます。
policy-config.xmlファイル: カスタム・ポリシー・ファイルを登録します。
アサーション・クラスとpolicy-config.xmlファイルをJARファイルとしてパッケージ化し、JARファイルをドメインのCLASSPATHで使用できるようにします。その後、必要に応じて、カスタム・ポリシー・ファイルをインポートしてWebサービスまたはクライアントに添付します。
次の項では、プロセスの各手順を説明します。
カスタム・アサーション・クラスを作成し、ポリシー・アサーションのロジックを実行および検証します。カスタム・アサーション・クラスはoracle.wsm.policyengine.impl.AssertionExecutor
を拡張している必要があります。
カスタム・アサーション・クラスを作成する際に、wsm-policy-core.jarとwsm-agent-core.jarのJARファイルがCLASSPATHに含まれていることを確認します。
次の例に、リクエストのIPアドレスを検証するために使用できるカスタム・アサーション・エグゼキュータを示します。リクエストのIPアドレスが無効の場合は、FAULT_FAILED_CHECK
例外がスローされます。
独自のカスタム・アサーション・クラスの開発に使用できるAPIの詳細は、『Java API Reference for Oracle Web Services Manager』を参照してください。
例14-1 カスタム・アサーション・クラスの例
package sampleassertion; import oracle.wsm.common.sdk.IContext; import oracle.wsm.common.sdk.IMessageContext; import oracle.wsm.common.sdk.IResult; import oracle.wsm.common.sdk.Result; import oracle.wsm.common.sdk.WSMException; import oracle.wsm.policy.model.IAssertionBindings; import oracle.wsm.policy.model.IConfig; import oracle.wsm.policy.model.IPropertySet; import oracle.wsm.policy.model.ISimpleOracleAssertion; import oracle.wsm.policy.model.impl.SimpleAssertion; import oracle.wsm.policyengine.impl.AssertionExecutor; public class IpAssertionExecutor extends AssertionExecutor { public IpAssertionExecutor() { } public void destroy() { } public void init(oracle.wsm.policy.model.IAssertion assertion, oracle.wsm.policyengine.IExecutionContext econtext, oracle.wsm.common.sdk.IContext context) { this.assertion = assertion; this.econtext = econtext; } public oracle.wsm.policyengine.IExecutionContext getExecutionContext() { return this.econtext; } public boolean isAssertionEnabled() { return ((ISimpleOracleAssertion)this.assertion).isEnforced(); } public String getAssertionName() { return this.assertion.getQName().toString(); } /** * @param context * @return */ public IResult execute(IContext context) throws WSMException { try { IAssertionBindings bindings = ((SimpleAssertion)(this.assertion)).getBindings(); IConfig config = bindings.getConfigs().get(0); IPropertySet propertyset = config.getPropertySets().get(0); String valid_ips = propertyset.getPropertyByName("valid_ips").getValue(); String ipAddr = ((IMessageContext)context).getRemoteAddr(); IResult result = new Result(); if (valid_ips != null && valid_ips.trim().length() > 0) { String[] valid_ips_array = valid_ips.split(","); boolean isPresent = false; for (String valid_ip : valid_ips_array) { if (ipAddr.equals(valid_ip.trim())) { isPresent = true; } } if (isPresent) { result.setStatus(IResult.SUCCEEDED); } else { result.setStatus(IResult.FAILED); result.setFault(new WSMException(WSMException.FAULT_FAILED_CHECK)); } } else { result.setStatus(IResult.SUCCEEDED); } return result; } catch (Exception e) { throw new WSMException(WSMException.FAULT_FAILED_CHECK, e); } } public oracle.wsm.common.sdk.IResult postExecute(oracle.wsm.common.sdk.IContext p1) { IResult result = new Result(); result.setStatus(IResult.SUCCEEDED); return result; } }
カスタム・ポリシー・ファイルを作成し、カスタム・アサーションのバインディングを定義して構成します。「カスタム・アサーションのスキーマ参照」で、カスタム・ポリシー・ファイルとカスタム・アサーションの作成に使用できるスキーマについて説明します。
次の例では、oracle/ip_assertion_policyカスタム・ポリシー・ファイルが定義されます。アサーションは、リクエストに対して有効なIPアドレスのカンマ区切りのリストを定義します。
例14-2 カスタム・ポリシー・ファイルの例
<?xml version = '1.0' encoding = 'UTF-8'?> <wsp:Policy xmlns="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:orasp="http://schemas.oracle.com/ws/2006/01/securitypolicy" orawsp:status="enabled" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" orawsp:category="security" orawsp:attachTo="binding.server" wsu:Id="ip_assertion_policy" xmlns:orawsp="http://schemas.oracle.com/ws/2006/01/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" wsp:Name="oracle/ip_assertion_policy"> <orasp:ipAssertion orawsp:Silent="true" orawsp:Enforced="true" orawsp:name="WSSecurity IpAssertion Validator" orawsp:category="security/authentication"> <orawsp:bindings> <orawsp:Config orawsp:name="ipassertion" orawsp:configType="declarative"> <orawsp:PropertySet orawsp:name="valid_ips"> <orawsp:Property orawsp:name="valid_ips" orawsp:type="string" orawsp:contentType="constant"> <orawsp:Value>127.0.0.1,192.168.1.1</orawsp:Value> </orawsp:Property> </orawsp:PropertySet> </orawsp:Config> </orawsp:bindings> </orasp:ipAssertion> </wsp:Policy>
新しいアサーションのエントリを定義してそのエグゼキュータ・クラスと関連付ける、policy-config.xmlファイルを作成します。
次に、policy-config.xmlファイルの形式を定義します。
<?xml version="1.0" encoding="UTF-8"?> <policy-config> <policy-model-config> <entry> <key namespace="namespace" elementName="elementname"/> <executor-classname>assertionclass</executor-classname> </entry> </policy-model-config> </policy-config>
次の表に、key要素の属性を示します。
表14-1 key要素の属性
属性 | 説明 |
---|---|
namespace |
ポリシーのネームスペース。この値は、カスタム・ポリシー・ファイルで定義したネームスペース(手順2)と一致する必要があります。 例14-2では、ネームスペースは次のように<wsp:Policy>タグの一部として定義されます。
xmlns:orasp="http://schemas.oracle.com/ws/2006/01/securitypolicy"
|
elementName |
要素の名前。この値は、カスタム・ポリシー・ファイルで定義したアサーション名(手順2)と一致する必要があります。 例14-2では、要素名ipAssertionは次のタグで定義されています。
<orasp:ipAssertion orawsp:Silent="true" orawsp:Enforced="true" orawsp:name="WSSecurity
IpAssertion Validator" orawsp:category="security/authentication">
|
次に、ipAssertionポリシーのエントリを含むpolicy-config.xmlファイルの例を示します。
例14-3 policy-config.xmlファイルの例
<?xml version="1.0" encoding="UTF-8"?> <policy-config> <policy-model-config> <entry> <key namespace="http://schemas.oracle.com/ws/2006/01/securitypolicy" elementName="ipAssertion"/> <executor-classname>sampleassertion.IpAssertionExecutor</executor-classname> </entry> </policy-model-config> </policy-config>
IPAssertionExecutorクラスとpolicy-config.xmlファイルを含むカスタム・アサーションJARファイルを作成します。JARファイルの生成には、Oracle JDeveloper、別のIDE、またはjarツールを使用できます。
次のファイルをCLASSPATHに追加する必要があります。
カスタム・アサーション実行クラスをサーバー環境で使用できるようにするカスタム・アサーションJARファイル。
カスタム・アサーション・クラスの作成に必要なwsm-policy-core.jar、wsm-agent-core.jar、およびmodules/oracle.logging-utils_11.1.1.jar。
カスタム・アサーションJARファイルをCLASSPATHに追加するには、次の手順を実行します。
WebLogic Serverを停止します。
WebLogic Serverの停止の詳細は、『Managing Server Startup and Shutdown for Oracle WebLogic Server』を参照してください。
手順4で作成したカスタム・アサーションJARファイルを、$DOMAIN_HOME/libディレクトリにコピーします。
WebLogic Serverを再起動します。
WebLogic Serverの再起動の詳細は、『Managing Server Startup and Shutdown for Oracle WebLogic Server』を参照してください。
カスタム・ポリシーをWebサービスに添付できるようにするには、「Webサービス・ポリシーのインポート」の手順に従ってカスタム・ポリシーをインポートする必要があります。
「Webサービスへのポリシーの添付」の手順に従って、カスタム・ポリシーをWebサービスに添付します。