Submitted on July 3, 2008 - 11:17.
The release of Axis2 1.4 introduced the policy configuration at binding level facility that's been long awaited. Now, with Axis2 1.4 you can define policies using binding hierarchy at binding level, binding operation level and binding message level. However, if you configure security using the new configuration, it makes services vulnerable, exposing the service in an unsecure manner for some End Point References (EPR).
| Project/lan | version |
| Apache Rampart | 1.4 |
| Apache Axis2 | 1.4 |
So let's take the version service founf in Axis2 as an example. In Aixs2 1.4, it is exposed in four EPRs.
When policies are configured at binding-level for requests coming through EPR 1.) , 2.) and 3) using new policy configuration mechanism, Axis Engine will correctly set appropriate effective policies. However, if requests comes through EPR 4.), policies will not be set on request messages. So when it comes to Rampart module doing security validation, Rampart will consider the fact that there is no policy associated with the corresponding message and allow the message that doesn’t satisfy security requirements to consume the service.
Due to the above reason, you SHOULD NOT use the new policy configuration found in Axis2 1.4 to configure security and should stick to the old way of configuration even with Axis2 1.4. You can find how to configure security using the old configurations, in the following tutorials listed below:
Now we will look at problems that arise as a result of appling polices using old configurations in Axis2 1.4.
When we configure policies using the old configurations, that is, when we attach policies to the service, operation, message elements in the services.xml, they are attached to the portType element WSDL generated in Axis2 1.4. In Axis2 1.4 if you need to attach policies to the binding, you are required to attach them using the new configurations introduced in Axis2 1.4, that allows you to attach policies to the binding hierarchy. But, as we discussed earlier we are not able to implement this due to security vulnerabilities.
As an example, If we deploy the service I've used in the tutorial titled “ Web Services Security with Apache Rampart – Part 1 ( Transport Level Security )” using Axis2 1.3 and Axis2 1.4, the WSDLs generated would look like this.
As you can see below, in Axis2 1.3 generated WDSL, policies are attached to bindings.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns0="http://service.rampart.tutorial" >
<wsdl:binding name="SecureServiceSOAP11Binding" type="ns0:SecureServicePortType">
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" Id="UTOverTransport">
...
</wsp:Policy>
</wsdl:binding>
<wsdl:binding name="SecureServiceSOAP12Binding" type="ns0:SecureServicePortType">
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" Id="UTOverTransport">
...
</wsp:Policy>
</wsdl:binding>
...
</wsdl:definitions>
But if we look at Axis2 1.4 generated WSDL policies are attached to the port type.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
...
<wsp:Policy wsu:Id="UTOverTransport"
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">
</wsp:Policy>
...
<wsdl:portType name="SecureServicePortType"
wsp:PolicyURIs="#UTOverTransport"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" >
...
</wsdl:portType>
...
</wsdl:definitions>
So does this really matter ? Yes, because WS - Security Policy specification specifically states not to attach security policies to the port type and they should appear in the bindings and this is a violation of what the specification is suggesting. For more information please refer to the section 4.2 – Policy Subjects in the WS - Security Policy specification. What this means is we lose the interoperability between other WS Stacks. And another problem is Axis2 code generator doesn’t attached these policies to the generated Stub when we code generate against the WSDL. This is discussed in the section "Code generated Stubs against Axis2 1.4 generated WSDL doesn’t contain the policies".
One work around would be to put the correct WSDL in to the service archive and configure Axis2 to use the original WSDL in the service archive. You can do this annotation in the WSDL generation correctly and redeploy using the use original parameter set in the services.xml as illustrated below:
<service name="MyService">
...
<parameter name="ServiceClass" locked="false">com.wso2.training.MyService</parameter>
<parameter name="useOriginalwsdl">true</parameter>
...
</service>
You should put correctly annotated MyService.wsdl file in to the META-INF directory in your service archive.
Now, let's look at the second issue if you use the WSDL generated by Axis2 1.4.
Generally Axis2 code generator correctly attaches policies in the WSDL to the WSDL generated ( as described in the tutorial titled“ Web Services Security with Apache Rampart – Part 1 ( Transport Level Security )”. But when policies are attached to the port type as it is done in Axis2 1.4 generated WSDL, policies in the WSDL are not attached to the stub generated.
Work around for this would be to inject policies from a policy file. In order to do this, you need to first extract the policy from the WSDL and save it as a file. For the example discussed, the policy file would look like this. Then you could create a policy object from that file using the following code:
StAXOMBuilder builder = new StAXOMBuilder(path/to/policy/file);
Policy clientPolicy = PolicyEngine.getPolicy(builder.getDocumentElement());
Then you can attach that policy using the following code:
ServiceClient sc = stub._getServiceClient(); sc.getAxisService().getPolicySubject().attachPolicy(clientPolicy);
You SHOULD NOT attach security polices to binding hierarchy using the new policy configuration introduced in Axis2 1.4, as this leads to exposing service with security threats. You can use the more older way of configuring security policies and use one of the work arounds whenever necessary.
Nandana Mihindukulasooriya, Software Engineer, WSO2 Inc. nandana AT wso2 DOT com
| Attachment | Size |
|---|---|
| SecureService.zip | 2.14 KB |
Does this problem still exist in Axis2 1.41?
Hi Nandana,
thanks for this hint.
I´m wondering if this problem is already fixed in Axis2 1.41 or does it still exist there? Is there a JIRA-issue?
regards,
Nicolas
Fixed in Axis2 1.4.1
Hi Nicolas,
This problem is fixed in Axis2 1.4.1. This was the main reason for us to go for a quick Axis2 1.4.1. Issues fixed in 1.4.1 - [1].
thanks,
nandana
[1] - http://issues.apache.org/jira/secure/ReleaseNote.jspa?version=12313298&styleName=Text&projectId=10611&Create=Create
Good News!
Great!!!
Thanks for your reply.
Best regards,
Nicolas
Missing wsse:Security header in request
Hi Nandana,
Thanks for your tutorial! I've attached the policy file in my client program, but I have always the error: Missing wsse:Security header in request.
This is my code:
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("client-repo",null);
ExampleStub stb = new ExampleStub(ctx,"https://localhost:8443/axis2/services/ExampleService");
ServiceClient sc = stb._getServiceClient();
sc.engageModule("rampart");
sc.engageModule("addressing");
sc.getAxisService().getPolicySubject().attachPolicy(loadPolicy("policy.xml"));
Options options = sc.getOptions();
options.setUserName("apache");
options.setPassword("password");
System.setProperty("javax.net.ssl.trustStore", "C:\\.keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "keystorepass");
int a = 3; int b = 4;
ExampleStub.Add ex = new ExampleStub.Add();
ex.setA(a);
ex.setB(b);
ExampleStub.AddResponse result = stb.add(ex);
System.out.println(a + " + " + b + " = " + result.get_return());
Could you help me?
Thanks
Cam Tu
Re: Missing wsse:Security header in request
What is the policy you used ? Tutorial 1 or 2.
thanks,
nandana
How about migrating to Axis2
How about migrating to Axis2 1.4.1 to take advantage of the latest changes?
japanese fashion online
How about migrating to Axis2
How about migrating to Axis2 1.4.1 to take advantage of the latest changes? Cayenne pepper diet | สุขภาพ | โรคความดันโลหิตสูง
Anyone tried migrating to
Anyone tried migrating to Axis for a change.Could anyone help me clarify this? Citibank Credit Card
thanks for this hint. I´m
thanks for this hint.
I´m wondering if this problem is already fixed in Axis2 1.41 or does it still exist there? Is there a JIRA-issue? Cayenne Pepper Diet | Printable Address Labels | เครื่องสำอางเกาหลี