wso2ws-securitywss4jwso2-esb

WSO2 ESB - Rampart Password Callback class - WSPasswordCallback cannot be cast


I want to to invoke a secured backend service in WSO2 ESB 5.0.0 with rampart configuration and Password Callback class

package com.yenlo.wso2.services;
import org.apache.ws.security.WSPasswordCallback;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.IOException;

public class PWCBHandler implements CallbackHandler {

public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]; 

    // set the password for our message.
    pc.setPassword("YENLO_TEST");       

   }
}

When i call the proxy service this error occurs:

org.apache.ws.security.WSPasswordCallback cannot be cast to org.apache.ws.security.WSPasswordCallback

I have compiled my source code with wss4j 1.6.17 and 1.5.12. Nothing's Changed.


Solution

  • I've created a new callbackhandler project from scratch and got it working with a few sidenodes: - I've used the following dependency in the main pom.xml:

    <dependency>
        <groupId>org.apache.ws.security</groupId>
        <artifactId>wss4j</artifactId>
        <version>1.5.11</version>
    </dependency>
    

    I put the resulting '.jar' in repository/components/lib. Also I removed the .jar from repository/components/dropins when redeploying to be sure(ESB creates a file there during startup when processing the .jar)

    I've put the entire project here. Build using 'mvn clean package'.

    Good luck! I'd like to hear back if you succeeded!