How to turn off SecureConversationToken in WCF web service - java

I have a WCF web service with WS-* security and I need to write a Java client for it using WSS4J API.
But, as it turns out WSS4J does not support the <SecurityContextToken> and <DerivedKeyToken> tags, which are specific to WS-SecureConversation.
is there a way to turn it off via code or better, via web.config?
UPDATE:
Service definition:
<service name="my.service"
behaviorConfiguration="SecureTransport">
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint
contract="my.interface"
binding="wsHttpBinding"
bindingConfiguration="UsernameAndPassword"/>
</service>
Behaviour and Bindings:
<behaviors>
<serviceBehaviors>
<behavior name="SecureTransport">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="example.API.Security.CustomUserNameValidator, APISecurity" />
<serviceCertificate findValue="CN=Example" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectDistinguishedName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="UsernameAndPassword">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>

Just turn security context and probably also negotiation in your binding configuration:
<bindings>
<wsHttpBinding>
<binding name="UsernameAndPassword">
<security mode="Message">
<message clientCredentialType="UserName" establishSecurityContext="false"
negotiateServiceCredential="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>

Related

Mule: Interface binding for different components, how to avoid duplication?

We have the following mule flow:
<flow name="mule-flow-1">
<component>
<spring-object bean="springBean_1"/>
<binding interface="com.acme.EmailService" method="send">
<vm:outbound-endpoint path="send-email" exchange-pattern="one-way"/>
</binding>
</component>
</flow>
but right now we want to introduce new flow, with new Spring bean which uses the same EmailService.send method, so, we can do it as:
<flow name="mule-flow-2">
<component>
<spring-object bean="springBean_2"/>
<binding interface="com.acme.EmailService" method="send">
<vm:outbound-endpoint path="send-email" exchange-pattern="one-way"/>
</binding>
</component>
</flow>
As you can see, we bound EmailService.send method twice in two different flows and it is pure code duplication.
Is it possible to bind EmailService.send method somewhere in common place and just use ref in mule-flow-1 and mule-flow-2?
maybe you can use subflow? Define your component there and then use flow-ref in any flow you want to reuse it.
<sub-flow name="mule-flow-send">
<component>
<spring-object bean="springBean_1"/>
<binding interface="com.acme.EmailService" method="send">
<vm:outbound-endpoint path="send-email" exchange-pattern="one-way"/>
</binding>
</component>
</sub-flow>
and then reusing:
<flow name="mule-flow-1">
<flow-ref name="mule-flow-send" doc:name="mule-flow-send"/>
</flow>
<flow name="mule-flow-2">
<flow-ref name="mule-flow-send" doc:name="mule-flow-send"/>
</flow>

Authenticating SOAP service using certificate encodedValue in MULE ESB

I'm provided with a wsdl and have to access certain service (TestMessage) using the authentication credentials provided (username : test-Ser, password: XXXX). The wsdl file was generated from the given config file in C#.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="PProxyEndpoint">
<security>
<message clientCredentialType="UserName" establishSecurityContext="false" />
</security>
</binding>
<binding name="PProxyEndpointSvcCertSpecified">
<security>
<message clientCredentialType="UserName" negotiateServiceCredential="false"
establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://p-cer.test.ca/PService.svc"
binding="wsHttpBinding" bindingConfiguration="PProxyEndpoint"
contract="IPService" name="PProxyEndpoint">
<identity>
<certificate encodedValue="XXXXXXXXXXXXXXXXXX............" />
</identity>
</endpoint>
<endpoint address="http://p-cer.test.ca/PService.svc/SvcCertSpecified"
binding="wsHttpBinding" bindingConfiguration="PProxyEndpointSvcCertSpecified"
contract="IPService" name="PProxyEndpointSvcCertSpecified">
<identity>
<certificate encodedValue="XXXXXXXXXXXXXXXXXX............" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
The authentication code is in C# as below:
private static TestClient AuthUser()
{
TestClient client = new TestClient();
client.ClientCredentials.UserName.UserName = “XXXX”;
client.ClientCredentials.UserName.Password = “XXXXX”;
return client;
}
using (TestClient test = AuthUser())
{
TestListRequestItemWrapper ttt = new TestListRequestItemWrapper();
ttt.RequestItems = new ListRequestItem[1];
ttt.RequestItems[0] = new ListRequestItem();
TestListResponseItemWrapper resp = test.TestList(ttt);
}
I have to do same such thing in java, And I'm unable to do so. Please help.
How can I authenticate SOAP service using certificate encoded value in JAVA?
My configuration.xml in Mule ESB is as follow
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="test" doc:name="HTTP Listener Configuration"/>
<spring:beans>
<spring:bean name="myPasswordCallback" class="com.org.message.PasswordCallback"/>
</spring:beans>
<spring:beans>
<spring:bean id="wss4jInConfiguration" name="Bean" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<spring:constructor-arg>
<spring:map>
<spring:entry key="action" value="UsernameToken "/>
<spring:entry key="passwordType" value="PasswordText"/>
<spring:entry key="user" value="vha-test.xml"/>
<spring:entry key="passwordCallbackRef" value-ref="myPasswordCallback">
</spring:entry>
</spring:map>
</spring:constructor-arg>
</spring:bean>
</spring:beans>
<http:listener-config name="HTTP_Listener_Configuration_3" host="0.0.0.0" port="8083" doc:name="HTTP Listener Configuration"/>
<ws:consumer-config name="Web_Service_Consumer" wsdlLocation="http://path.svc?wsdl" service="XService" port="XProxyEndpointSvcCertSpecified" serviceAddress="http://path.svc/SvcCertSpecified" doc:name="Web Service Consumer"/>
<flow name="testdemoFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<custom-transformer class="com.org.message.GetMessageExample" doc:name="Java"/>
<response>
<object-to-string-transformer doc:name="Object to String"/>
</response>
<cxf:jaxws-client serviceClass="com.org.IXmlService" doc:name="CXF" operation="GetMessageList" port="IXmlService" soapVersion="1.2">
<!-- <cxf:ws-security>
<cxf:ws-config>
<cxf:property key="action" value="UsernameToken"/>
<cxf:property key="user" value="uname"/>
<cxf:property key="passwordCallbackClass" value="com.org.message.PasswordCallback"/>
<cxf:property key="passwordType" value="PasswordText"/>
</cxf:ws-config>
</cxf:ws-security> -->
<cxf:inInterceptors>
<spring:bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
<spring:bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<spring:constructor-arg>
<spring:map>
<spring:entry key="action" value="Signature" />
<spring:entry key="signaturePropFile" value="src/main/resources/ws-sign-security.properties" />
</spring:map>
</spring:constructor-arg>
</spring:bean>
</cxf:inInterceptors>
</cxf:jaxws-client>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="Content-type" value="application/soap+xml"/>
<add-message-property key="charset" value="UTF-8"/>
</message-properties-transformer>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8084" method="POST" doc:name="HTTP"/>
</flow>
and below is another configuration.xml I've tried:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" basePath="wsdl" doc:name="HTTP Listener Configuration"/>
<ws:consumer-config name="Web_Service_Consumer" wsdlLocation="http://patyh.svc?wsdl" service="XService" port="XProxyEndpoint" serviceAddress="http://path.svc" doc:name="Web Service Consumer">
<ws:security>
<ws:wss-username-token username="uname" password="password" passwordType="TEXT" addCreated="true" addNonce="true"/>
<ws:wss-timestamp expires="60000"/>
</ws:security>
</ws:consumer-config>
<flow name="wsdltestFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<ws:consumer config-ref="Web_Service_Consumer" operation="PingWithAuthorization" doc:name="Web Service Consumer"/>
<logger level="INFO" doc:name="Logger" message="req gen : #[payload]"/>
</flow>
</mule>
I'm still not able to authenticate with any of the XMl

call third party web service using apache camel

I am new to camel
I am trying to call webservice using camel java dsl
from("cxf://http://darshan:8080/sampleWebService/SampleTestServicePort?wsdlURL=http://darshan:8080/sampleWebService/SampleTestServicePort?wsdl&serviceName={http://ws.test.com/}SampleTestServiceService&portName={http://ws.test.com/}SampleTestServicePort&dataFormat=MESSAGE")
following is my wsdl file:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.test.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.test.com/" name="SampleTestServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.test.com/" schemaLocation="http://darshan:808O/sampleWebService/SampleTestServicePort?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"></part>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"></part>
</message>
<portType name="SampleTestServiceDelegate">
<operation name="sayHello">
<input message="tns:sayHello"></input>
<output message="tns:sayHelloResponse"></output>
</operation>
</portType>
<binding name="SampleTestServicePortBinding" type="tns:SampleTestServiceDelegate">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="sayHello">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="SampleTestServiceService">
<port name="SampleTestServicePort" binding="tns:SampleTestServicePortBinding">
<soap:address location="http://darshan:808O/sampleWebService/SampleTestServicePort"></soap:address>
</port>
</service>
</definitions>
That gives no error but also output is nothing.
Please suggest me what is wrong in my code.
Thanks in advance
When you use the Apache CXF Component as a from() what you are doing is you are hosting the webservice instead of accessing a third-party one.
To access a third-party service you need to use the to() form of the component. You need to do something like this:
<route>
<from uri="file:./myFileRequest?delay=1000&include=myRequest.xml">
<to uri="cxf://http://darshan:8080/sampleWebService/SampleTestServicePort?wsdlURL=http://darshan:8080/sampleWebService/SampleTestServicePort?wsdl&serviceName={http://ws.test.com/}SampleTestServiceService&portName={http://ws.test.com/}SampleTestServicePort&dataFormat=MESSAGE" />
...
</route>
Is this what you are looking for?
Define the cxf bean as below in the camel context
<cxf:cxfEndpoint
address="Service ENDPOINT"
endpointName="give wsdl:port#name here from wsdl"
id="any id" loggingFeatureEnabled="true"
serviceClass="your service class - it will be inside the stubs generated from WSDL"
serviceName="Service Name"
wsdlURL="WSDL path" xmlns:ws="namespace">
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD"/>
</cxf:properties>
</cxf:cxfEndpoint>
then write the following in your route:
<to id="_to1" uri="cxf:bean:id Of the cxfEndpoint bean"/>

How to configure Userid/Password on a client side for a WCF service in config file and not in code

Requirement is to call a Java Web Service. There is a WSDL provided. Call is successful in unsecured fashion. Now the service call needs to be authenticated. Service call will be successful only via a paricular windows userid/password. Since everything in our application is config based, we don't want to hard-code anything in code. Appreciate if someone can show how to do so ?
I have this config by the way....
<basicHttpBinding>
<binding name="MyBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
You can't set the username/password anywhere in the WCF-specific configuration. You can, however, set the username/password pair as application settings, retrieve them from the code, and set them in the WCF client.
<configuration>
<appSettings>
<add key="UserName" value="My user name" />
<add key="Password" value="Your secret password" />
</appSettings>
</configuration>
and in the code:
var username = ConfigurationManager.AppSettings["UserName"];
var password = ConfigurationManager.AppSettings["Password"];
client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;

Generate webservice from WSDL with Document/literal format

I am having troubles generating a WS from a WSDL by means of wsimport.
The WSDL is the TMDD v3.0 standard specification (WSDL and related XSD files can be found here)
According to this article from IBM the WSDL seems to be in Document/literal format.
In order to get the WSDL compiled I have created some bindings/tweaks however I am stuck at this error (it does not generate a method since the operation has more than one part):
[WARNING] Ingoring operation "DlFullEventUpdateSubscription": more than one part
bound to body
line 17 of file:/O:/temp/wsdltest/TMDD-stripped.wsdl
To simplify, this is the stripped down version of the WSDL with only the interesting operation definition
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:tns="http://www.tmdd.org/3/dialogs"
xmlns:tmdd="http://www.tmdd.org/3/messages" xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:c2c="http://www.ntcip.org/c2c-message-administration" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
name="TMDDCenterServices" targetNamespace="http://www.tmdd.org/3/dialogs">
<documentation>
</documentation>
<types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.tmdd.org/3/messages"
schemaLocation="TMDD.xsd" />
<xs:import namespace="http://www.ntcip.org/c2c-message-administration"
schemaLocation="C2C.xsd" />
</xs:schema>
</types>
<message name="MSG_EventSubscription">
<part name="c2cMsgAdmin" element="c2c:c2cMessageSubscription" />
<part name="message" element="tmdd:eventRequestMsg" />
</message>
<!-- Common Messages -->
<message name="MSG_ConfirmationReceipt">
<!-- CONNECTION MANAGEMENT Messages -->
<part name="message" element="c2c:c2cMessageReceipt" />
</message>
<message name="MSG_ErrorReport">
<part name="message" element="tmdd:errorReportMsg" />
</message>
<!-- TMDD Owner Center Porttype -->
<portType name="tmddOCSoapHttpServicePortType">
<operation name="DlFullEventUpdateSubscription">
<documentation>
<objectClass>Event</objectClass>
<msgPattern>Sub</msgPattern>
<requirement>REQ1261</requirement>
</documentation>
<input message="tns:MSG_EventSubscription" />
<output message="tns:MSG_ConfirmationReceipt" />
<fault name="errorReport" message="tns:MSG_ErrorReport" />
</operation>
</portType>
<!-- TMDD Owner Center binding -->
<binding name="tmddOCSoapHttpServiceBinding" type="tns:tmddOCSoapHttpServicePortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="DlFullEventUpdateSubscription">
<soap:operation soapAction="' '" style="document" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
<fault name="errorReport">
<soap:fault name="errorReport" use="literal" />
</fault>
</operation>
</binding>
<!-- TMDD Owner Center Service -->
<service name="tmddOCSoapHttpService">
<!-- ************************ -->
<!-- OWNER CENTER Services -->
<!-- ************************ -->
<port name="tmddOCSoapHttpServicePort" binding="tns:tmddOCSoapHttpServiceBinding">
<soap:address location="http://tmdd.owner.center.com/c2cxml/" />
</port>
</service>
</definitions>
The bindings file:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<!-- To create standalone classes instead of nested classes -->
<!--<globalBindings localScoping="toplevel"/>-->
<!--*****************-->
<!-- Package Binding -->
<!--*****************-->
<!--*****************************-->
<!-- C2C classes package binding -->
<!--*****************************-->
<bindings schemaLocation="C2C.xsd">
<schemaBindings>
<package name="tdf.tmdd.model.ntcip.messageadministration" />
</schemaBindings>
</bindings>
<!--**************************************-->
<!-- ITIS-Adopted classes package binding -->
<!--**************************************-->
<bindings schemaLocation="ITIS-Adopted-03-00-02.xsd">
<schemaBindings>
<package name="tdf.tmdd.model.itis.adopted" />
</schemaBindings>
</bindings>
<!--************************************-->
<!-- ITIS-Local classes package binding -->
<!--************************************-->
<bindings schemaLocation="ITIS-Local-03-00-02.xsd">
<schemaBindings>
<package name="tdf.tmdd.model.itis.local" />
</schemaBindings>
</bindings>
<!--**************************************-->
<!-- LRMS-Adopted classes package binding -->
<!--************************************* -->
<bindings schemaLocation="LRMS-Adopted-02-00-00.xsd">
<schemaBindings>
<package name="tdf.tmdd.model.lrms.adopted" />
</schemaBindings>
</bindings>
<!--************************************-->
<!-- LRMS-Local classes package binding -->
<!--************************************-->
<bindings schemaLocation="LRMS-Local-02-00-00.xsd">
<schemaBindings>
<package name="tdf.tmdd.model.lrms.local" />
</schemaBindings>
</bindings>
<!--*******************************-->
<!-- NTCIP classes package binding -->
<!--*******************************-->
<bindings schemaLocation="NTCIP-References.xsd">
<schemaBindings>
<package name="tdf.tmdd.model.ntcip.objectreferences" />
</schemaBindings>
</bindings>
<!--******************************-->
<!-- TMDD classes package binding -->
<!--******************************-->
<bindings schemaLocation="TMDD.xsd">
<schemaBindings>
<package name="tdf.tmdd.model" />
</schemaBindings>
</bindings>
<!--***********************-->
<!-- Class personalization -->
<!--***********************-->
<!--************************************-->
<!-- LRMS-Adopted class personalization -->
<!--************************************-->
<bindings schemaLocation="LRMS-Adopted-02-00-00.xsd">
<bindings node="//xs:complexType[#name='Chain']//xs:sequence//xs:element[#name='chain']//xs:complexType">
<class name="ChainElement" />
</bindings>
<bindings node="//xs:complexType[#name='GridPointPair']">
<class name="GridPointPairAdopted" />
</bindings>
<bindings node="//xs:complexType[#name='AreaLocation']">
<class name="AreaLocationAdopted" />
</bindings>
<bindings node="//xs:complexType[#name='LinkLocation']">
<class name="LinkLocationAdopted" />
</bindings>
<bindings node="//xs:complexType[#name='AdminAreaGroup']">
<class name="AdminAreaGroupAdopted" />
</bindings>
<bindings node="//xs:complexType[#name='GridPointSequence']">
<class name="GridPointSequenceAdopted" />
</bindings>
<bindings node="//xs:complexType[#name='Grid']">
<class name="GridAdopted" />
</bindings>
<bindings node="//xs:complexType[#name='NodeAttribute']">
<class name="NodeAttributeAdopted" />
</bindings>
<bindings node="//xs:complexType[#name='GridPoint']">
<class name="GridPointAdopted" />
</bindings>
</bindings>
<!--********************************-->
<!-- factory method personalization -->
<!--********************************-->
<!--*************************************-->
<!-- TMDD factory method personalization -->
<!--*************************************-->
<bindings schemaLocation="TMDD.xsd" >
<bindings node="//xs:complexType[#name='IntersectionSignalInventoryLinkList']">
<factoryMethod name="createIntersectionSignalInventoryLinks" />
</bindings>
</bindings>
</bindings>
The command line to invoke wsimport is the following:
O:\temp\wsdltest>wsimport -extension -Xdebug -s src -b bindings.xjb TMDD-stripped.wsdl
What can I do to get the "DlFullEventUpdateSubscription" operation correctly created? Are there any alternatives to generate the Java web service? I can not modify the operation definition, since that would not comply with the standard.
Update. Solution
I managed to get it working by modifying WSDL so each part of the message is assigned to header and body:
<binding name="tmddOCSoapHttpServiceBinding" type="tns:tmddOCSoapHttpServicePortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="DlFullEventUpdateSubscription">
<soap:operation soapAction="' '" style="document" />
<input>
<soap:header message="tns:MSG_EventSubscription" use="literal" part="c2cMsgAdmin"/>
<soap:body use="literal" parts="message"/>
</input>
<output>
<soap:body use="literal" />
</output>
<fault name="errorReport">
<soap:fault name="errorReport" use="literal" />
</fault>
</operation>
</binding>
Document-Literal cannot have multi-part message operations. You can use below alternatives.
Use Document/Literal Wrapped style - Wrap multiple parts in a single
document.
Use RPC/Literal style - No restrictions on binding multiple
parts in soap body.
Thanks,
Sreehari.

Categories