I have fixed the problem. It seems the behavior of WSS4JOutInterceptor has 
changed, so I have to call super.handleMessage(message) from my interceptor and 
add my real interceptor to the interceptor chain as it does in 
WSS4JOutInterceptor.

Boxiong


----- Original Message ----
From: Boxiong Ding <[EMAIL PROTECTED]>
To: [email protected]
Sent: Thursday, June 5, 2008 5:56:38 PM
Subject: Use WSS4JOutInterceptor to add header is broken with 2.1

I am writing a CXF client and using interceptor to add security headers in Java 
code. It used to work fine with 2.0.4, but broken when I upgrade to 2.1 jar 
(the only thing changed is cxf-2.1.jar). In the following getSecurityHeader() 
method, it now returns null but used to return header element.

Does any one have any clue?

// This method add interceptor:  AuthenticationInterceptor extends 
WSS4JOutInterceptor
  private static void addHeaders(MyService port) throws Exception {
    Client cli = ClientProxy.getClient(port);
    Endpoint endpoint = cli.getEndpoint();

    Map<String, Object> outprops = new HashMap<String, Object>();
    outprops.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outprops.put(WSHandlerConstants.USER, "myname");
    outprops.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    outprops.put(WSHandlerConstants.PW_CALLBACK_CLASS, 
ClientPasswordCallbackHandler.class.getName());

    AuthenticationInterceptor wssout = new AuthenticationInterceptor(outprops);
    endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
    endpoint.getOutInterceptors().add(wssout);
  }

// This method try to get security header, and I will do something with it 
later. This is in  AuthenticationInterceptor
  private Element getSecurityHeader(SoapMessage message) throws SOAPException
  {
    SOAPMessage doc = message.getContent(SOAPMessage.class);
    String actor = (String)getOption(WSHandlerConstants.ACTOR);

    SOAPConstants sc = 
WSSecurityUtil.getSOAPConstants(doc.getSOAPPart().getDocumentElement());
    return  WSSecurityUtil.getSecurityHeader(doc.getSOAPPart(), actor, sc);
  }

Thanks,
Boxiong


      

Reply via email to