When applying security scenario 1 to a Proxy in wso2 esb , I get the following errors , but only when the Respond mediator is reached.
> TID: [0] [ESB] [2015-03-23 12:52:05,418] DEBUG
> {org.apache.synapse.mediators.builtin.SendMediator} - Start : Send
> mediator {org.apache.synapse.mediators.builtin.SendMediator} TID: [0]
> [ESB] [2015-03-23 12:52:05,419] DEBUG
> {org.apache.synapse.mediators.builtin.SendMediator} - Sending
> response message using implicit message properties.. Sending To:
> http://www.w3.org/2005/08/addressing/anonymous SOAPAction:
> {org.apache.synapse.mediators.builtin.SendMediator} TID: [0] [ESB]
> [2015-03-23 12:52:05,511] ERROR
> {org.apache.synapse.core.axis2.Axis2Sender} -
> Content-Type:text/xml;charset=UTF-8,Date:Mon, 23 Mar 2015 10:52:02
> GMT,Server:WSO2 Carbon Server,Transfer-Encoding:chunked,<?xml
> version="1.0" encoding="utf-8"?><soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:prod="http://za.co.pepkor/product_service/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
> soapenv:mustUnderstand="1"><wsu:Timestamp
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
> wsu:Id="Timestamp-1"><wsu:Created>2015-03-23T10:52:05.507Z</wsu:Created><wsu:Expires>2015-03-23T10:57:05.507Z</wsu:Expires></wsu:Timestamp></wsse:Security></soapenv:Header><soapenv:Body><prod:productSearchResp>
> <productDetails><noItemFound>No item in
> Ackerman's</noItemFound></productDetails><productDetails><productID>1452168</productID><productName>PUMPS</productName><productSize>7</productSize><productColour>ORANGE</productColour><productType>SHOE</productType><sourceID>SHC</sourceID></productDetails><productDetails><productID>1124596</productID><productName>REEBOK_SNEAKERS</productName><productSize>7</productSize><productColour>BROWN</productColour><productType>SHOES</productType><sourceID>SHC</sourceID></productDetails><productDetails><productID>1123456</productID><productName>NIKE_SHIRTS</productName><productSize>7</productSize><productColour>RED</productColour><productType>SHIRT</productType><sourceID>SHC</sourceID></productDetails>
> </prod:productSearchResp></soapenv:Body></soapenv:Envelope> Unexpected
> error sending message back {org.apache.synapse.core.axis2.Axis2Sender}
> org.apache.axis2.AxisFault: No user value in the rampart configuration
> policy at
> org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:76)
> at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340) at
> org.apache.axis2.engine.Phase.invoke(Phase.java:313) at
> org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:261) at
> org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:426) at
> org.apache.synapse.core.axis2.Axis2Sender.sendBack(Axis2Sender.java:163)
> at
> org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send(Axis2SynapseEnvironment.java:321)
> at
> org.apache.synapse.mediators.builtin.SendMediator.mediate(SendMediator.java:94)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
> at
> org.apache.synapse.config.xml.AnonymousListMediator.mediate(AnonymousListMediator.java:30)
> at
> org.apache.synapse.config.xml.SwitchCase.mediate(SwitchCase.java:66)
> at
> org.apache.synapse.mediators.filters.SwitchMediator.mediate(SwitchMediator.java:123)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
> at
> org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
> at
> org.apache.synapse.mediators.eip.aggregator.AggregateMediator.completeAggregate(AggregateMediator.java:419)
> at
> org.apache.synapse.mediators.eip.aggregator.AggregateMediator.mediate(AggregateMediator.java:314)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
> at
> org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
> at
> org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:196)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
> at
> org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
> at
> org.apache.synapse.mediators.eip.aggregator.AggregateMediator.completeAggregate(AggregateMediator.java:419)
> at
> org.apache.synapse.mediators.eip.aggregator.AggregateMediator.mediate(AggregateMediator.java:314)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
> at
> org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
> at org.apache.synapse.mediators.eip.Target.mediate(Target.java:106)
> at
> org.apache.synapse.mediators.eip.splitter.IterateMediator.mediate(IterateMediator.java:146)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
> at
> org.apache.synapse.mediators.filters.FilterMediator.mediate(FilterMediator.java:160)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
> at
> org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
> at
> org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
> at
> org.apache.synapse.core.axis2.Axis2SynapseEnvironment.injectMessage(Axis2SynapseEnvironment.java:261)
> at
> org.apache.synapse.core.axis2.SynapseCallbackReceiver.handleMessage(SynapseCallbackReceiver.java:488)
> at
> org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170)
> at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
> at
> org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:225)
> at
> org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> at java.lang.Thread.run(Thread.java:745) Caused by:
> org.apache.rampart.RampartException: No user value in the rampart
> configuration policy at
> org.apache.rampart.builder.BindingBuilder.addUsernameToken(BindingBuilder.java:212)
> at
> org.apache.rampart.builder.TransportBindingBuilder.build(TransportBindingBuilder.java:95)
> at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:140)
> at
> org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:65)
> ... 46 more
This is of course using the default policies. I tried editing the policy as follows (soap11binding level) :
<rampart:RampartConfig xmlns:rampart="http://ws.apache.org/rampart/policy">
<rampart:user>admin</rampart:user>
<rampart:timestampPrecisionInMilliseconds>true</rampart:timestampPrecisionInMilliseconds>
<rampart:timestampTTL>300</rampart:timestampTTL>
<rampart:timestampMaxSkew>300</rampart:timestampMaxSkew>
<rampart:timestampStrict>false</rampart:timestampStrict>
<rampart:tokenStoreClass>org.wso2.carbon.security.mypwhandler.PWCBHandler</rampart:tokenStoreClass>
<rampart:nonceLifeTime>300</rampart:nonceLifeTime>
</rampart:RampartConfig>
Where PWCBHandler =
package org.wso2.carbon.security.mypwhandler;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;
import org.wso2.carbon.user.core.UserStoreException;
import org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager;
public class PWCBHandler implements CallbackHandler {
private String all;
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[i];
int usage = pwcb.getUsage();
if (usage == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {
// verify uT password
if ("admin".equals(pwcb.getIdentifier())
&& "admin".equals(pwcb.getPassword())) {
return;
}
}
When I use the above handler , I get the following error:
AxisFault: No password supplied by the callback handler for the user : "admin"
Please assist me with this. I suspect it could be the service chaining aspect that might be causing the issue.
Other things I've tried :
Apply the above as a custom scenario policy , why does includes the keystore/trusted keystore option even though there is NO encryption taking place???
Another thing is why the default SecurityTokenStore is all commented out in the source code??? I cannot hit the above SecurityTokenStore in remote debug...
Proxy :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="Product_Search_Proxy"
transports="https"
statistics="disable"
trace="disable"
startOnLoad="true">
<target outSequence="productSearchHandler">
<inSequence>
<switch source="$trp:Content-Type">
<case regex="text/xml;charset=UTF-8">
<property name="CallType" value="SOAP" scope="default" type="STRING"/>
<log level="custom">
<property name="Soap request read ..." value="sending..."/>
</log>
<log level="full" category="DEBUG" separator="____:::::____"/>
<clone>
<target sequence="ackProductSearchRq"/>
<target sequence="shcProductSearchRq"/>
</clone>
</case>
<case regex="application/json">
<property name="CallType" value="REST" scope="default" type="STRING"/>
<log level="custom">
<property name="REST or API request read ..." value="sending..."/>
</log>
<property name="messageType" value="text/xml" scope="axis2" type="STRING"/>
<log level="full" category="DEBUG" separator="____:::::____"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="name"
expression="//productSearch/productName/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="size"
expression="//productSearch/productSize/text()"
scope="default"
type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd"
name="colour"
expression="//productSearch/productColour/text()"
scope="default"
type="STRING"/>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:prod="http://za.co.pepkor/product_service/">
<soapenv:Body>
<prod:productSearchReq>
<productName xmlns="">$1</productName>
<productSize xmlns="">$2</productSize>
<productColour xmlns="">$3</productColour>
</prod:productSearchReq>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg xmlns:ns="http://org.apache.synapse/xsd"
evaluator="xml"
expression="$ctx:name"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"
evaluator="xml"
expression="$ctx:size"/>
<arg xmlns:ns="http://org.apache.synapse/xsd"
evaluator="xml"
expression="$ctx:colour"/>
</args>
</payloadFactory>
<clone>
<target sequence="ackProductSearchRq"/>
<target sequence="shcProductSearchRq"/>
</clone>
</case>
<default/>
</switch>
</inSequence>
<faultSequence/>
</target>
<publishWSDL key="conf:/service_definitions/PepKorProductSearch.wsdl"/>
<parameter name="ScenarioID">scenario1</parameter>
<enableSec/>
<policy key="conf:/repository/axis2/service-groups/Product_Search_Proxy/services/Product_Search_Proxy/policies/UTOverTransport"/>
<description/>
</proxy>
Since the service runs on the axis 2 engine , going into the axis2.xml file in wso2esb-4.8.1\repository\conf\axis2\ , we see that in the Phases section(the phases represent the "flow" that proxies/services will run through") specifically the < phaseOrder type="OutFlow" > section (which would correspond to the "outSequence" of the proxies) just after the < phase name="MessageOut"/ > , it performs the < phase name="Security"/ > (which would correspond to the security policy of the proxy). So this is where the error is thrown and confirms with the above observation and error log
<phaseOrder type="OutFlow">
<!-- Handlers related to unified-endpoint component are added to the UEPPhase -->
<phase name="UEPPhase" />
<!-- user can add his own phases to this area -->
<phase name="RMPhase"/>
<phase name="MUPhase"/>
<phase name="OpPhase"/>
<phase name="OperationOutPhase"/>
<!--system predefined phase-->
<!--these phase will run irrespective of the service-->
<phase name="PolicyDetermination"/>
<phase name="PTSecurityOutPhase">
<handler name="RelaySecuirtyMessageBuilderDispatchandler"
class="org.apache.synapse.transport.passthru.util.RelaySecuirtyMessageBuilderDispatchandler"/>
</phase>
<phase name="PTCacheOutPhase">
<handler name="CacheMessageBuilderDispatchandler"
class="org.wso2.carbon.mediation.initializer.handler.CacheMessageBuilderDispatchandler"/>
</phase>
<phase name="MessageOut"/>
<phase name="Security"/>
<phase name="MsgOutObservation"/>
</phaseOrder>
So we need to assert that the response for this specific proxy must be executed in a non-secured manner.( Communication between the back end is secured already using mutual SSL).
We can write a new module and plug it with ESB's module section( see https://docs.wso2.com/display/ESB481/Working+with+Modules ) where this module can be used to either skip the < phase name="Security"/ > or apply an empty policy just before the < phase name="Security"/ >. This modular way is the best approach since we can engage “NoSecurity” module only for our desired proxy/services.
Steps:
1. In developer studio , created a module as described in (https://docs.wso2.com/display/ESB481/Writing+an+Axis2+Module):
Handler Logic:
Note that following 2 uses requires the following OutFlow phaseOrder
<OutFlow>
:
<NoSecurity/>
<Security/>
:
</OutFlow>
// To apply the bottom(getPolicy) empty policy for security phase...
InputStream stream = new ByteArrayInputStream(getPolicy().getBytes());
Policy policy = PolicyEngine.getPolicy(stream);
if (policy != null) {
messageContext.setProperty("rampartOutPolicy", policy);
}
return InvocationResponse.CONTINUE;
// To skip the <security> phase when <noSecurity> is reached..
msgContext.setCurrentHandlerIndex(msgContext.getCurrentHandlerIndex()+ 2);
return InvocationResponse.CONTINUE;
{
private String getPolicy() {
return "<wsp:Policy wsu:Id=\"emptyPolicy\" 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:ExactlyOne><wsp:All><sp:TransportBinding xmlns:sp=\"http://schemas.xmlsoap.org/ws/2005/07/securitypolicy\">"
+ "<wsp:Policy></wsp:Policy></sp:TransportBinding></wsp:All></wsp:ExactlyOne></wsp:Policy>";
}
}
2. Upload module to ESB (https://docs.wso2.com/display/ESB481/Uploading+a+Module)
3. Engage module on a SERVICE LEVEL (https://docs.wso2.com/display/ESB481/Module+Engagement+for+Service)
4. Re-tested = SUCCESS !