views:

68

answers:

1

Hi,

I have been given a WSDL to generate a client against which uses a security policy. This is my first time using a security policy and although I've read about it (basic theory), putting it into practice with specific elements and a specific technology isn't straight forward (to me anyway).

I generated the client using wsimport and there is nothing in the generated classes regarding the security policy. Is this expected?

Can anyone recommend a good tutorial/how to for someone implementing this for the first time? I am using Eclipse as my IDE so something that is not NetBeans specific would be much appreciated.

If it helps, the security portion of the WSDL looks like this:

<wsp:Policy xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
    xmlns:wsaw3c="http://www.w3.org/2005/08/addressing" xmlns:ssp="http://schemas.sun.com/2006/03/wss/server"
    xmlns:sunwsp="http://java.sun.com/xml/ns/wsit/policy" wsu:Id="MyServicePortBindingPolicy">
    <sp:SymmetricBinding>
        <wsp:Policy>
            <sp:AlgorithmSuite>
                <wsp:Policy>
                    <sp:Basic128 />
                </wsp:Policy>
            </sp:AlgorithmSuite>
            <sp:IncludeTimestamp />
            <sp:Layout>
                <wsp:Policy>
                    <sp:Lax />
                </wsp:Policy>
            </sp:Layout>
            <sp:OnlySignEntireHeadersAndBody />
            <sp:ProtectionToken>
                <wsp:Policy>
                    <sp:IssuedToken
                        sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"&gt;
                        <wsp:Policy>
                            <sp:RequireInternalReference />
                        </wsp:Policy>
                        <sp:Issuer>
                            <wsaw3c:Address>https://server.com:8443/service&lt;/wsaw3c:Address&gt;
                            <wsaw3c:Metadata>
                                <ns1:Metadata
                                    xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/09/mex"&gt;
                                    <ns1:MetadataSection>
                                        <ns1:MetadataReference>
                                            <wsaw3c:Address>https://server.com:8443/service&lt;/wsaw3c:Address&gt;
                                        </ns1:MetadataReference>
                                    </ns1:MetadataSection>
                                </ns1:Metadata>
                            </wsaw3c:Metadata>
                        </sp:Issuer>
                        <sp:RequestSecurityTokenTemplate>
                            <ns2:KeySize
                                xmlns:ns2="http://docs.oasis-open.org/ws-sx/ws-trust/200512"&gt;128&lt;/ns2:KeySize&gt;
                            <ns3:KeyType
                                xmlns:ns3="http://docs.oasis-open.org/ws-sx/ws-trust/200512"&gt;http://docs.oasis-open.org/ws-sx/ws-trust/200512/SymmetricKey&lt;/ns3:KeyType&gt;
                            <ns4:TokenType
                                xmlns:ns4="http://docs.oasis-open.org/ws-sx/ws-trust/200512"&gt;http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1&lt;/ns4:TokenType&gt;
                        </sp:RequestSecurityTokenTemplate>
                    </sp:IssuedToken>
                </wsp:Policy>
            </sp:ProtectionToken>
        </wsp:Policy>
    </sp:SymmetricBinding>
    <sp:Trust13>
        <wsp:Policy>
            <sp:MustSupportIssuedTokens />
            <sp:RequireClientEntropy />
            <sp:RequireServerEntropy />
        </wsp:Policy>
    </sp:Trust13>
    <sp:Wss11>
        <wsp:Policy>
            <sp:MustSupportRefEncryptedKey />
            <sp:MustSupportRefIssuerSerial />
            <sp:MustSupportRefThumbprint />
        </wsp:Policy>
    </sp:Wss11>


    <wsam:Addressing />
</wsp:Policy>
<wsp:Policy xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
    wsu:Id="MyServicePortBinding_getMyService_Input_Policy">
    <sp:EncryptedParts>
        <sp:Body />
    </sp:EncryptedParts>
    <sp:SignedParts>
        <sp:Body />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="ReplyTo" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="To" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="From" />
        <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"
            Name="AckRequested" />
        <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"
            Name="CreateSequence" />
        <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"
            Name="Sequence" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="MessageID" />
        <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" />
        <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"
            Name="SequenceAcknowledgement" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="Action" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="RelatesTo" />
    </sp:SignedParts>
</wsp:Policy>
<wsp:Policy xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
    wsu:Id="MyServicePortBinding_getMyService_Output_Policy">
    <sp:EncryptedParts>
        <sp:Body />
    </sp:EncryptedParts>
    <sp:SignedParts>
        <sp:Body />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="ReplyTo" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="To" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="From" />
        <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"
            Name="AckRequested" />
        <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"
            Name="CreateSequence" />
        <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"
            Name="Sequence" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="MessageID" />
        <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" />
        <sp:Header Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"
            Name="SequenceAcknowledgement" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="Action" />
        <sp:Header Namespace="http://www.w3.org/2005/08/addressing"
            Name="RelatesTo" />
    </sp:SignedParts>
</wsp:Policy>
A: 

Not an answer, but more information/questions. Perhaps I should have edited the original question, but there's a lot of information...

I have since discovered the need for a MyService.xml file and wsit-client.xml files. The policy in the MyService.xml file looks like:

<wsp:Policy wsu:Id="MyServicePortBindingPolicy">
    <wsp:ExactlyOne>
        <wsp:All>
            <sc:CallbackHandlerConfiguration
                wspp:visibility="private">
                <sc:CallbackHandler default="testUser"
                    name="usernameHandler" />
                <sc:CallbackHandler default="testPW"
                    name="passwordHandler" />
            </sc:CallbackHandlerConfiguration>
        </wsp:All>
    </wsp:ExactlyOne>
</wsp:Policy>

I have created a MyServiceCallbackHandler class:

package my.service.client;

import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;

public class MyServiceCallbackHandler implements CallbackHandler
{

    public void handle(Callback[] callbacks) throws IOException,
            UnsupportedCallbackException
    {
        for (Callback callback : callbacks)
        {
            if (callback instanceof NameCallback)
            {
                ((NameCallback) callback).setName("testUser");
            }
            else if (callback instanceof PasswordCallback)
            {
                ((PasswordCallback) callback).setPassword("testPW".toCharArray());
            }
            else
            {
                throw new UnsupportedCallbackException(callback,
                        "Unrecognized Callback");
            }
        }
    }
}

My wsit-client.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?> 
 <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" 
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="mainclientconfig">
    <import location="MyService.xml" namespace="http://my.service/"/&gt;
</definitions>

Both the wsit-client.xml and MyService.xml files are located in my src/main/resources/meta-info folder.

I am trying to test the client by running a main method in my client class, but get this exception:

Caught Exception: javax.xml.ws.soap.SOAPFaultException: Security Requirements not met - No Security header in message
javax.xml.ws.soap.SOAPFaultException: Security Requirements not met - No Security header in message

This isn't unexpected because I have no idea how to configure the client to use the handler/xml files. I have searched for how to do this, but to no avail.

My intent was to create a jar file that can be used as a library in other web applications that need to access the web service. Can I do this or do I need to package it as a war file? Do I need to configure the handler class in a web.xml file?

If anyone can point me to a resource on how to deploy a web services client with this type of security policy it would be greatly appreciated.

sdoca