+ Start a Discussion
DimonDimon 

WebServiceCallout and WSSE Authentiction

Hi Guys,

 

I'm working on integration with some web service that requires WSSE authentication.

WSSE Authentication requires special SOAP Header that can look like below:

 

<env:Header>

            <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">

                        <wsse:UsernameToken>

                                                <wsse:Username>test</wsse:Username>

                                                <wsse:Password>123</wsse:Password>

                        </wsse:UsernameToken>

            </wsse:Security>

</env:Header>

 

So, I decided to use WebServiceCallout class to invoke that web service methods. I also found a way how to add SOAP header but I spent a lot of time reading documentation and trying different things to figure out how to add "wsse" prefix for the lements in this header without any success...

 

The maximum I was able to produce is:

 

<env:Header>

     <n1:Security xmlns:n1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

             <usernameToken>

                   <username>test</username>

                   <password>123</password>

             </usernameToken>

      </n1:Security>

</env:Header>

 

Do anybody know about any workaround to specify "wsse" prefix?

I really don't want to go with Http classes solution yet hoping that there could be some solution I don't know about. Please advise.

 

Thanks in advance!

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

As per the xml namespaces spec, the actual prefix doesn't matter, all that matters is the URI that the prefix is bound to. What you have is close to what you want, you just need to fix the namespace URI, and the capitalization of the elements.

All Answers

SuperfellSuperfell

As per the xml namespaces spec, the actual prefix doesn't matter, all that matters is the URI that the prefix is bound to. What you have is close to what you want, you just need to fix the namespace URI, and the capitalization of the elements.

This was selected as the best answer
DimonDimon

Thanks a lot


SimonF wrote:

As per the xml namespaces spec, the actual prefix doesn't matter, all that matters is the URI that the prefix is bound to. What you have is close to what you want, you just need to fix the namespace URI, and the capitalization of the elements.



for your reply, SimonF!

 

I made changes in the code to have the capitalization. I left URI as is because it's suggested by web service provider.

I didn't find a way how to make "n1" prefix for all elments inside "Security" one, probably that's why I still have UnAuthorized response from that web service...

 

 

SuperfellSuperfell

Can you post your code.

DimonDimon

Well, here is my code (of course it's simplified to exclude sensitive information):

 

public class SoapSecurity {

    public UsernameToken UsernameToken = new UsernameToken();

    private String[] UsernameToken_type_info = new String[] {'UsernameToken','','ComplexType','1','1','false'};

    private String[] apex_schema_type_info = new String[] {'','true','false'};

    private String[] field_order_type_info = new String[]{'UsernameToken'};

}

 

public class UsernameToken {

    public String Username = 'test';

    public String Password = '123';

    private String[] Username_type_info = new String[] {'Username','','string','1','1','false'};

    private String[] Password_type_info = new String[] {'Password','','string','1','1','false'};

    private String[] apex_schema_type_info = new String[] {'','true','false'};

    private String[] field_order_type_info = new String[]{'Username', 'Password'};

}

 

public class ServicePort {

    public SoapSecurity Security = new SoapSecurity();

    private String Security_hns = 'Security=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

    ...

    ...

    public DWebService.SendDataResponse_element sendData(String userId, DataRecord[] data) {

        WebServiceCallout.invoke(

            this,

            request_x,

            response_map_x,

            new String[] {

                  endpoint_x,

                  '',

                  'http://www.demo.com/DWebService/schema/beans','sendDataRequest',

                  'http://www.demo.com/DWebService/schema/beans',

                  'sendDataResponse','DWebService.sendDataResponse_element'

             }

         );

         ...

         ...

     }

}

 

Please let me know if I need to provide more information.

 

Thanks in advance!

DimonDimon

Well, I've resolved my issue already! SimonF was right with the wsse prefix is not important. The only think I corrected to get it work is right namespaces for all ements in my SOAP header. So, thanks SimonF again!

Harshala Shewale (Salesforce)Harshala Shewale (Salesforce)

Facing same issue, can you help  me?

 

I wanted to craete below response :

 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
	<s:Header>
		<o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:mustUnderstand="1">
			<u:Timestamp u:Id="_0">
				<u:Created>2012-02-28T14:59:55Z</u:Created>
				<u:Expires>2012-02-28T15:04:55Z</u:Expires>
			</u:Timestamp>
			<o:UsernameToken u:Id="uuid-b4a524e5-7486-43c3-bdcf-c6b3fe705ff2-66">
				<o:Username>username</o:Username>
				<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</o:Password>
			</o:UsernameToken>
		</o:Security>
	</s:Header>
	<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
		<request xmlns="http://www.avinode.com/integration/MessageDownload">
			<product>Test Software v3.7</product>
		</request>
	</s:Body>
</s:Envelope>

My class is :

public class MessageDownloadWebServiceImplPort 
    {
        public String endpoint_x = 'https://services.avinode.com:443/avinode/AvinodeIntegrationWeb/ws/MessageDownload.ws';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x ;
        public String clientCert_x ;
        public String clientCertPasswd_x ;
        public Integer timeout_x ;
        private String Security_hns = 'Security=' + SECURITY_HEADER_SCHEMA_NS;
        public AvinodeComIntegrationMessagedownl.Security Security;
        private String[] ns_map_type_info = new String[]{'http://www.avinode.com/integration/MessageDownload', 'AvinodeComIntegrationMessagedownl', 'http://www.avinode.com/core/CommonTypes', 'AvinodeComCoreCommontypes'};
        
        public MessageDownloadWebServiceImplPort(String APIUsername, String APIPassword)
        {
                Security = new AvinodeComIntegrationMessagedownl.Security(APIUsername, APIPassword);
        }
        
        public AvinodeComIntegrationMessagedownl.DownloadResponseType request(String product,DateTime after) 
        {
            AvinodeComIntegrationMessagedownl.DownloadRequestType request_x = new AvinodeComIntegrationMessagedownl.DownloadRequestType();
            AvinodeComIntegrationMessagedownl.DownloadResponseType response_x;
            request_x.product = product;
            request_x.after = after;
            Map<String, AvinodeComIntegrationMessagedownl.DownloadResponseType> response_map_x = new Map<String, AvinodeComIntegrationMessagedownl.DownloadResponseType>();
            response_map_x.put('response_x', response_x);
            
            system.debug('request_x:'+request_x);
            
            WebServiceCallout.invoke
            (
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.avinode.com/integration/MessageDownload#request',
              'http://www.avinode.com/integration/MessageDownload',
              'request',
              'http://www.avinode.com/integration/MessageDownload',
              'response',
              'AvinodeComIntegrationMessagedownl.DownloadResponseType'}
            );
            response_x = response_map_x.get('response_x');
            return response_x;
        }
    }

 

 

 

 I have tried alot but in vain, can anyone tell me how should i code to get the same resonse?