Error Rampart Receiver

1k Views Asked by At

I'm trying to send a information for a securite webservice but I am with the following error when he gotta tell me the answer

[ERROR] Expected encrypted part missing org.apache.axis2.AxisFault: Expected encrypted part missing at org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(RampartReceiver.java:186) at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:99) at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:335) at org.apache.axis2.engine.Phase.invoke(Phase.java:308) at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:250) at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:156) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:357) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:414) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150) at tutorial.somar.Soma001SNAPSHOTStub.add(Soma001SNAPSHOTStub.java:190) at tutorial.somar.teste2.main(teste2.java:65) Caused by: org.apache.rampart.RampartException: Expected encrypted part missing at org.apache.rampart.PolicyBasedResultsValidator.validateEncrSig(PolicyBasedResultsValidator.java:276) at org.apache.rampart.PolicyBasedResultsValidator.validate(PolicyBasedResultsValidator.java:153) at org.apache.rampart.RampartEngine.process(RampartEngine.java:280) at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92) ... 10 more Exception in thread "main" org.apache.axis2.AxisFault: Expected encrypted part missing at org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(RampartReceiver.java:186) at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:99) at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:335) at org.apache.axis2.engine.Phase.invoke(Phase.java:308) at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:250) at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:156) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:357) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:414) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150) at tutorial.somar.Soma001SNAPSHOTStub.add(Soma001SNAPSHOTStub.java:190) at tutorial.somar.teste2.main(teste2.java:65) Caused by: org.apache.rampart.RampartException: Expected encrypted part missing at org.apache.rampart.PolicyBasedResultsValidator.validateEncrSig(PolicyBasedResultsValidator.java:276) at org.apache.rampart.PolicyBasedResultsValidator.validate(PolicyBasedResultsValidator.java:153) at org.apache.rampart.RampartEngine.process(RampartEngine.java:280) at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92) ... 10 more

I'm using maven on the server:

here is the services.xml

<module ref="rampart"/>

<parameter name="ServiceClass" locked="false">tutorial.somar.SecureService</parameter>

<operation name="add">
    <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>   

   <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                <wsp:Policy>
                        <sp:MustSupportRefKeyIdentifier/>
                        <sp:MustSupportRefIssuerSerial/>
                </wsp:Policy>
            </sp:Wss10>

  <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
    <sp:Body/>
  </sp:SignedParts>
  <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
    <sp:Body/>
  </sp:EncryptedParts>

  <ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 
    <ramp:user>serverkey</ramp:user>
    <ramp:encryptionUser>clientkey</ramp:encryptionUser>
    <ramp:passwordCallbackClass>tutorial.somar.PWCBHandler</ramp:passwordCallbackClass>

    <ramp:signatureCrypto>
      <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
        <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">JKS</ramp:property>
        <ramp:property name="org.apache.ws.security.crypto.merlin.file">server.keystore</ramp:property>
        <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">nosecret</ramp:property>
      </ramp:crypto>
    </ramp:signatureCrypto>

    <ramp:encryptionCrypto>
      <ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
        <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">JKS</ramp:property>
        <ramp:property name="org.apache.ws.security.crypto.merlin.file">server.keystore</ramp:property>
        <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">nosecret</ramp:property>
      </ramp:crypto>
    </ramp:encryptionCrypto>

  </ramp:RampartConfig>

</wsp:All>

and the SecureService.java

public int add(int a, int b) {
    System.out.println(a+b);
    return a+b;
}

my WS-client is like this:

public class teste2 {
private static Policy loadPolicy(String name) throws XMLStreamException{
    ClassLoader loader = teste2.class.getClassLoader();
    InputStream resource = loader.getResourceAsStream(name);
    StAXOMBuilder builder = new StAXOMBuilder(resource);
    return PolicyEngine.getPolicy(builder.getDocumentElement());
}

public static void main (String[] args) throws XMLStreamException, RemoteException{
    /*if(args.length < 4){
        System.out.println("Usage:\n  java " +
                "com.sosnoski.ws.library.adb.WebServiceClient protocol host port path");
        System.exit(1);
    }*/

    //String target = args[0] + "://" + args[1] + ":" + args[2] + args[3];
    String target = "http://localhost:8070/axis2/services/soma-0.0.1-SNAPSHOT";
    System.out.println("Connecting to " + target);

    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("client-repo", null);

    Soma001SNAPSHOTStub stub = new Soma001SNAPSHOTStub(ctx ,target);
    //FacebookStub stub = new FacebookStub(target);

    ServiceClient client = stub._getServiceClient();
    Options options = client.getOptions();

    Policy policy = loadPolicy("signencr-policy-client.xml");
    //Policy policy = loadPolicy("policy.xml");
    //Policy policy = loadPolicy("sign-policy-client.xml");
    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);
    options.setUserName("libuser");
    options.setPassword("books");
    client.engageModule("rampart");


    int a = 4;
    int b = 4;
    Add n = new Add();

    n.setA(a);
    n.setB(b);
    AddResponse result = stub.add(n);

    System.out.println(a + " + " + b + " = " + result.get_return());
}

}

I'm using axis2 1.7.1, rampart 1.7.0

1

There are 1 best solutions below

0
Renato Souza Dias On

I solve the problem... I just change that line

<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never"/>

for that

<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
              <wsp:Policy>
              <sp:RequireThumbprintReference/>
            </wsp:Policy>
          </sp:X509Token>

peace.