You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Bitsch. Frederic" <F....@seeburger.de> on 2008/04/21 22:57:14 UTC
Basic authentication as a client
Hi,
I'm facing a problem with basic authentication when consuming a service
with CXF.
Currently the cxf-configuration XML contains these lines for each
service my client is invoking:
<http-conf:authorization>
<UserName
xmlns="http://cxf.apache.org/configuration/security">@@username@@</UserN
ame>
<Password
xmlns="http://cxf.apache.org/configuration/security">@@password@@</Passw
ord>
</http-conf:authorization>
The tokens @@username@@ and @@password@@ are replaced by the classoader
(loading the resource) to allow
dynamic configuration. This is required because the consumed services
can be deployed on different servers having
different security settings (user credentials). I have not yet found a
way to accomplish this with CXF which is not requiring
the classloader workaround.
This is how I instantiate the service-consumer:
new
MyService(ReplacingClassloader.getInstance().getResource("wsdl/myservice
/main.wsdl"),
new QName("urn:MyServiceWsd", "MyService"););
Any ideas how this can be done programmatically ?
Regards,
Frederic
_________________________________________________________________________
SEEBURGER AG Vorstand/Seeburger Executive Board:
Sitz der Gesellschaft/ Bernd Seeburger, Axel Haas, Michael Kleeberg
Registered Office:
Edisonstrasse 1 Vorsitzender des Aufsichtsrats/Chairperson of
D-75015 Bretten the Seeburger Supervisory Board:
Tel.: 07252 / 96-0 Dr. Franz Scherer
Fax: 07252 / 96-2222
Internet: http://www.seeburger.de Registergericht/Commercial Register:
e-mail: info@seeburger.de HRB 240708 Mannheim
_________________________________________________________________________
Dieses E-Mail ist nur fur den Empfanger bestimmt, an den es gerichtet
ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes
Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs-
au?erung ist die des Autors und stellt nicht notwendigerweise die
Ansicht oder Meinung der SEEBURGER AG dar.
Sind Sie nicht der Empfanger, so haben Sie diese E-Mail irrtumlich
erhalten und jegliche Verwendung, Veroffentlichung, Weiterleitung,
Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt.
Weder die SEEBURGER AG noch der Absender (Frederic Bitsch)
ubernehmen die Haftung fur Viren; es obliegt Ihrer Verantwortung,
die E-Mail und deren Anhange (0) auf Viren zu prufen.
The present email addresses only the addressee which it targets and
may contain confidential material that may be protected by the
professional secret. The opinions reflected herein are not necessarily
the one of the SEEBURGER AG.
If you are not the addressee, you have accidentally got this email and
are not enabled to use, publish, forward, copy or print it in any way.
Neither the SEEBURGER AG, nor the sender (Frederic Bitsch) are
liable for viruses, being your own responsibility to check this email
and its attachments (0) for this purpose.
_________________________________________________________________________
Re: Basic authentication as a client
Posted by Sagi Mann <sa...@gmail.com>.
Hi, I've got a similar problem: I'm trying to do this via the
<http:authentication> config, but it seems that only by using the code
version am I able to authenticate to the web service... I don't want to use
code - I want to use the external cxf.xml config and it simply does not
work.
Here is my secure_cxf.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:http="http://cxf.apache.org/transports/http/configuration"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xsi:schemaLocation="
http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<http:conduit name="{http://ws}HelloPort.http-conduit">
<http:authorization>
<sec:UserName>tester1</sec:UserName>
<sec:Password>test</sec:Password>
</http:authorization>
</http:conduit>
</beans>
Here is my client code:
SpringBusFactory bf = new SpringBusFactory();
URL busFile = null;
busFile =
Hello_HelloImplPort_Client.class.getResource("/secure_cxf.xml");
Bus bus = bf.createBus(busFile.toString());
bf.setDefaultBus(bus);
cxf.client.HelloService ss = new HelloService(wsdlURL,
SERVICE_NAME);
cxf.client.Hello port = ss.getHelloPort();
// the authentication works only if I uncomment the following lines.
It does not seems to take the credentials from the .xml:
//BindingProvider bp = (BindingProvider)port;
//bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,
"tester1");
//bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,
"test");
By the way, I also tried the following alternative .xml, with the same code
- same results:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:client id="client1"
serviceClass="cxf.client.Hello"
address="http://mann2:8080/param-tester-ws/HelloService"
username="tester1" password="test"/>
</beans>
any ideas how to define the credentials in the xml rather than code?
thanks.
--
View this message in context: http://www.nabble.com/Basic-authentication-as-a-client-tp16819907p19888674.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Basic authentication as a client
Posted by Vijay Allam <vi...@revolutionhealth.com>.
You may want to use JAX-WS code to accomplish this.
QName SERVICE_NAME = new QName( "http://yournamespace.com",
"MyWebServiceService"); QName PORT_NAME = new QName(
"http://yournamespace.com", "MyService");
Service service = Service.create(SERVICE_NAME);
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, myConfig
.getUrl()); MyWebService port = service.getPort(PORT_NAME,
MyService.class); BindingProvider provider = (BindingProvider) port;
Map<String, Object> requestContext = provider.getRequestContext();
requestContext.put(BindingProvider.PASSWORD_PROPERTY,
myConfig.getPassword());
requestContext.put(BindingProvider.USERNAME_PROPERTY, myConfig.getUserID());
MyConfig is an environment aware config class which dynamically loads my
configurations uid,pwd , service endpoint url etc from propertyfile.
--Vijay
On 4/21/08 4:57 PM, "Bitsch. Frederic" <F....@seeburger.de> wrote:
>
>
> Hi,
>
> I'm facing a problem with basic authentication when consuming a service
> with CXF.
>
> Currently the cxf-configuration XML contains these lines for each
> service my client is invoking:
>
>
>
> <http-conf:authorization>
>
> <UserName
> xmlns="http://cxf.apache.org/configuration/security">@@username@@</UserN
> ame>
>
> <Password
> xmlns="http://cxf.apache.org/configuration/security">@@password@@</Passw
> ord>
>
> </http-conf:authorization>
>
>
>
> The tokens @@username@@ and @@password@@ are replaced by the classoader
> (loading the resource) to allow
>
> dynamic configuration. This is required because the consumed services
> can be deployed on different servers having
>
> different security settings (user credentials). I have not yet found a
> way to accomplish this with CXF which is not requiring
>
> the classloader workaround.
>
>
>
> This is how I instantiate the service-consumer:
>
>
>
> new
> MyService(ReplacingClassloader.getInstance().getResource("wsdl/myservice
> /main.wsdl"),
>
> new QName("urn:MyServiceWsd", "MyService"););
>
>
>
> Any ideas how this can be done programmatically ?
>
>
>
> Regards,
>
> Frederic
>
>
>
> _________________________________________________________________________
>
> SEEBURGER AG Vorstand/Seeburger Executive Board:
> Sitz der Gesellschaft/ Bernd Seeburger, Axel Haas, Michael Kleeberg
> Registered Office:
> Edisonstrasse 1 Vorsitzender des Aufsichtsrats/Chairperson of
> D-75015 Bretten the Seeburger Supervisory Board:
> Tel.: 07252 / 96-0 Dr. Franz Scherer
> Fax: 07252 / 96-2222
> Internet: http://www.seeburger.de Registergericht/Commercial Register:
> e-mail: info@seeburger.de HRB 240708 Mannheim
> _________________________________________________________________________
>
> Dieses E-Mail ist nur fur den Empfanger bestimmt, an den es gerichtet
> ist und kann vertrauliches bzw. unter das Berufsgeheimnis fallendes
> Material enthalten. Jegliche darin enthaltene Ansicht oder Meinungs-
> au?erung ist die des Autors und stellt nicht notwendigerweise die
> Ansicht oder Meinung der SEEBURGER AG dar.
> Sind Sie nicht der Empfanger, so haben Sie diese E-Mail irrtumlich
> erhalten und jegliche Verwendung, Veroffentlichung, Weiterleitung,
> Abschrift oder jeglicher Druck dieser E-Mail ist strengstens untersagt.
> Weder die SEEBURGER AG noch der Absender (Frederic Bitsch)
> ubernehmen die Haftung fur Viren; es obliegt Ihrer Verantwortung,
> die E-Mail und deren Anhange (0) auf Viren zu prufen.
>
> The present email addresses only the addressee which it targets and
> may contain confidential material that may be protected by the
> professional secret. The opinions reflected herein are not necessarily
> the one of the SEEBURGER AG.
> If you are not the addressee, you have accidentally got this email and
> are not enabled to use, publish, forward, copy or print it in any way.
> Neither the SEEBURGER AG, nor the sender (Frederic Bitsch) are
> liable for viruses, being your own responsibility to check this email
> and its attachments (0) for this purpose.
> _________________________________________________________________________
>