You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Martin Steffen Correa <ma...@gmail.com> on 2013/01/15 22:19:30 UTC
WS-Security: How to insert two Security elements in SOAP header?
Hello,
I'm new to CXF and I want to create a SOAP message with two Security
elements as follow:
<soap:Header>
<wsse:Security soap:actor="actor1" >
...
</wsse:Security>
<wsse:Security soap:actor="actor2" >
...
</wsse:Security>
</soap:Header>
How I can generate a message with two Security elements in SOAP header?
I configure my client with Spring:
<jaxws:client id="helloClient">
<jaxws:outInterceptors>
<ref bean="ut_actor1" />
<ref bean="ut_actor2" />
</jaxws:outInterceptors>
</jaxws:client>
Both ut_actor1 and ut_actor2 are
org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor interceptors,
but only one interceptor is executed, it seems that is not possible to
define two interceptors of the same type.
Thanks,
Martin Steffen.
Re: WS-Security: How to insert two Security elements in SOAP
header?
Posted by manoj kumar <ma...@yahoo.com>.
Hi Martin,
I'm trying to do the same use case you reported.
I need to set the default actor with some username token and add another
specific actor with some other username token.
I'm trying to set the interceptors to the JaxWsProxyFactoryBean in the
context xml.
<property name="outInterceptors">
<list>
<ref bean="wss4jOutInterceptor"/>
<ref bean="customWss4jOutInterceptor"/>
</list>
</property>
public CustomWSS4JOutInterceptor(Map<String, Object> props) {
super(props);
id = getClass().getName();
id += System.identityHashCode(this);
}
public String getId() {
return id;
}
With the above stuff, my custom interceptor is still not added to the
header.
Could you provide some details on how you customized the interceptor and
what configuration was added to the client to get this custom interceptor
added to the soap header.
Any help is much appreciated.
Thanks,
Manoj
--
View this message in context: http://cxf.547215.n5.nabble.com/WS-Security-How-to-insert-two-Security-elements-in-SOAP-header-tp5721679p5728516.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: WS-Security: How to insert two Security elements in SOAP header?
Posted by Martin Steffen Correa <ma...@gmail.com>.
Hi,
I did what you said and it worked perfectly,
Thanks!
On 17 January 2013 11:25, Andrei Shakirin <as...@talend.com> wrote:
> Hi,
>
> > -----Original Message-----
> > From: Martin Steffen Correa [mailto:martins1930@gmail.com]
> > Sent: Mittwoch, 16. Januar 2013 22:00
> > To: users@cxf.apache.org
> > Subject: Re: WS-Security: How to insert two Security elements in SOAP
> > header?
> >
> > Hi Glen,
> >
> > Thanks for your help,
> > I read your posts 52 and 53,
> > but i dont want to manually create the Security element (and
> > UsernameToken element), because this is already implemented in actions
> > (e.g.
> > org.apache.ws.security.action.UsernameTokenAction).
> > Therefore, I inspected the cxf code and, I find that is not allowed to
> define
> > two interceptors with the same id in the same phase.
> > In the class org.apache.cxf.phase.PhaseInterceptorChain (
> > http://svn.apache.org/viewvc/cxf/tags/cxf-
> > 2.7.2/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?
> > revision=1429139&view=markup)
> > in the insertInterceptor method, see:
> > if (!force && cmpId.equals(id)) {
> > // interceptor is already in chain
> > return;
> > }
> >
> > This means that I can not have two WSS4JOutInterceptor in the chain.
> > Due to the above,
> > I implemented the class: MyWSSecurityInterceptor (
> > https://github.com/martins1930/samples/blob/master/gradle/WSCxf/WSCli
> > ent/src/main/java/org/apache/cxf/ws/security/wss4j/uy/MyWSSecurityInte
> > rceptor.java)
> > This class is a copy of
> org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor
> > ,
> > except that MyWSSecurityInterceptor always returns a different ID
> > (overwrote the method getId()).
> > With this change, you can include multiple MyWSSecurityInterceptor in the
> > chain, as you can see in my Spring conf:
> > https://github.com/martins1930/samples/blob/master/gradle/WSCxf/WSCli
> > ent/src/main/resources/client-bean.xml
> > .
> >
> > I think that would be nice,
> > that cxf team modify WSS4JOutInterceptor class to return a different ID
> each
> > time.
> > In this way support multiple WSS4JOutInterceptor in a chain.
>
> I do not think that it is good idea to update WSS4JOutInterceptor in a way
> to add multiple instances into chain, because it breaks a lot of existing
> code that rely on fact that WSS4JOutInterceptor can be added only once.
>
> However you can subclass WSS4JOutInterceptor, override getId() method and
> add other constructor:
>
> public CustomWSS4JOutInterceptor(boolean uniqueId) {
> super();
> id = getClass().getName();
> if (uniqueId) {
> id += System.identityHashCode(this);
> }
> }
>
> It allows to add multiple interceptor instances into chain.
>
> Andrei.
>
>
> >
> > Martín.
> >
> >
> >
> >
> > On 15 January 2013 21:00, Glen Mazza <gm...@talend.com> wrote:
> >
> > > If you're doing UsernameToken you might be able to manually create the
> > > headers (it's possible they won't be too complex): Links #52 and #53
> here:
> > >
> > http://www.jroller.com/gmazza/**entry/blog_article_index<http://www.jr
> > oller.com/gmazza/entry/blog_article_index>, in particular the links at
> the
> > bottom of #53, provide additional options.
> > >
> > > Glen
> > >
> > >
> > > On 01/15/2013 04:19 PM, Martin Steffen Correa wrote:
> > >
> > >> Hello,
> > >>
> > >> I'm new to CXF and I want to create a SOAP message with two Security
> > >> elements as follow:
> > >>
> > >> <soap:Header>
> > >> <wsse:Security soap:actor="actor1" >
> > >> ...
> > >> </wsse:Security>
> > >> <wsse:Security soap:actor="actor2" >
> > >> ...
> > >> </wsse:Security>
> > >> </soap:Header>
> > >>
> > >> How I can generate a message with two Security elements in SOAP
> > header?
> > >>
> > >> I configure my client with Spring:
> > >> <jaxws:client id="helloClient">
> > >> <jaxws:outInterceptors>
> > >> <ref bean="ut_actor1" />
> > >> <ref bean="ut_actor2" />
> > >> </jaxws:outInterceptors>
> > >> </jaxws:client>
> > >>
> > >> Both ut_actor1 and ut_actor2 are
> > >> org.apache.cxf.ws.security.**wss4j.WSS4JOutInterceptor interceptors,
> > >> but only one interceptor is executed, it seems that is not possible
> > >> to define two interceptors of the same type.
> > >>
> > >> Thanks,
> > >> Martin Steffen.
> > >>
> > >>
> > >
> > > --
> > > Glen Mazza
> > > Talend Community Coders - coders.talend.com
> > > blog: www.jroller.com/gmazza
> > >
> > >
>
RE: WS-Security: How to insert two Security elements in SOAP header?
Posted by Andrei Shakirin <as...@talend.com>.
Hi,
> -----Original Message-----
> From: Martin Steffen Correa [mailto:martins1930@gmail.com]
> Sent: Mittwoch, 16. Januar 2013 22:00
> To: users@cxf.apache.org
> Subject: Re: WS-Security: How to insert two Security elements in SOAP
> header?
>
> Hi Glen,
>
> Thanks for your help,
> I read your posts 52 and 53,
> but i dont want to manually create the Security element (and
> UsernameToken element), because this is already implemented in actions
> (e.g.
> org.apache.ws.security.action.UsernameTokenAction).
> Therefore, I inspected the cxf code and, I find that is not allowed to define
> two interceptors with the same id in the same phase.
> In the class org.apache.cxf.phase.PhaseInterceptorChain (
> http://svn.apache.org/viewvc/cxf/tags/cxf-
> 2.7.2/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?
> revision=1429139&view=markup)
> in the insertInterceptor method, see:
> if (!force && cmpId.equals(id)) {
> // interceptor is already in chain
> return;
> }
>
> This means that I can not have two WSS4JOutInterceptor in the chain.
> Due to the above,
> I implemented the class: MyWSSecurityInterceptor (
> https://github.com/martins1930/samples/blob/master/gradle/WSCxf/WSCli
> ent/src/main/java/org/apache/cxf/ws/security/wss4j/uy/MyWSSecurityInte
> rceptor.java)
> This class is a copy of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor
> ,
> except that MyWSSecurityInterceptor always returns a different ID
> (overwrote the method getId()).
> With this change, you can include multiple MyWSSecurityInterceptor in the
> chain, as you can see in my Spring conf:
> https://github.com/martins1930/samples/blob/master/gradle/WSCxf/WSCli
> ent/src/main/resources/client-bean.xml
> .
>
> I think that would be nice,
> that cxf team modify WSS4JOutInterceptor class to return a different ID each
> time.
> In this way support multiple WSS4JOutInterceptor in a chain.
I do not think that it is good idea to update WSS4JOutInterceptor in a way to add multiple instances into chain, because it breaks a lot of existing code that rely on fact that WSS4JOutInterceptor can be added only once.
However you can subclass WSS4JOutInterceptor, override getId() method and add other constructor:
public CustomWSS4JOutInterceptor(boolean uniqueId) {
super();
id = getClass().getName();
if (uniqueId) {
id += System.identityHashCode(this);
}
}
It allows to add multiple interceptor instances into chain.
Andrei.
>
> Martín.
>
>
>
>
> On 15 January 2013 21:00, Glen Mazza <gm...@talend.com> wrote:
>
> > If you're doing UsernameToken you might be able to manually create the
> > headers (it's possible they won't be too complex): Links #52 and #53 here:
> >
> http://www.jroller.com/gmazza/**entry/blog_article_index<http://www.jr
> oller.com/gmazza/entry/blog_article_index>, in particular the links at the
> bottom of #53, provide additional options.
> >
> > Glen
> >
> >
> > On 01/15/2013 04:19 PM, Martin Steffen Correa wrote:
> >
> >> Hello,
> >>
> >> I'm new to CXF and I want to create a SOAP message with two Security
> >> elements as follow:
> >>
> >> <soap:Header>
> >> <wsse:Security soap:actor="actor1" >
> >> ...
> >> </wsse:Security>
> >> <wsse:Security soap:actor="actor2" >
> >> ...
> >> </wsse:Security>
> >> </soap:Header>
> >>
> >> How I can generate a message with two Security elements in SOAP
> header?
> >>
> >> I configure my client with Spring:
> >> <jaxws:client id="helloClient">
> >> <jaxws:outInterceptors>
> >> <ref bean="ut_actor1" />
> >> <ref bean="ut_actor2" />
> >> </jaxws:outInterceptors>
> >> </jaxws:client>
> >>
> >> Both ut_actor1 and ut_actor2 are
> >> org.apache.cxf.ws.security.**wss4j.WSS4JOutInterceptor interceptors,
> >> but only one interceptor is executed, it seems that is not possible
> >> to define two interceptors of the same type.
> >>
> >> Thanks,
> >> Martin Steffen.
> >>
> >>
> >
> > --
> > Glen Mazza
> > Talend Community Coders - coders.talend.com
> > blog: www.jroller.com/gmazza
> >
> >
Re: WS-Security: How to insert two Security elements in SOAP header?
Posted by Martin Steffen Correa <ma...@gmail.com>.
Hi Glen,
Thanks for your help,
I read your posts 52 and 53,
but i dont want to manually create the Security element (and UsernameToken
element), because this is already implemented in actions (e.g.
org.apache.ws.security.action.UsernameTokenAction).
Therefore, I inspected the cxf code and,
I find that is not allowed to define two interceptors with the same id in
the same phase.
In the class org.apache.cxf.phase.PhaseInterceptorChain (
http://svn.apache.org/viewvc/cxf/tags/cxf-2.7.2/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?revision=1429139&view=markup)
in the insertInterceptor method, see:
if (!force && cmpId.equals(id)) {
// interceptor is already in chain
return;
}
This means that I can not have two WSS4JOutInterceptor in the chain.
Due to the above,
I implemented the class: MyWSSecurityInterceptor (
https://github.com/martins1930/samples/blob/master/gradle/WSCxf/WSClient/src/main/java/org/apache/cxf/ws/security/wss4j/uy/MyWSSecurityInterceptor.java)
This class is a copy of org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor
,
except that MyWSSecurityInterceptor always returns a different ID
(overwrote the
method getId()).
With this change, you can include multiple MyWSSecurityInterceptor in the
chain,
as you can see in my Spring conf:
https://github.com/martins1930/samples/blob/master/gradle/WSCxf/WSClient/src/main/resources/client-bean.xml
.
I think that would be nice,
that cxf team modify WSS4JOutInterceptor class to return a different ID each
time.
In this way support multiple WSS4JOutInterceptor in a chain.
Martín.
On 15 January 2013 21:00, Glen Mazza <gm...@talend.com> wrote:
> If you're doing UsernameToken you might be able to manually create the
> headers (it's possible they won't be too complex): Links #52 and #53 here:
> http://www.jroller.com/gmazza/**entry/blog_article_index<http://www.jroller.com/gmazza/entry/blog_article_index>, in particular the links at the bottom of #53, provide additional options.
>
> Glen
>
>
> On 01/15/2013 04:19 PM, Martin Steffen Correa wrote:
>
>> Hello,
>>
>> I'm new to CXF and I want to create a SOAP message with two Security
>> elements as follow:
>>
>> <soap:Header>
>> <wsse:Security soap:actor="actor1" >
>> ...
>> </wsse:Security>
>> <wsse:Security soap:actor="actor2" >
>> ...
>> </wsse:Security>
>> </soap:Header>
>>
>> How I can generate a message with two Security elements in SOAP header?
>>
>> I configure my client with Spring:
>> <jaxws:client id="helloClient">
>> <jaxws:outInterceptors>
>> <ref bean="ut_actor1" />
>> <ref bean="ut_actor2" />
>> </jaxws:outInterceptors>
>> </jaxws:client>
>>
>> Both ut_actor1 and ut_actor2 are
>> org.apache.cxf.ws.security.**wss4j.WSS4JOutInterceptor interceptors,
>> but only one interceptor is executed, it seems that is not possible to
>> define two interceptors of the same type.
>>
>> Thanks,
>> Martin Steffen.
>>
>>
>
> --
> Glen Mazza
> Talend Community Coders - coders.talend.com
> blog: www.jroller.com/gmazza
>
>
Re: WS-Security: How to insert two Security elements in SOAP header?
Posted by Glen Mazza <gm...@talend.com>.
If you're doing UsernameToken you might be able to manually create the
headers (it's possible they won't be too complex): Links #52 and #53
here: http://www.jroller.com/gmazza/entry/blog_article_index , in
particular the links at the bottom of #53, provide additional options.
Glen
On 01/15/2013 04:19 PM, Martin Steffen Correa wrote:
> Hello,
>
> I'm new to CXF and I want to create a SOAP message with two Security
> elements as follow:
>
> <soap:Header>
> <wsse:Security soap:actor="actor1" >
> ...
> </wsse:Security>
> <wsse:Security soap:actor="actor2" >
> ...
> </wsse:Security>
> </soap:Header>
>
> How I can generate a message with two Security elements in SOAP header?
>
> I configure my client with Spring:
> <jaxws:client id="helloClient">
> <jaxws:outInterceptors>
> <ref bean="ut_actor1" />
> <ref bean="ut_actor2" />
> </jaxws:outInterceptors>
> </jaxws:client>
>
> Both ut_actor1 and ut_actor2 are
> org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor interceptors,
> but only one interceptor is executed, it seems that is not possible to
> define two interceptors of the same type.
>
> Thanks,
> Martin Steffen.
>
--
Glen Mazza
Talend Community Coders - coders.talend.com
blog: www.jroller.com/gmazza