Monday May 14, 2007
Monday May 14, 2007
In Manual Web Service Configuration In From Java Case you saw how to manually configure Java web service endpoint. This entry describes how to use external policies for endpoint configuration instead of including policy assertions directly into WSIT config file. The scenario enables you to store and maintain all your policies at one central place...

$ vim $AS_HOME/domains/domain1/docroot/policies.xml
Content of your newly created "policy repository" could be as follows:
<?xml version="1.0" encoding="UTF-8"?>
<policies
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy">
<wsp:Policy wsu:Id="Class1BindingPolicy">
<wsp:ExactlyOne>
<wsp:All>
<wsrm:RMAssertion/>
<wsaws:UsingAddressing/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
</policies>
This way your "policy repository" should be available at http://localhost:8080/policies.xml and you have defined just one policy Class1BindingPolicy which could be referenced as http://localhost:8080/policies.xml#Class1BindingPolicy
The endpoint is created the same way as in Manual Web Service Configuration In From Java Case
For sake of clarity I will repeat the steps here:
$ mkdir work-wspol ; cd work-wspol ; vim Stock.java
package org.example;import javax.jws.WebMethod;
import javax.jws.WebService;@WebService(serviceName="StockSvc", portName="StockPort", targetNamespace="http://example.org")
public class Stock {@WebMethod()
public boolean itemAvaiable (String itemId, int amount) {
return Math.random() > 0.6;
}
}
$ mkdir -p WEB-INF/classes; javac -cp $AS_HOME/lib/javaee.jar -d WEB-INF/classes Stock.java
$ $AS_HOME/bin/wsgen -wsdl -cp WEB-INF/classes org.example.Stock ; mv StockSvc.wsdl WEB-INF/wsit-org.example.Stock.xml
Now remove useless lines from the skeleton:
$ vim WEB-INF/wsit-org.example.Stock.xml
Lines to remove:
<types>
<xsd:schema>
<xsd:import namespace="http://example.org" schemaLocation="StockSvc_schema1.xsd"/>
</xsd:schema>
</types>
And:
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
Attaching an external policy simply means adding a PolicyReference to the config file.
In our case, we will only add the following line to our wsit config file:
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
URI="http://localhost:8080/policies.xml#Class1BindingPolicy"/>
So that our config file will look like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://example.org" name="StockSvc"
xmlns:tns="http://example.org"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="itemAvaiable">
<part name="parameters" element="tns:itemAvaiable"/>
</message>
<message name="itemAvaiableResponse">
<part name="parameters" element="tns:itemAvaiableResponse"/>
</message>
<portType name="Stock">
<operation name="itemAvaiable">
<input message="tns:itemAvaiable"/>
<output message="tns:itemAvaiableResponse"/>
</operation>
</portType>
<binding name="StockPortBinding" type="tns:Stock">
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
URI="http://localhost:8080/policies.xml#Class1BindingPolicy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="itemAvaiable">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="StockSvc">
<port name="StockPort" binding="tns:StockPortBinding">
</port>
</service>
</definitions>
You should now be able to deploy the endpoint in one shot by:
$ jar cvf $AS_HOME/domains/domain1/autodeploy/stock.war WEB-INF
If you look at the published WSDL of our endpoint, you will probably notice that
original external reference was replaced by a local one and the policy definition was included into the wsdl.
It means that consumer of your endpoint does not need to have access to original "policy repository". On the other hand, if you forbid access to your "policy repository" from outside, described mechanism will still work! So what? You can store sensitive information in your policy repository (keystore locations, passwords, etc.). Such information will be properly used for configuring your endpoints and safely removed from published WSDLs. It means you can maintain such a sensitive information at just one place and still be able to use it for configuring lots of your endpoints.
Links are broken... I'm interested in what the internally referenced wsdl looks like. Can all external references be changed to internal, for the case of intranet-only web services in a secure environment?
Posted by mark wiseman on July 14, 2008 at 07:56 PM CEST #
Mark, i have just published the wsdl at http://blogs.sun.com/japod/resource/wspol/StockSvc.wsdl
(btw. the link in the original post is not broken. It was meant like you reproduce the steps as you read and finally have the service and it's wsdl published at your machine)
Posted by Jakub on July 15, 2008 at 01:54 PM CEST #
Can you attach a ws-securitypolicy to an operation instead of the service binding? Whenever I tried that in a tomcat container I get a policy exception? According ws-policy doc I should be able to attach a policy simply to an operation and not the whole portType...
Posted by Andy Basu on April 28, 2009 at 05:37 PM CEST #