Liberty:ibm-ws-bnd.xml 檔
您可以利用 Liberty 中的 ibm-ws-bnd.xml 檔,針對 Web 服務提供者和 Web 服務用戶端兩者,來自訂 Web 服務端點及配置安全設定。您必須將這個檔案儲存在 Web 應用程式的 /WEB-INF 目錄或 EJB 模組的 /META-INF 目錄中。
ibm-ws-bnd.xml 檔提供下列元素階層:
ibm-ws-bnd.xml 檔中每個元素的說明如下:
<webservice-endpoint-properties>
這個元素用來定義相同模組中所有 Web 服務端點的預設內容。 一個模組只能指定一個 webservice-endpoint-properties 元素。 您可以將適用於 Web 服務端點的任何名稱/值配對指定為 webservice-endpoint-properties 元素的屬性。
如果您新增 <enableLoggingInOutInterceptor> 內容,您可以同時記載用戶端和伺服器端的 SOAP 要求和回應:
<webservice-endpoint-properties enableLoggingInOutInterceptor="false">
註: 如果您設定 enable LoggingInOutInterceptor="true",您的認證會顯示在 message.log 中。
<webservice-endpoint>
這個元素用來指定所指定之服務實例的連結。
它有下列屬性:
- port-component-name:這個屬性是必要的。它用來指定埠元件的名稱。
- address:這個屬性是選用的。它用來指定服務端點的置換位址。
如果您新增 <enableLoggingInOutInterceptor> 內容,您可以同時記載用戶端和伺服器端的 SOAP 要求和回應:
<webservice-endpoint port-component-name="Hello">
<properties enableLoggingInOutInterceptor="true"/>
</webservice-endpoint>
註: 如果您設定 enable LoggingInOutInterceptor="true",您的認證會顯示在 message.log 中。
<http-publishing>
當所有 Web 服務端點都使用 HTTP 通訊協定時,這個元素用來指定發佈配置。
每一個模組中只能指定一個 <http-publishing> 元素。它有下列屬性:
- context-root:這個屬性是選用的。它用來指定 EJB 型 JAX-WS 應用程式中的 EJB 模組的環境定義根目錄。
<webservice-security>
這個元素是用來配置 POJO Web 服務和 EJB 型 Web 服務的角色型授權。它有下列屬性:
- security-constraint:這個屬性是選用的。它用來將安全限制關聯於一或多個 Web 資源集合,只能作為 Web 應用程式中的部署描述子或註釋的補充配置。
- security-role:這個屬性是選用的。它包含安全角色的定義,且只能作為 Web 應用程式中的部署描述子或註釋的補充配置。
- login-config:這個屬性是選用的。它用來配置鑑別方法和網域範圍名稱,且只對 JAR 檔內的 EJB 型 Web 服務有效。如果在部署描述子檔案中指定了相同的屬性,會使用部署描述子中的值。 這個屬性的值必須是 BASIC 或 CLIENT_CERT。
<service-ref>
這個元素用來定義 Web 服務用戶端的 Web 服務參照配置。
它有下列屬性:
- name:這個屬性是必要的。它用來指定 Web 服務參照的名稱。
- component-name:這個屬性是選用的。如果在 EJB 模組中使用了服務參照,它用來指定 EJB Bean 名稱。
- port-address:這個屬性是選用的。如果所參照的 Web 服務只有一個埠,它用來指定 Web 服務埠的位址。
- wsdl-location:這個屬性是選用的。它用來指定要置換之 WSDL 的 URL。
<port>
這個元素用來定義與 Web 服務參照相關聯的埠配置。
在 service-ref 內可以定義多個 port 元素。
它有下列屬性:
- name:這個屬性是必要的。它用來指定 Web 服務埠的名稱。
- namespace:這個屬性是選用的。它用來指定 Web 服務埠的名稱空間。如果 namespace 屬性存在,連結適用於有相同名稱和名稱空間的埠。 否則,連結適用於有相同名稱的埠。
- address:這個屬性是選用的。它用來指定 Web 服務埠的位址。 如果存在,它會置換 service-ref 元素中所定義的 port-address 屬性值。
- username:這個屬性是選用的。它用來指定基本鑑別的使用者名稱。
- password:這個屬性是選用的。它用來指定基本鑑別的密碼。密碼可以編碼。
- ssl-ref:這個屬性是選用的。它利用 id 屬性來參照 server.xml 檔中所配置的 ssl 元素。 如果沒有指定這個屬性,但透過啟用 ssl-1.0 特性,伺服器支援傳輸層安全,服務用戶端會使用 Liberty 的預設 SSL 配置。
- key-alias:這個屬性是選用的。它用來指定用戶端憑證的別名。 如果沒有指定這個屬性,且 Web 服務提供者支援用戶端憑證,就會以金鑰儲存庫中的第一個憑證來作為這個屬性值。 這個屬性也可以置換 server.xml 檔的 ssl 元素中所定義的 clientKeyAlias 屬性。
<properties>
這個元素是用來定義 Web 服務端點或用戶端的內容。這些屬性可以是任何名稱及任何值。
- 對於 Web 服務用戶端,您可以指定 client.ConnectionTimeout、authorization.UserName、tlsClientParameters.disableCNcheck 和其他屬性。
- 對於 Web 服務端點,您可以指定 publishedEndpointUrl、org.apache.cxf.wsdl.create.imports 和其他屬性。
下列範例顯示 ibm-ws-bnd.xml 檔的一般配置:
<?xml version="1.0" encoding="UTF-8"?>
<webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd "
version="1.0">
<!-- optional Web service endpoint default properties -->
<webservice-endpoint-properties org.apache.cxf.wsdl.create.imports="true" ... />
<!-- 0 to many endpoint descriptions -->
<webservice-endpoint port-component-name="..." address="optional override address">
<!-- optional Web service endpoint properties -->
<properties publishedEndpointUrl="http://www.example.com/services/hello"
org.apache.cxf.wsdl.create.imports="false" />
</webservice-endpoint>
...
<!-- optional http publishing module overrides -->
<http-publishing context-root="optional override of module's context root">
<!-- optional web.xml fragment for security -->
<webservice-security>
<!-- SECURITY CONSTRAINTS -->
<security-constraint>
<web-resource-collection>
<web-resource-name>SayHelloServiceName</web-resource-name>
<url-pattern>/SayHelloService</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>SayHelloServiceAuth</description>
<role-name>group123</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!-- SECURITY CONSTRAINTS -->
<security-constraint>
<web-resource-collection>
<web-resource-name>SecuredSayHelloServiceName</web-resource-name>
<url-pattern>/Secured*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>SecuredSayHelloServiceAuth</description>
<role-name>group123</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<!-- SECURITY ROLES -->
<security-role id="group123_id">
<role-name>group123</role-name>
</security-role>
<!-- AUTHENTICATION METHOD: Client certificate or basic authentication -->
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</webservice-security>
</http-publishing>
<!-- 0 to many client refs -->
<service-ref name="services/sayHelloService"
port-address="http://productServer:productPort/context-root/SayHelloService"/>
<service-ref name="services/securedSayHelloService"
port-address="http://productServer:productPort/context-root/SecuredSayHelloService"
wsdl-location="optional override of WSDL document" />
</webservices-bnd>