<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: CXF WS-Security using JSR 181 + Interceptor Annotations (XFire Migration)</title>
	<atom:link href="http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/feed/" rel="self" type="application/rss+xml" />
	<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/</link>
	<description>Because programming is depressing</description>
	<lastBuildDate>Thu, 05 Nov 2009 23:29:15 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: morg r</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-810</link>
		<dc:creator>morg r</dc:creator>
		<pubDate>Fri, 21 Nov 2008 22:11:01 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-810</guid>
		<description>Thanks for the fast response. That&#039;s what I thought. So, by calling setPassword() it looks like I&#039;m essentially telling WS-Security &quot;this user is authenticated&quot;, even though it&#039;s not. That&#039;s not a problem for me since I&#039;m using Spring Security. So I don&#039;t need to look up a password in the database in the interceptor - Spring will do that for me once the request goes through. 

I&#039;ve implemented everything you show above, plus I added this to ValidateUserTokenInterceptor, which I found at http://www.jroller.com/wookets/entry/cxf_acegi_ws_security_acegi


if (userTokenValidated) {
	HttpServletRequest request = (HttpServletRequest) message.get(&quot;HTTP.REQUEST&quot;);
	request.getSession(true).getId(); // necessary hack

	// authenticate with acegi
	final UsernamePasswordAuthenticationToken authReq = 
		new UsernamePasswordAuthenticationToken(principal.getName(), principal
			.getPassword());

	// message.HTTP_REQUEST_METHOD
	authReq.setDetails(new WebAuthenticationDetails(request));

	SecurityContextHolder.getContext().setAuthentication(authReq);
}

It looks like I&#039;m just using WS-Security to pass through a username and password then, since I don&#039;t see any more graceful way of telling WS-Security or CXF to use our Spring&#039;s  security configuration. Do you see any limitations or concerns with my approach? 

Thanks</description>
		<content:encoded><![CDATA[<p>Thanks for the fast response. That&#8217;s what I thought. So, by calling setPassword() it looks like I&#8217;m essentially telling WS-Security &#8220;this user is authenticated&#8221;, even though it&#8217;s not. That&#8217;s not a problem for me since I&#8217;m using Spring Security. So I don&#8217;t need to look up a password in the database in the interceptor &#8211; Spring will do that for me once the request goes through. </p>
<p>I&#8217;ve implemented everything you show above, plus I added this to ValidateUserTokenInterceptor, which I found at <a href="http://www.jroller.com/wookets/entry/cxf_acegi_ws_security_acegi" rel="nofollow">http://www.jroller.com/wookets/entry/cxf_acegi_ws_security_acegi</a></p>
<p>if (userTokenValidated) {<br />
	HttpServletRequest request = (HttpServletRequest) message.get(&#8220;HTTP.REQUEST&#8221;);<br />
	request.getSession(true).getId(); // necessary hack</p>
<p>	// authenticate with acegi<br />
	final UsernamePasswordAuthenticationToken authReq =<br />
		new UsernamePasswordAuthenticationToken(principal.getName(), principal<br />
			.getPassword());</p>
<p>	// message.HTTP_REQUEST_METHOD<br />
	authReq.setDetails(new WebAuthenticationDetails(request));</p>
<p>	SecurityContextHolder.getContext().setAuthentication(authReq);<br />
}</p>
<p>It looks like I&#8217;m just using WS-Security to pass through a username and password then, since I don&#8217;t see any more graceful way of telling WS-Security or CXF to use our Spring&#8217;s  security configuration. Do you see any limitations or concerns with my approach? </p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arsenalist</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-809</link>
		<dc:creator>Arsenalist</dc:creator>
		<pubDate>Fri, 21 Nov 2008 21:37:47 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-809</guid>
		<description>The PasswordHandler is where you verify whether the password passed in through WS-Security is in fact the correct one.  Only if its correct do you make a call to pc.setPassword(...)... Here&#039;s an example which checks against a datbase:


&lt;code&gt;
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
String id = pc.getIdentifer();
username.set(id);
User user = userManager.getUserByUsername(id);
if (user != null) {
&#160;&#160;&#160;&#160;pc.setPassword(user.getPassword());
&#160;&#160;&#160;&#160;userData.set(user);
} else {
&#160;&#160;&#160;&#160;throw new RuntimeException(&quot;Invalid Credentials&quot;);
}
&lt;/code&gt;

</description>
		<content:encoded><![CDATA[<p>The PasswordHandler is where you verify whether the password passed in through WS-Security is in fact the correct one.  Only if its correct do you make a call to pc.setPassword(&#8230;)&#8230; Here&#8217;s an example which checks against a datbase:</p>
<p><code><br />
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];<br />
String id = pc.getIdentifer();<br />
username.set(id);<br />
User user = userManager.getUserByUsername(id);<br />
if (user != null) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;pc.setPassword(user.getPassword());<br />
&nbsp;&nbsp;&nbsp;&nbsp;userData.set(user);<br />
} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;throw new RuntimeException("Invalid Credentials");<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: morg r</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-808</link>
		<dc:creator>morg r</dc:creator>
		<pubDate>Fri, 21 Nov 2008 21:30:17 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-808</guid>
		<description>This is an excellent example. Thank you! But in trying this out, I&#039;m wondering what the point of the PasswordHandler is. I integrated this example with Spring Security, and got it work but only while passing PasswordHandler to WSS4JInInterceptor. Even stranger, I couldn&#039;t create an empty handle() method. So my PasswordHandler now looks like this:

public class PasswordHandler implements CallbackHandler {
	public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
		WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
		pc.setPassword(pc.getPassword());
	}
}

Do you know why this is even needed? It&#039;s not doing anything useful. And all calls fail when I leave out this line from WSSecurityInterceptor:
 props.put(WSHandlerConstants.PW_CALLBACK_REF, new PasswordHandler());  

It works for me. But I&#039;d prefer not to have useless code in place.

Thanks!</description>
		<content:encoded><![CDATA[<p>This is an excellent example. Thank you! But in trying this out, I&#8217;m wondering what the point of the PasswordHandler is. I integrated this example with Spring Security, and got it work but only while passing PasswordHandler to WSS4JInInterceptor. Even stranger, I couldn&#8217;t create an empty handle() method. So my PasswordHandler now looks like this:</p>
<p>public class PasswordHandler implements CallbackHandler {<br />
	public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {<br />
		WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];<br />
		pc.setPassword(pc.getPassword());<br />
	}<br />
}</p>
<p>Do you know why this is even needed? It&#8217;s not doing anything useful. And all calls fail when I leave out this line from WSSecurityInterceptor:<br />
 props.put(WSHandlerConstants.PW_CALLBACK_REF, new PasswordHandler());  </p>
<p>It works for me. But I&#8217;d prefer not to have useless code in place.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bhoga Pappu</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-738</link>
		<dc:creator>Bhoga Pappu</dc:creator>
		<pubDate>Tue, 27 May 2008 19:13:49 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-738</guid>
		<description>I have implmented ClientPasswordCallback, ServerPasswordCallback and accordingly attached them with client side code and server side code.
However, when I run the client, it fails with the error &#039;Request does not contain Security Header&#039;
I don&#039;t know what I am doing wrong.</description>
		<content:encoded><![CDATA[<p>I have implmented ClientPasswordCallback, ServerPasswordCallback and accordingly attached them with client side code and server side code.<br />
However, when I run the client, it fails with the error &#8216;Request does not contain Security Header&#8217;<br />
I don&#8217;t know what I am doing wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nilantha</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-330</link>
		<dc:creator>Nilantha</dc:creator>
		<pubDate>Wed, 12 Mar 2008 15:14:01 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-330</guid>
		<description>Thanks for posting this,

I would like to add following...

for those who need to access Spring context in any part of the application including CallbackHanders, this would be helpful

http://www.mail-archive.com/axis-user@ws.apache.org/msg22148.html

please update if you come across any better way of doing that.

Thanks,
Nilantha</description>
		<content:encoded><![CDATA[<p>Thanks for posting this,</p>
<p>I would like to add following&#8230;</p>
<p>for those who need to access Spring context in any part of the application including CallbackHanders, this would be helpful</p>
<p><a href="http://www.mail-archive.com/axis-user@ws.apache.org/msg22148.html" rel="nofollow">http://www.mail-archive.com/axis-user@ws.apache.org/msg22148.html</a></p>
<p>please update if you come across any better way of doing that.</p>
<p>Thanks,<br />
Nilantha</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sai C</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-329</link>
		<dc:creator>Sai C</dc:creator>
		<pubDate>Tue, 11 Mar 2008 16:23:45 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-329</guid>
		<description>I am calling a .Net web service in Java (client)and used the JAXWsProxyFactoryBean by enabling the WSAddressFeature, however, my soap header does not contain a  though it prints an  element. Could somebody let me know how do I get wsa:action in soap header using CXF API.

Appreciate your help.

Regards,
Sai</description>
		<content:encoded><![CDATA[<p>I am calling a .Net web service in Java (client)and used the JAXWsProxyFactoryBean by enabling the WSAddressFeature, however, my soap header does not contain a  though it prints an  element. Could somebody let me know how do I get wsa:action in soap header using CXF API.</p>
<p>Appreciate your help.</p>
<p>Regards,<br />
Sai</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yulinxp</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-310</link>
		<dc:creator>yulinxp</dc:creator>
		<pubDate>Thu, 10 Jan 2008 15:45:37 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-310</guid>
		<description>It will handle PasswordDigest automatically.
For PasswordText, I have to do the comparison and throw exception.

public class ServerPasswordCallback implements CallbackHandler {
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];

        String strClientPwd = pc.getPassword();
        int usage = pc.getUsage();

        if(pc.getIdentifer().equals(&quot;joe&quot;)) {

        	String strServerPwd = &quot;password&quot;;

        	if(usage == WSPasswordCallback.USERNAME_TOKEN) {	//PasswordDigest
        	    pc.setPassword(strServerPwd);

        	}else if(usage == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {	//PasswordText
        	    pc.setPassword(strServerPwd);

        	    if(!strClientPwd.equalsIgnoreCase(strServerPwd)){	//DIY compare
        	    	throw new WSSecurityException(WSSecurityException.FAILED_AUTHENTICATION);
        	    }
        	}
        }
    }
}</description>
		<content:encoded><![CDATA[<p>It will handle PasswordDigest automatically.<br />
For PasswordText, I have to do the comparison and throw exception.</p>
<p>public class ServerPasswordCallback implements CallbackHandler {<br />
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {</p>
<p>        WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];</p>
<p>        String strClientPwd = pc.getPassword();<br />
        int usage = pc.getUsage();</p>
<p>        if(pc.getIdentifer().equals(&#8220;joe&#8221;)) {</p>
<p>        	String strServerPwd = &#8220;password&#8221;;</p>
<p>        	if(usage == WSPasswordCallback.USERNAME_TOKEN) {	//PasswordDigest<br />
        	    pc.setPassword(strServerPwd);</p>
<p>        	}else if(usage == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN) {	//PasswordText<br />
        	    pc.setPassword(strServerPwd);</p>
<p>        	    if(!strClientPwd.equalsIgnoreCase(strServerPwd)){	//DIY compare<br />
        	    	throw new WSSecurityException(WSSecurityException.FAILED_AUTHENTICATION);<br />
        	    }<br />
        	}<br />
        }<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arsenalist</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-327</link>
		<dc:creator>Arsenalist</dc:creator>
		<pubDate>Mon, 07 Jan 2008 17:45:45 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-327</guid>
		<description>I see what you&#039;re saying and maybe they&#039;ve changed the implementation on the server side however ValidateUserTokenInterceptor was present in the XFire samples and its use was recommended by the committers.  I think you also need to look at the source code for the WSS4J class UsernameTokenProcessor to learn more.

Have you tried the case where you specify an invalid username/password or a valid username but an invalid password? Do you still receive the SoapFault?</description>
		<content:encoded><![CDATA[<p>I see what you&#8217;re saying and maybe they&#8217;ve changed the implementation on the server side however ValidateUserTokenInterceptor was present in the XFire samples and its use was recommended by the committers.  I think you also need to look at the source code for the WSS4J class UsernameTokenProcessor to learn more.</p>
<p>Have you tried the case where you specify an invalid username/password or a valid username but an invalid password? Do you still receive the SoapFault?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yulinxp</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-328</link>
		<dc:creator>yulinxp</dc:creator>
		<pubDate>Mon, 07 Jan 2008 17:22:40 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-328</guid>
		<description>You mention:
Since WSS4J validates a UsernameToken only if it finds a security header we need to cover the case where no security header is specified.

In the following snippet from WSS4JInInterceptor.java
public void handleMessage(SoapMessage msg) throws Fault

if (wsResult == null) { // no security header found
 if (doAction == WSConstants.NO_SECURITY) {
    return;
 } else {
    LOG.warning(&quot;Request does not contain required Security header&quot;);
     throw new SoapFault(new Message(&quot;NO_SECURITY&quot;, LOG), version.getSender());
 }
}

If no security header found, a SoapFault is thrown. In my test, I set WS Security in server but not in client. And my client side does receive that SoapFault. So do we still need ValidateUserTokenInterceptor?</description>
		<content:encoded><![CDATA[<p>You mention:<br />
Since WSS4J validates a UsernameToken only if it finds a security header we need to cover the case where no security header is specified.</p>
<p>In the following snippet from WSS4JInInterceptor.java<br />
public void handleMessage(SoapMessage msg) throws Fault</p>
<p>if (wsResult == null) { // no security header found<br />
 if (doAction == WSConstants.NO_SECURITY) {<br />
    return;<br />
 } else {<br />
    LOG.warning(&#8220;Request does not contain required Security header&#8221;);<br />
     throw new SoapFault(new Message(&#8220;NO_SECURITY&#8221;, LOG), version.getSender());<br />
 }<br />
}</p>
<p>If no security header found, a SoapFault is thrown. In my test, I set WS Security in server but not in client. And my client side does receive that SoapFault. So do we still need ValidateUserTokenInterceptor?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nigel</title>
		<link>http://depressedprogrammer.wordpress.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-319</link>
		<dc:creator>Nigel</dc:creator>
		<pubDate>Sat, 10 Nov 2007 09:06:21 +0000</pubDate>
		<guid isPermaLink="false">http://arsenalist.com/2007/07/31/cxf-ws-security-using-jsr-181-interceptor-annotations-xfire-migration/#comment-319</guid>
		<description>&lt;a href=&quot;http://www.hpc.jcu.edu.au/projects/archer-data-activities/svn/MCATExtClientDemo/trunk/src/main/webapp/WEB-INF/clientBeans.xml&quot; title=&quot;clientBean.xml&quot; rel=&quot;nofollow&quot;&gt;Client Bean&lt;/a&gt;

Thanks</description>
		<content:encoded><![CDATA[<p><a href="http://www.hpc.jcu.edu.au/projects/archer-data-activities/svn/MCATExtClientDemo/trunk/src/main/webapp/WEB-INF/clientBeans.xml" title="clientBean.xml" rel="nofollow">Client Bean</a></p>
<p>Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
