Oracle® Fusion Middleware Oracle Web Services Manager拡張可能アプリケーションの開発 12c (12.1.2) E48046-02 |
|
前 |
次 |
Oracle Web Services Manager Java APIリファレンスでは、カスタム・アサーションに高度な機能を実装するために使用するパッケージ、インタフェースおよびメソッドを指定します。この章では、APIを使用して一部の共通の機能を実装する方法について説明します。この章では、APIの使用および例外処理について説明します。次の項目について説明します。
次のインタフェースおよびメソッドを使用して、カスタム・アサーションにパラメータを入力できます。
IAssertionBindings
IConfig
IPropertySet
getBindings
getConfigs
getPropertySets
getPropertyByName
getValue
カスタム・アサーションにパラメータを入力するには、次の手順を実行します。
カスタム・アサーション内部に、パラメータをプロパティとして指定します。この例では、valid_ipsという名前が付いたorawsp:PropertySetがプロパティのグループを定義します。orawsp:Property要素は単一のプロパティを定義します。orawsp:Valueではプロパティの有効な値のリストを定義します。
<orawsp:PropertySet orawsp:name="valid_ips"> <orawsp:Property orawsp:name="valid_ips" orawsp:type="string" orawsp:contentType="constant"> <orawsp:Value>140.87.6.143,10.178.93.107</orawsp:Value> </orawsp:Property> </orawsp:PropertySet>
対応するポリシーのカスタム・エグゼキュータ内部のパラメータにアクセスします。たとえば、カスタム・アサーションのExecutorクラスの実行メソッドの次のコードは、プロパティvalid_ipsにアクセスします。
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();
IMessageContextインタフェースを使用して、OWSMコンテキスト・プロパティにアクセスします。
次のインタフェースおよびメソッドを使用して、カスタム・アサーションへのパラメータにアクセスします。
IMessageContext
getServiceURL
getProperty
getAllProperty
OWSMコンテキスト・プロパティにアクセスするには、次の手順を実行します。
カスタム・アサーション・エグゼキュータ内部のOWSMコンテキスト・プロパティにアクセスするには、IMessageContextインタフェースを使用します。次に例を示します。
IMessageContext messagecontext = (IMessageContext) context; messagecontext.getServiceURL();
カスタム・アサーション・エグゼキュータ内部にある特定のプロパティの値にアクセスするには、IMessageContextインタフェースを使用します。次に例を示します。
messagecontext.getProperty("<property name>");
カスタム・アサーション・エグゼキュータ内部から実行中に使用されるすべてのプロパティにアクセスするには、IMessageContextインタフェースを使用します。次に例を示します。
msgContextProperties = messagecontext.getAllProperties();
OWSMカスタム・セキュリティ・アサーションには、リクエスト、レスポンスおよびフォルトの3つのステージがあります。
クライアントがリクエストを実行し、そのリクエストがリクエスト先に配信中であるときに、リクエスト・ステージが発生します。
リクエスト先がメッセージを処理し、レスポンスを返しているときに、レスポンス・ステージが発生します。
フォルトの場合に、フォルト・ステージが発生します。
コンテキスト情報(ステージやメッセージなど)はコンテキスト・プロパティを使用して渡され、IMessageContextインタフェースによって取得されます。次のインタフェースとメソッドは、コンテンツ・プロパティにアクセスするために使用します。
IMessageContext
getStage
getRequestMessage
getResponseMessage
リクエスト、レスポンスおよびフォルトのメッセージやステージにアクセスするには、次の手順を実行します。
ステージにアクセスするには、カスタム・アサーション・エグゼキュータ内で次のコードを使用します。
IMessageContext.STAGE stage = ((IMessageContext) iContext).getStage(); if (stage == IMessageContext.STAGE.request) { //handle request } if (stage == IMessageContext.STAGE.response) { //handle response } if (stage == IMessageContext.STAGE.fault) { //handle fault conditions }
SOAPリクエスト・メッセージを取得するには、次の例に示すように、同じコンテキストのoracle.wsm.common.sdk.IMessageContextを使用します。
oracle.wsm.common.sdk.SOAPBindingMessageContext soapMsgCtxt= (oracle.wsm.common.sdk.SOAPBindingMessageContext) context; javax.xml.soap.SOAPMessage soapMessage = soapMsgCtxt.getRequestMessage();
SOAPレスポンス・メッセージを取得するには、次の例に示すように、同じコンテキストのoracle.wsm.common.sdk.IMessageContextを使用します。
oracle.wsm.common.sdk.SOAPBindingMessageContext soapMsgCtxt= (oracle.wsm.common.sdk.SOAPBindingMessageContext) context; javax.xml.soap.SOAPMessage soapMessage = soapMsgCtxt.getResponseMessage ();
カスタム・ポリシー・エグゼキュータ内のXPath式を使用して、SOAPメッセージのパーツにアクセスできます。
次のSOAPメッセージ例では、ノードarg0の値はjohnです。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Header/> <S:Body> <ns2:echo xmlns:ns2="http://project1/"> <arg0>john</arg0> </ns2:echo> </S:Body> </S:Envelope>
XPathには、要素、属性、テキスト、ネームスペース、処理の指示、コメントおよびドキュメント・ノードの7種類のノードがあります。XPathでは、パス式を使用してXMLドキュメントのノードを選択します。表4-1は、XPath式の例を示しています。
表4-1 XPath式の例
式 | 説明 |
---|---|
/S:Envelope |
ルート要素S:Envelopeから選択します。 |
/S:Envelope/S:Body |
S:Envelopeの子であるすべてのS:Body要素を選択します。 |
//S:Body |
ドキュメント内のどこにあっても、すべてのS:Body要素を選択します。 |
たとえば、ノードarg0の値にアクセスするには、前述のSOAPメッセージのarg0のXPath式は次のように定義されます。
//xpath expression that will be used to identify the node arg0 String xpathStr = "/S:Envelope/S:Body/ns2:echo/arg0";
XPath式が参照する任意のネームスペースのためのネームスペースを定義し、これらをネームスペース・コンテキストに追加します。次に例を示します。
final DefaultNamespaceContext nsContext = new DefaultNamespaceContext(); nsContext.addEntry("S", "http://schemas.xmlsoap.org/soap/envelope/"); nsContext.addEntry("ns2", "http://project1/"); XPathFactory xpathFact = XPathFactory.newInstance(); XPath xpath = xpathFact.newXPath(); xpath.setNamespaceContext(nsContext);
評価メソッドを使用して、ノードの値を取得します。次に例を示します。
//This will return node arg0 from SOAP message, here soapElement is // org.w3c.dom.Elemet representation of SOAP message org.w3c.dom.Node inputNode = (Node)xpath.evaluate(xpathStr, soapElement, XPathConstants.NODE);
SSLの証明書を取得するには、次の手順を実行します。
次の例に示すように、同じコンテキストのoracle.wsm.common.sdk.IMessageContextを使用して、SOAPレスポンス・メッセージを取得します。
oracle.wsm.common.sdk.SOAPBindingMessageContext soapMsgCtxt= (oracle.wsm.common.sdk.SOAPBindingMessageContext) context;
HttpServletRequestインタフェースを使用して、サーブレット・リクエスト情報を取得します。
javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest) soapMsgCtxt.getTransportObject(ITransportContext.HTTP_SERVLETREQUEST_OBJ_ NAME);
X.509証明書の属性にアクセスします。次に例を示します。
X509Certificate[] certificates = (X509Certificate[]) request.getAttribute(oracle.wsm.security.util.SecurityConstants.SSL_PEER_ CERTIFICATES);
注意: javax.servlet.http.HttpServletRequestインタフェースを使用するには、JARファイルmodules/javax.servlet_1.0.0.0_2-5.jarをクラスパスに含める必要があります。 |
HTTPリクエストおよびレスポンスなどのトランスポート・オブジェクトにアクセスするには、次の手順を実行します。
次の例に示すように、同じコンテキストのoracle.wsm.common.sdk.IMessageContextを使用して、SOAPレスポンス・メッセージを取得します。
oracle.wsm.common.sdk.SOAPBindingMessageContext soapMsgCtxt= (oracle.wsm.common.sdk.SOAPBindingMessageContext) context;
HttpServletRequestインタフェースを使用して、次の例に示すように、HTTPサーブレットのサーブレット・リクエスト情報を取得します。
//to retrieve http servlet request object HttpServletRequest request = (HttpServletRequest) soapMsgCtxt .getTransportObject(ITransportContext.HTTP_SERVLETREQUEST_OBJ_ NAME);
HttpServletRequestインタフェースを使用して、次の例に示すように、HTTPサーブレットのサーブレット・レスポンス情報を取得します。
//to retrieve http servlet response object HttpServletResponse response = (HttpServletResponse) soapMsgCtxt .getTransportObject(ITransportContext.HTTP_SERVLETRESPONSE_OBJ_ NAME);
注意: javax.servlet.http.HttpServletRequestインタフェースを使用するには、JARファイルmodules/javax.servlet_1.0.0.0_2-5.jarをクラスパスに含める必要があります。 |
資格証明ストア・フレームワーク(CSF)を使用して、資格証明を安全に管理し、資格証明を保存、取得および維持できます。
CSFを構成するには、次の手順を実行します。
jps-config.xmlでCSFを構成します。
WLSTを使用した資格証明ストアの構成方法の詳細は、『Oracle Web Services ManagerによるWebサービスの保護とポリシーの管理』の資格証明ストアの構成に関する説明を参照してください。
カスタム・アサーション・エグゼキュータ内部のCSFからCSFキーを追加、更新または取得できます。例4-1および例4-2では、資格証明ストアからCSFキーにアクセスするために使用できるサンプル・コードを示しています。
例4-1 CSFキーへのアクセス
final String mapName = "oracle.wsm.security"; final csfKey = "user.credentials"; final oracle.security.jps.service.credstore.PasswordCredential userCreds = getCredentialsFromCSF(mapName, csfKey); if (userCreds != null) { System.out.println("name:"+ userCreds.getName()); System.out.println("name:"+ new String(userCreds.getPassword())); }
例4-2 getCredentialsFromCSFメソッド
private static oracle.security.jps.service.credstore.PasswordCredential getCredentialsFromCSF( final String mapName, final String csfKey) { oracle.security.jps.service.credstore.PasswordCredential passwordCredential = null; try { if (csfKey != null) { final oracle.security.jps.service.credstore.CredentialStore credStore = getCredStore(); if (credStore != null) { passwordCredential = (oracle.security.jps.service.credstore.PasswordCredential) java.security.AccessController .doPrivileged(new java.security.PrivilegedExceptionAction<oracle.security.jps.service.credstore. Credential>() { public oracle.security.jps.service.credstore.Credential run() throws Exception { return (credStore .getCredential(mapName, csfKey)); } }); } else { // failure obtaining csf credentials } } } catch (final java.security.PrivilegedActionException ex) { //handle excpetion } catch (final oracle.security.jps.JpsException jpse) { //handle excpetion } return passwordCredential; } private static oracle.security.jps.service.credstore.CredentialStore getCredStore() throws oracle.security.jps.JpsException { oracle.security.jps.service.credstore.CredentialStore csfStore; oracle.security.jps.service.credstore.CredentialStore appCsfStore = null; oracle.security.jps.service.credstore.CredentialStore systemCsfStore = null; final oracle.security.jps.internal.api.runtime.ServerContextFactory factory = (oracle.security.jps.internal.api.runtime.ServerContextFactory) oracle.security.jps.JpsContextFactory .getContextFactory(); final oracle.security.jps.JpsContext jpsCtxSystemDefault = factory.getContext(oracle.security.jps.internal.api.runtime.ServerContextFactory.S cope.SYSTEM); final oracle.security.jps.JpsContext jpsCtxAppDefault = factory .getContext(oracle.security.jps.internal.api.runtime.ServerContextFactory.Scope.AP PLICATION); appCsfStore = (jpsCtxAppDefault != null) ? jpsCtxAppDefault .getServiceInstance(oracle.security.jps.service.credstore.CredentialStore.class) : null; if (appCsfStore == null) { systemCsfStore = jpsCtxSystemDefault .getServiceInstance(oracle.security.jps.service.credstore.CredentialStore.class); csfStore = systemCsfStore; } else { //use Credential Store defined in app-level jps-config.xml csfStore = appCsfStore; } return csfStore; }
注意: JARファイルoracle.jps_12.1.2/jps-api.jar、oracle.jps_12.1.2/jps-unsupported-api.jarは、クラスパスに含まれている必要があります。 |
カスタム・ポリシー・エグゼキュータのjarに対して、CredentialAccessPermission権限を指定する必要があります。権限の付与についての詳細は、『Oracle Platform Security Servicesによるアプリケーションの保護』のJavaセキュリティ・ポリシーの権限に関する説明を参照してください。
カスタム・アサーション実行中の例外は、すべてWSMExceptionがカスタム・アサーション・エグゼキュータで処理する必要があります。
IResult execute(IContext mcontext) throws WSMException
このメソッドは、常に、null以外のIResultオブジェクトを返します。ステータス・フィールドは、成功、失敗または他の状態を示します。IResult.getFault()メソッドは失敗の詳細な原因を返すために使用され、成功の場合はnullを返します。
次の例に示すように、カスタム・アサーション・エグゼキュータの実行メソッドから発生している例外は、まず、WSMExceptionでラップする必要があります。実行ステータスがIResult.FAILEDに設定され、generateFault methodがWSMExceptionをスローします。
IResult execute(IContext mcontext) throws WSMException { IResult result = new Result(); try { .... ..... } catch (Exception e) { WSMException wsmException = new WSMException(e); result.setStatus(IResult.FAILED); generateFault(wsmException); } }