cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Manson <dev.mansontho...@gmail.com>
Subject CXF client - how to dynamically set user/password at runtime
Date Wed, 10 Jul 2013 16:29:18 GMT
Hi,

  I need to call a web service provider and specify on the fly the
username/password (and later use SAML (header & body need to be signed)).

  I'm in a context of a J2EE multiuser application, and I have to call the
web service provider with the credential of the user connected to the web
application.

 Later I'll have to implement SAML implementation (and X509 if I've time),
and I would like to be able to put this in the same code base, where you
switch authentication type by configuration.


Here is below the current implémentation I've and that is working,
I can see that I can use the PasswordCallback to get the password, but I've
no option to set dynamically the username.

For the password, I was planning to use ThreadLocal to retrieve the
password, If you have other suggestions, I'm eager to hear it.


I've seen related to AbstractUsernameTokenInInterceptor, but I don't have a
full example with both username & password dynamically setted.

If you have any full example, or documation to point me out, would be great
;)

Thanks,
Thomas.


*final* String password = *this*.password;



    JaxWsProxyFactoryBean factory = *new* JaxWsProxyFactoryBean();

    factory.setServiceClass(WorkListService.*class*);

    factory.setAddress(*this*.endpoint);

    //
factory.setWsdlLocation("D:/ARTIC/SOURCE/artic/trunk/webapp/src/main/webapp/WSDL/brm.wsdl");

    factory.setServiceName(*new* QName("http://services.brm.n2.tibco.com",
"WorkListService"));

    WorkListService workListService = (WorkListService) factory.create();



    Client client = ClientProxy.*getClient*(workListService);



    Map<String, Object> properties = *new* HashMap<String, Object>();

    properties.put(WSHandlerConstants.*ACTION*, WSHandlerConstants.*
USERNAME_TOKEN*);

    properties.put(WSHandlerConstants.*USER*, *this*.username);

    properties.put(WSHandlerConstants.*PASSWORD_TYPE*, WSConstants.*PW_TEXT*
);// "PasswordDigest"

    properties.put(WSHandlerConstants.*PW_CALLBACK_REF*, *new*CallbackHandler()

    {

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

      {

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

        pc.setPassword(password);

      }

    });



    client.getOutInterceptors().add(*new* WSS4JOutInterceptor(properties));



    HTTPConduit conduit = (HTTPConduit) client.getConduit();



    *long* timeoutMillis = timeout * 1000;



    HTTPClientPolicy policy = *new* HTTPClientPolicy();

    policy.setConnectionTimeout(timeoutMillis);

    policy.setReceiveTimeout(timeoutMillis);



    conduit.setClient(policy);

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message