<?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/"
		>
<channel>
	<title>Comments for Bogdan Mocanu</title>
	<atom:link href="http://bmocanu.ro/coding/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://bmocanu.ro/coding</link>
	<description>discussing about Java, coding and anything tech-related</description>
	<lastBuildDate>Thu, 03 May 2012 15:22:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>Comment on Access Spring context from static methods by Liviu Tudor</title>
		<link>http://bmocanu.ro/coding/387/access-spring-context-from-static-methods/#comment-584</link>
		<dc:creator>Liviu Tudor</dc:creator>
		<pubDate>Thu, 03 May 2012 15:22:46 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/coding/?p=387#comment-584</guid>
		<description>Thanks for the code and spring configs - just what I needed!
Keep up the good work!</description>
		<content:encoded><![CDATA[<p>Thanks for the code and spring configs &#8211; just what I needed!<br />
Keep up the good work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Combining JUnit Theories/Parameterized tests with Spring by Henrik Kaipe</title>
		<link>http://bmocanu.ro/coding/320/combining-junit-theoriesparameterized-tests-with-spring/#comment-567</link>
		<dc:creator>Henrik Kaipe</dc:creator>
		<pubDate>Wed, 15 Feb 2012 23:00:17 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/blog/?p=320#comment-567</guid>
		<description>If you use CallbackParams (instead of Parameterized) you can use the annotation ...

@WrappedRunner(SpringJUnit4ClassRunner.class)

... and you will have a parameterized Spring-test with transaction support. 

An example test-class can be found here:
http://callbackparams.svn.sourceforge.net/viewvc/callbackparams/trunk/junit4-tests/src/test/java/org/callbackparams/junit4/integration/TestSpringTransaction.java?revision=88&amp;view=markup</description>
		<content:encoded><![CDATA[<p>If you use CallbackParams (instead of Parameterized) you can use the annotation &#8230;</p>
<p>@WrappedRunner(SpringJUnit4ClassRunner.class)</p>
<p>&#8230; and you will have a parameterized Spring-test with transaction support. </p>
<p>An example test-class can be found here:<br />
<a href="http://callbackparams.svn.sourceforge.net/viewvc/callbackparams/trunk/junit4-tests/src/test/java/org/callbackparams/junit4/integration/TestSpringTransaction.java?revision=88&#038;view=markup" rel="nofollow">http://callbackparams.svn.sourceforge.net/viewvc/callbackparams/trunk/junit4-tests/src/test/java/org/callbackparams/junit4/integration/TestSpringTransaction.java?revision=88&#038;view=markup</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Combining JUnit Theories/Parameterized tests with Spring by Jan Goyvaerts</title>
		<link>http://bmocanu.ro/coding/320/combining-junit-theoriesparameterized-tests-with-spring/#comment-557</link>
		<dc:creator>Jan Goyvaerts</dc:creator>
		<pubDate>Thu, 05 Jan 2012 09:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/blog/?p=320#comment-557</guid>
		<description>Many thanks for sharing this !

Unfortunately it doesn&#039;t work when transactions are involved. Found this (http://www.javathinking.com/2011/09/junit-parameterized-test-with-spring-autowiring-and-transactions/) however which does work for transactions too.</description>
		<content:encoded><![CDATA[<p>Many thanks for sharing this !</p>
<p>Unfortunately it doesn&#8217;t work when transactions are involved. Found this (<a href="http://www.javathinking.com/2011/09/junit-parameterized-test-with-spring-autowiring-and-transactions/" rel="nofollow">http://www.javathinking.com/2011/09/junit-parameterized-test-with-spring-autowiring-and-transactions/</a>) however which does work for transactions too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on OAuth 2-legged model with Spring Security by Thusitha</title>
		<link>http://bmocanu.ro/coding/303/oauth-2legged-model-with-spring-security/#comment-555</link>
		<dc:creator>Thusitha</dc:creator>
		<pubDate>Sun, 01 Jan 2012 21:42:49 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/blog/?p=303#comment-555</guid>
		<description>Thanks for your implementation of two legged approach. 
ConsumerBasedAuthenticationHandler class was the most important bit to me..Thanks for that.I think Oauth2.0 will be released soon.I think it will offload some complexity with Oauth 1.0..
Thanks very much</description>
		<content:encoded><![CDATA[<p>Thanks for your implementation of two legged approach.<br />
ConsumerBasedAuthenticationHandler class was the most important bit to me..Thanks for that.I think Oauth2.0 will be released soon.I think it will offload some complexity with Oauth 1.0..<br />
Thanks very much</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Client for OAuth with Spring Security by Bogdan</title>
		<link>http://bmocanu.ro/coding/409/client-for-oauth-with-spring-security/#comment-504</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Sun, 04 Dec 2011 18:53:30 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/coding/?p=409#comment-504</guid>
		<description>Well, there is not much of a project to share other than what I copy pasted in the article. I used the Sparklr application as the OAuth enabled server. The client is composed of just one java class (the client) and the POM xml file (since it is a maven project). These 2 files are already in the article.</description>
		<content:encoded><![CDATA[<p>Well, there is not much of a project to share other than what I copy pasted in the article. I used the Sparklr application as the OAuth enabled server. The client is composed of just one java class (the client) and the POM xml file (since it is a maven project). These 2 files are already in the article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Client for OAuth with Spring Security by tatoo</title>
		<link>http://bmocanu.ro/coding/409/client-for-oauth-with-spring-security/#comment-491</link>
		<dc:creator>tatoo</dc:creator>
		<pubDate>Fri, 02 Dec 2011 10:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/coding/?p=409#comment-491</guid>
		<description>Could you share the entirely code project?</description>
		<content:encoded><![CDATA[<p>Could you share the entirely code project?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on OAuth 2-legged model with Spring Security by Bogdan</title>
		<link>http://bmocanu.ro/coding/303/oauth-2legged-model-with-spring-security/#comment-406</link>
		<dc:creator>Bogdan</dc:creator>
		<pubDate>Sun, 20 Nov 2011 13:12:54 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/blog/?p=303#comment-406</guid>
		<description>Thank you all for the comments on this article. Because this article contains an incorrect explanation of the OAuth 2Legged mode, I wrote a newer and (I hope) better article on this subject, available here: http://bmocanu.ro/coding/409/client-for-oauth-with-spring-security/.</description>
		<content:encoded><![CDATA[<p>Thank you all for the comments on this article. Because this article contains an incorrect explanation of the OAuth 2Legged mode, I wrote a newer and (I hope) better article on this subject, available here: <a href="http://bmocanu.ro/coding/409/client-for-oauth-with-spring-security/" rel="nofollow">http://bmocanu.ro/coding/409/client-for-oauth-with-spring-security/</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Client for OAuth with Spring Security by OAuth 2-legged model with Spring Security &#171; Bogdan Mocanu &#124; Coding</title>
		<link>http://bmocanu.ro/coding/409/client-for-oauth-with-spring-security/#comment-405</link>
		<dc:creator>OAuth 2-legged model with Spring Security &#171; Bogdan Mocanu &#124; Coding</dc:creator>
		<pubDate>Sun, 20 Nov 2011 13:10:32 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/coding/?p=409#comment-405</guid>
		<description>[...] mode of the OAuth protocol. Thanks to all the people that commented on this article, I wrote a new article, where the 2Legged mode is (I hope) better explained and where a better client for OAuth is implemented. This article is left here for historical [...]</description>
		<content:encoded><![CDATA[<p>[...] mode of the OAuth protocol. Thanks to all the people that commented on this article, I wrote a new article, where the 2Legged mode is (I hope) better explained and where a better client for OAuth is implemented. This article is left here for historical [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on OAuth 2-legged model with Spring Security by Client for OAuth with Spring Security &#171; Bogdan Mocanu &#124; Coding</title>
		<link>http://bmocanu.ro/coding/303/oauth-2legged-model-with-spring-security/#comment-404</link>
		<dc:creator>Client for OAuth with Spring Security &#171; Bogdan Mocanu &#124; Coding</dc:creator>
		<pubDate>Sun, 20 Nov 2011 12:53:15 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/blog/?p=303#comment-404</guid>
		<description>[...] one year ago I wrote an article in which I described how can one implement a client and a server that uses the OAuth security [...]</description>
		<content:encoded><![CDATA[<p>[...] one year ago I wrote an article in which I described how can one implement a client and a server that uses the OAuth security [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on OAuth 2-legged model with Spring Security by Muhammad Yousaf</title>
		<link>http://bmocanu.ro/coding/303/oauth-2legged-model-with-spring-security/#comment-403</link>
		<dc:creator>Muhammad Yousaf</dc:creator>
		<pubDate>Mon, 14 Nov 2011 20:01:46 +0000</pubDate>
		<guid isPermaLink="false">http://bmocanu.ro/blog/?p=303#comment-403</guid>
		<description>Following are the changes I have made to make it OAuth 2 legged implementation

package com.sequent.resources;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.GrantedAuthorityImpl;
import org.springframework.security.oauth.common.OAuthException;
import org.springframework.security.oauth.common.signature.SharedConsumerSecret;
import org.springframework.security.oauth.provider.BaseConsumerDetails;
import org.springframework.security.oauth.provider.ConsumerDetails;
import org.springframework.security.oauth.provider.ConsumerDetailsService;
import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.userdetails.UserDetailsService;
import org.springframework.security.userdetails.UsernameNotFoundException;

public class ConsumerDetailsServiceImpl implements ConsumerDetailsService, UserDetailsService {
	 
    private Map consumers;
 
    public ConsumerDetailsServiceImpl() {
        consumers = new HashMap();
        consumers.put( &quot;consumer-k1&quot;, createConsumerDetails( &quot;consumer-k1&quot;, &quot;consumer-n1&quot;, &quot;consumer-secret1&quot; ) );
        consumers.put( &quot;consumer-k2&quot;, createConsumerDetails( &quot;consumer-k2&quot;, &quot;consumer-n2&quot;, &quot;consumer-secret2&quot; ) );
    }
 
    private ConsumerDetails createConsumerDetails( String consumerKey, String consumerName, String consumerSecret ) {
        SharedConsumerSecret secret = new SharedConsumerSecret( consumerSecret );
 
        BaseConsumerDetails bcd = new BaseConsumerDetails();
        bcd.setConsumerKey( consumerKey );
        bcd.setConsumerName( consumerName );
        bcd.setSignatureSecret( secret );
        bcd.setAuthorities( new GrantedAuthority[] { new GrantedAuthorityImpl( &quot;ROLE_OAUTH_USER&quot; ) } );
 
        // set this to false to enable the 2legged OAuth model
        // see http://spring-security-oauth.codehaus.org/twolegged.html
        bcd.setRequiredToObtainAuthenticatedToken( false );
 
        return bcd;
    }
 
    @Override
    public ConsumerDetails loadConsumerByConsumerKey( String key ) throws OAuthException {
        System.out.println( &quot;Request received to find consumer for consumerKey=[&quot; + key + &quot;]&quot; );
        ConsumerDetails consumer = consumers.get( key );
        if ( consumer == null ) {
            System.out.println( &quot;Result: No consumer found for [&quot; + key + &quot;]&quot;  );
            throw new OAuthException( &quot;No consumer found for key &quot; + key );
        }
            
        System.out.println( &quot;Result: Found consumer [&quot; + consumer.getConsumerName() + &quot;]&quot; );
        return consumer;
    }
 
    @Override
    public UserDetails loadUserByUsername( String username ) throws UsernameNotFoundException, DataAccessException {
        throw new UnsupportedOperationException();
    }
 
}

------------------------------------------------------------------------
web.xml
-----------------------------------------------------------------------
	
        springSecurityFilterChain
        org.springframework.web.filter.DelegatingFilterProxy
    
    
        springSecurityFilterChain
        /*
    
 
    
        org.springframework.web.context.ContextLoaderListener
    

---------------------------------------------------------------------------
applicationContext.xml
---------------------------------------------------------------------------


 
  
  
 
  
    
  
 
  
 
  
 
 

-------------------------------------------------------------------------
Client Test
--------------------------------------------------------------------------
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.io.IOUtils;
import org.springframework.security.oauth.common.signature.SharedConsumerSecret;
import org.springframework.security.oauth.common.signature.SignatureSecret;
import org.springframework.security.oauth.consumer.BaseProtectedResourceDetails;
import org.springframework.security.oauth.consumer.CoreOAuthConsumerSupport;
import org.springframework.security.oauth.consumer.OAuthConsumerSupport;
import org.springframework.security.oauth.consumer.OAuthRequestFailedException;
import org.springframework.security.oauth.consumer.ProtectedResourceDetails;
import org.springframework.security.oauth.consumer.ProtectedResourceDetailsService;
import org.springframework.security.oauth.consumer.net.DefaultOAuthURLStreamHandlerFactory;
import org.springframework.security.oauth.consumer.token.OAuthConsumerToken;

public class ApiConsumer {
	 
    private static final String SERVER_URL = &quot;http://localhost:8080/sequent-api-public&quot;;
 
    private static final String SERVER_URL_RESOURCE = SERVER_URL + &quot;/sqms/v1/walletmetadata/getTermsOfUse&quot;;
 
    private static final String CONSUMER_KEY = &quot;consumer-k1&quot;;
    private static final String CONSUMER_SECRET = &quot;consumer-secret1&quot;;
    private static final String SIGNATURE_METHOD = &quot;HMAC-SHA1&quot;;
 
    private static final String RESOURCE_ID = &quot;PublicApi&quot;;
    private static OAuthConsumerSupport consumerSupport;
 
 
    public static void main( String[] args ) throws HttpException, IOException {
        CoreOAuthConsumerSupport localConsumerSupport = new CoreOAuthConsumerSupport();
        localConsumerSupport.setStreamHandlerFactory( new DefaultOAuthURLStreamHandlerFactory() );
        localConsumerSupport.setProtectedResourceDetailsService( new ProtectedResourceDetailsService() {
 
            @Override
            public ProtectedResourceDetails loadProtectedResourceDetailsById( String id ) throws IllegalArgumentException {
                SignatureSecret secret = new SharedConsumerSecret( CONSUMER_SECRET );
 
                BaseProtectedResourceDetails result = new BaseProtectedResourceDetails();
                result.setConsumerKey( CONSUMER_KEY );
                result.setSharedSecret( secret );
                result.setSignatureMethod( SIGNATURE_METHOD );
                result.setUse10a( false );
                return result;
            }
        } );
 
        consumerSupport = localConsumerSupport;
 
        getProtectedResource();
    }
 
    public static void getProtectedResource() throws OAuthRequestFailedException, IOException {
        System.out.println( &quot;OAUTH: Getting protected resource&quot; );
 
        OAuthConsumerToken accessToken = new OAuthConsumerToken();        
        accessToken.setResourceId(RESOURCE_ID);
        InputStream is = consumerSupport.readProtectedResource( new URL( SERVER_URL_RESOURCE ), accessToken, &quot;GET&quot; );
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy( is, baos );
        is.close();
        baos.close();
 
        System.out.println( &quot;OAUTH: Resource : &quot; + new String( Arrays.copyOf( baos.toByteArray(), 30 ) ) );
    }
 
}</description>
		<content:encoded><![CDATA[<p>Following are the changes I have made to make it OAuth 2 legged implementation</p>
<p>package com.sequent.resources;</p>
<p>import java.util.HashMap;<br />
import java.util.Map;</p>
<p>import org.springframework.dao.DataAccessException;<br />
import org.springframework.security.GrantedAuthority;<br />
import org.springframework.security.GrantedAuthorityImpl;<br />
import org.springframework.security.oauth.common.OAuthException;<br />
import org.springframework.security.oauth.common.signature.SharedConsumerSecret;<br />
import org.springframework.security.oauth.provider.BaseConsumerDetails;<br />
import org.springframework.security.oauth.provider.ConsumerDetails;<br />
import org.springframework.security.oauth.provider.ConsumerDetailsService;<br />
import org.springframework.security.userdetails.UserDetails;<br />
import org.springframework.security.userdetails.UserDetailsService;<br />
import org.springframework.security.userdetails.UsernameNotFoundException;</p>
<p>public class ConsumerDetailsServiceImpl implements ConsumerDetailsService, UserDetailsService {</p>
<p>    private Map consumers;</p>
<p>    public ConsumerDetailsServiceImpl() {<br />
        consumers = new HashMap();<br />
        consumers.put( &#8220;consumer-k1&#8243;, createConsumerDetails( &#8220;consumer-k1&#8243;, &#8220;consumer-n1&#8243;, &#8220;consumer-secret1&#8243; ) );<br />
        consumers.put( &#8220;consumer-k2&#8243;, createConsumerDetails( &#8220;consumer-k2&#8243;, &#8220;consumer-n2&#8243;, &#8220;consumer-secret2&#8243; ) );<br />
    }</p>
<p>    private ConsumerDetails createConsumerDetails( String consumerKey, String consumerName, String consumerSecret ) {<br />
        SharedConsumerSecret secret = new SharedConsumerSecret( consumerSecret );</p>
<p>        BaseConsumerDetails bcd = new BaseConsumerDetails();<br />
        bcd.setConsumerKey( consumerKey );<br />
        bcd.setConsumerName( consumerName );<br />
        bcd.setSignatureSecret( secret );<br />
        bcd.setAuthorities( new GrantedAuthority[] { new GrantedAuthorityImpl( &#8220;ROLE_OAUTH_USER&#8221; ) } );</p>
<p>        // set this to false to enable the 2legged OAuth model<br />
        // see <a href="http://spring-security-oauth.codehaus.org/twolegged.html" rel="nofollow">http://spring-security-oauth.codehaus.org/twolegged.html</a><br />
        bcd.setRequiredToObtainAuthenticatedToken( false );</p>
<p>        return bcd;<br />
    }</p>
<p>    @Override<br />
    public ConsumerDetails loadConsumerByConsumerKey( String key ) throws OAuthException {<br />
        System.out.println( &#8220;Request received to find consumer for consumerKey=[" + key + "]&#8221; );<br />
        ConsumerDetails consumer = consumers.get( key );<br />
        if ( consumer == null ) {<br />
            System.out.println( &#8220;Result: No consumer found for [" + key + "]&#8221;  );<br />
            throw new OAuthException( &#8220;No consumer found for key &#8221; + key );<br />
        }</p>
<p>        System.out.println( &#8220;Result: Found consumer [" + consumer.getConsumerName() + "]&#8221; );<br />
        return consumer;<br />
    }</p>
<p>    @Override<br />
    public UserDetails loadUserByUsername( String username ) throws UsernameNotFoundException, DataAccessException {<br />
        throw new UnsupportedOperationException();<br />
    }</p>
<p>}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
web.xml<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>        springSecurityFilterChain<br />
        org.springframework.web.filter.DelegatingFilterProxy</p>
<p>        springSecurityFilterChain<br />
        /*</p>
<p>        org.springframework.web.context.ContextLoaderListener</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
applicationContext.xml<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Client Test<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
import java.io.ByteArrayOutputStream;<br />
import java.io.IOException;<br />
import java.io.InputStream;<br />
import java.net.URL;<br />
import java.util.Arrays;</p>
<p>import org.apache.commons.httpclient.HttpClient;<br />
import org.apache.commons.httpclient.HttpException;<br />
import org.apache.commons.httpclient.methods.PostMethod;<br />
import org.apache.commons.io.IOUtils;<br />
import org.springframework.security.oauth.common.signature.SharedConsumerSecret;<br />
import org.springframework.security.oauth.common.signature.SignatureSecret;<br />
import org.springframework.security.oauth.consumer.BaseProtectedResourceDetails;<br />
import org.springframework.security.oauth.consumer.CoreOAuthConsumerSupport;<br />
import org.springframework.security.oauth.consumer.OAuthConsumerSupport;<br />
import org.springframework.security.oauth.consumer.OAuthRequestFailedException;<br />
import org.springframework.security.oauth.consumer.ProtectedResourceDetails;<br />
import org.springframework.security.oauth.consumer.ProtectedResourceDetailsService;<br />
import org.springframework.security.oauth.consumer.net.DefaultOAuthURLStreamHandlerFactory;<br />
import org.springframework.security.oauth.consumer.token.OAuthConsumerToken;</p>
<p>public class ApiConsumer {</p>
<p>    private static final String SERVER_URL = &#8220;http://localhost:8080/sequent-api-public&#8221;;</p>
<p>    private static final String SERVER_URL_RESOURCE = SERVER_URL + &#8220;/sqms/v1/walletmetadata/getTermsOfUse&#8221;;</p>
<p>    private static final String CONSUMER_KEY = &#8220;consumer-k1&#8243;;<br />
    private static final String CONSUMER_SECRET = &#8220;consumer-secret1&#8243;;<br />
    private static final String SIGNATURE_METHOD = &#8220;HMAC-SHA1&#8243;;</p>
<p>    private static final String RESOURCE_ID = &#8220;PublicApi&#8221;;<br />
    private static OAuthConsumerSupport consumerSupport;</p>
<p>    public static void main( String[] args ) throws HttpException, IOException {<br />
        CoreOAuthConsumerSupport localConsumerSupport = new CoreOAuthConsumerSupport();<br />
        localConsumerSupport.setStreamHandlerFactory( new DefaultOAuthURLStreamHandlerFactory() );<br />
        localConsumerSupport.setProtectedResourceDetailsService( new ProtectedResourceDetailsService() {</p>
<p>            @Override<br />
            public ProtectedResourceDetails loadProtectedResourceDetailsById( String id ) throws IllegalArgumentException {<br />
                SignatureSecret secret = new SharedConsumerSecret( CONSUMER_SECRET );</p>
<p>                BaseProtectedResourceDetails result = new BaseProtectedResourceDetails();<br />
                result.setConsumerKey( CONSUMER_KEY );<br />
                result.setSharedSecret( secret );<br />
                result.setSignatureMethod( SIGNATURE_METHOD );<br />
                result.setUse10a( false );<br />
                return result;<br />
            }<br />
        } );</p>
<p>        consumerSupport = localConsumerSupport;</p>
<p>        getProtectedResource();<br />
    }</p>
<p>    public static void getProtectedResource() throws OAuthRequestFailedException, IOException {<br />
        System.out.println( &#8220;OAUTH: Getting protected resource&#8221; );</p>
<p>        OAuthConsumerToken accessToken = new OAuthConsumerToken();<br />
        accessToken.setResourceId(RESOURCE_ID);<br />
        InputStream is = consumerSupport.readProtectedResource( new URL( SERVER_URL_RESOURCE ), accessToken, &#8220;GET&#8221; );<br />
        ByteArrayOutputStream baos = new ByteArrayOutputStream();<br />
        IOUtils.copy( is, baos );<br />
        is.close();<br />
        baos.close();</p>
<p>        System.out.println( &#8220;OAUTH: Resource : &#8221; + new String( Arrays.copyOf( baos.toByteArray(), 30 ) ) );<br />
    }</p>
<p>}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

