Hello,

Any assistance is greatly appreciated. 

I am developing a web service using cxf with ws-sercurity enabled. I am
using UsernameToken with PasswordText.

When I run my ws client, server side password callback is getting blank
password. 

Here is my code.

Server Side:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class ServerPasswordCallback implements CallbackHandler {
        Logger log = LoggerFactory.getLogger("");
        //protected static Logger log =
Logger.getLogger("demo.cxf.services.security");
    public void handle(Callback[] callbacks) throws IOException, 
        UnsupportedCallbackException {

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

        log.debug("Identifier :"+pc.getIdentifier());
        log.debug("Password :"+pc.getPassword());
        log.debug("Type :"+pc.getType());
        log.debug("Usage :"+pc.getUsage());
        log.debug("bytes :" + pc.getKey());
        log.debug("Requested Data in String format :" +
pc.getRequestData().toString());
        
        
        if(!pc.getPassword().equalsIgnoreCase("password")){
                throw new IOException("wrong password");
        }
        
        
//        if (pc.getIdentifier().equals("joe")) {
//            // set the password on the callback. This will be compared to
the
//            // password which was sent from the client.
//            pc.setPassword("password");
//        }
        
        
    }
}


bean.xml
------------
        <bean id="myPasswordCallback"
class="demo.cxf.services.security.ServerPasswordCallback"/>
        
        <jaxws:endpoint 
          id="helloWorld" 
          implementor="demo.cxf.services.HelloWorldImpl" 
          address="/HelloWorld">
          
          
      <jaxws:inInterceptors>
              <bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
                 <constructor-arg>
                    <map>
                       <entry key="action" value="UsernameToken"/>
                       <entry key="passwordType" value="PasswordText"/>
                       <entry key="passwordCallbackRef">
                          <ref bean="myPasswordCallback"/>
                       </entry>
                    </map>
                 </constructor-arg>
              </bean>
           </jaxws:inInterceptors>
      
          </jaxws:endpoint>



Client Side:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class ClientPasswordCallback implements CallbackHandler {

    public void handle(Callback[] callbacks) throws IOException, 
        UnsupportedCallbackException {

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

        // set the user name for out message.
        pc.setIdentifier("ws-client");
        // set the password for our message.
        pc.setPassword("password");
       
    }
}

public class WsClient {

        public static void main(String[] args) {
                // TODO Auto-generated method stub
                demo.cxf.client.HelloWorldImplService service = new
demo.cxf.client.HelloWorldImplService();
                demo.cxf.client.HelloWorld port =
service.getPort(demo.cxf.client.HelloWorld.class);

                Client client = ClientProxy.getClient(port);
                Endpoint cxfEndpoint = client.getEndpoint();

                Map outProps = new HashMap();
                outProps.put(WSHandlerConstants.ACTION,
WSHandlerConstants.USERNAME_TOKEN);
                // Specify our username
                outProps.put(WSHandlerConstants.USER, "ws-client");
                // Password type : plain text
                outProps.put(WSHandlerConstants.PASSWORD_TYPE, 
WSConstants.PW_TEXT);

                // Callback used to retrive password for given user.
                outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS,
demo.cxf.client.ClientPasswordCallback.class.getName());
                WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
                
                cxfEndpoint.getOutInterceptors().add(wssOut);
                cxfEndpoint.getOutInterceptors().add(new SAAJOutInterceptor());

                String result = port.sayHi("HelloWorld");
                System.out.println("Result is :"+result);

                }
}


Thnaks
Raman




--
View this message in context: 
http://cxf.547215.n5.nabble.com/Urgent-Blank-password-received-on-server-side-password-callback-tp5712743.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to