1

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.

Community
  • 1
  • 1
siavash fd
  • 27
  • 3

2 Answers2

0

Have a look at the available version of wss4j inside "wso2esb-5.0.0/repository/components/plugins" folder. It looks like you are using a different version in the compile time, that may lead to this kind of issue.

Try to use wss4j with the following dependency version when compiling.

version=1.5.11.wso2v14
groupId=org.apache.ws.security.wso2
artifactId=wss4j
Rans
  • 422
  • 2
  • 8
  • Nothing's Changed. I have downloaded wss4j-1.5.11.wso2v14.jar from https://mvnrepository.com/artifact/org.apache.ws.security.wso2/wss4j/1.5.11.wso2v14 – siavash fd Dec 26 '18 at 08:05
  • How do you compile your source ? Are you using maven or different method ? What is your java version? – Rans Dec 26 '18 at 08:08
  • I have used maven. my java version is 1.8.0_181 – siavash fd Dec 26 '18 at 08:27
  • my pom file: org.apache.ws.security.wso2 wss4j 1.5.11.wso2v14 wso2-public http://maven.wso2.org/nexus/content/repositories/public – siavash fd Dec 26 '18 at 08:45
0

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!

Jan
  • 618
  • 5
  • 12