<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3435429280123092588</id><updated>2024-10-24T16:55:19.619-07:00</updated><title type='text'>DNCodeFrags</title><subtitle type='html'>This blog is created with an intention of sharing my knowledge as a Java enterprise web application developer. I only have few years of experience as a developer and in my short career,I&#39;m grateful to those people who were kind enough to share their knowledge. So I thought to share some of my code fragments, which I found bit difficult to find in web. Hope these code fragments will help someone :)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dncodes.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3435429280123092588/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://dncodes.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16789505062816668313</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3435429280123092588.post-1119247869435481366</id><published>2012-06-17T06:13:00.002-07:00</published><updated>2012-06-17T06:13:45.648-07:00</updated><title type='text'>How to create a simple Maven 2 web project with Eclipse</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirbS1xFDq5FzRhu7hYKTt32urItC8tmJ_5PdaN7pCVGpTUAIAdHgz-FIIgzUwb6TZQtZraXlpItQzD9eZYvRWco_4HTGwxNJI88xexPT9-iCFvZQzfHjuXiJiuC1ABuaxUMZifC9saCMap/s1600/eclipse_IDE.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;130&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirbS1xFDq5FzRhu7hYKTt32urItC8tmJ_5PdaN7pCVGpTUAIAdHgz-FIIgzUwb6TZQtZraXlpItQzD9eZYvRWco_4HTGwxNJI88xexPT9-iCFvZQzfHjuXiJiuC1ABuaxUMZifC9saCMap/s200/eclipse_IDE.jpg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Here we will have look at how to create a Maven 2 Web application using &quot;Eclipse IDE for Java EE Developers&quot;&lt;br /&gt;
&lt;br /&gt;
If you don&#39;t have the IDE, it can be downloaded from &lt;a href=&quot;http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/heliosr&quot;&gt;here &lt;/a&gt;for free.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://maven.apache.org/what-is-maven.html&quot;&gt;Maven&lt;/a&gt; is a tool that can be used for building and managing any Java-based project. Here we will consider only about how to create a Web Application. &lt;br /&gt;
&lt;br /&gt;
Below are the steps to create the web application,&lt;br /&gt;
&lt;br /&gt;
Step 1:&amp;nbsp;Right click on project explorer and select New--&amp;gt;Other&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsDgOGwqvQeg66YuODUqAmafBEqzbVSKTKMVSBCBKxwrchzjiTzTalFiQYvaNk6DWrAc1-0ZZcntPQEUG6SLkHz-or5aeaM5mEGW-Rg1x_As6KIoeZKl-PbjEPRtr0XFnBNjbUqZBsqIhS/s1600/new_select.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;226&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsDgOGwqvQeg66YuODUqAmafBEqzbVSKTKMVSBCBKxwrchzjiTzTalFiQYvaNk6DWrAc1-0ZZcntPQEUG6SLkHz-or5aeaM5mEGW-Rg1x_As6KIoeZKl-PbjEPRtr0XFnBNjbUqZBsqIhS/s320/new_select.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Step 2: Type &quot;maven&quot; in the text box available, select &quot;Maven 2 Project Creation Wizard&quot;, and click &quot;Next&quot;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGIU-vbuoU5Rr-orFlIrGnY_YgkFKnFSwLibgCBDR_RwNBjZNncX_mumzlpR_Kmof_kxy8PpFXWL8IXuaCzcebaFAW_AOGvi1nFLfvOD6rmNgncxpg_9RPxxgvSztls7K36mVwKDa4mWs8/s1600/new_select_wizard.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;304&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGIU-vbuoU5Rr-orFlIrGnY_YgkFKnFSwLibgCBDR_RwNBjZNncX_mumzlpR_Kmof_kxy8PpFXWL8IXuaCzcebaFAW_AOGvi1nFLfvOD6rmNgncxpg_9RPxxgvSztls7K36mVwKDa4mWs8/s320/new_select_wizard.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
If you don&#39;t have &quot;Maven 2 Project&quot; here, it means you will need to add Maven plugin to eclipse. Find here how to do it:-&lt;a href=&quot;http://www.dotkam.com/2008/02/24/install-maven-plugin-for-eclipse/&quot;&gt;http://www.dotkam.com/2008/02/24/install-maven-plugin-for-eclipse/&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Step 3: Then, in the new window, type an appropriate name for the project and click &quot;Next&quot;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKFLZV4wf-EkJvWKloRbtZo49EmwdZbLAzaFMKrMkbJju36YBqnxggLNEil2HNXPN21dUYYMUS1eJP-BznMdXzo2-w-VNwLqzYkYd0E74w9BVy_jNPkY9B62IQs8zTUhdbI_XA4mLknrjl/s1600/wizard_step_2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKFLZV4wf-EkJvWKloRbtZo49EmwdZbLAzaFMKrMkbJju36YBqnxggLNEil2HNXPN21dUYYMUS1eJP-BznMdXzo2-w-VNwLqzYkYd0E74w9BVy_jNPkY9B62IQs8zTUhdbI_XA4mLknrjl/s320/wizard_step_2.jpg&quot; width=&quot;276&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Step 4: In the &quot;Maven&amp;nbsp;Archetypes&quot; type &quot;web&quot; and select &quot;maven-archetype-webapp-RELEASE&quot; from the list, and click next&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOUrDb02qrsA6DxB_PtbBDxx31USeMAqZcUJNzgOpaeh_TtYvhduNPTbMMtcwGGCpdObWMyjTvJ-B1ocVeTmTJyzbYvHkXOPL2AZ6sp3mIwpJ3Kjm8qWVfIyyoA2nX9bMFVhakD1aj-wxq/s1600/wizard_step_3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOUrDb02qrsA6DxB_PtbBDxx31USeMAqZcUJNzgOpaeh_TtYvhduNPTbMMtcwGGCpdObWMyjTvJ-B1ocVeTmTJyzbYvHkXOPL2AZ6sp3mIwpJ3Kjm8qWVfIyyoA2nX9bMFVhakD1aj-wxq/s320/wizard_step_3.jpg&quot; width=&quot;276&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Step 5: In the &quot;Maven Project Information&quot; window, change the names if you want, else leave it as it is, and then click finish&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicqVcGgesXV0lhTie1NQCSnF1Zm-rcqgyh4cPF06-al_rSYHQNwtwE2SnRrUxHFLhc_9lS1__Jf-LK7XCgkghIHrnNLqk0sv33L0CNvmcHlr0BPqJN38FAyerg0-DJqsjaLH5iouzUQgSl/s1600/wizard_step_4-final.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicqVcGgesXV0lhTie1NQCSnF1Zm-rcqgyh4cPF06-al_rSYHQNwtwE2SnRrUxHFLhc_9lS1__Jf-LK7XCgkghIHrnNLqk0sv33L0CNvmcHlr0BPqJN38FAyerg0-DJqsjaLH5iouzUQgSl/s320/wizard_step_4-final.jpg&quot; width=&quot;276&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
If you followed the steps correctly, a project will be created in your workspace with the following structure&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIYXvsOqAEB4Ys0E_6jH260iN43eWURYt7Mkabs1PsdAAXlHGIsDTqQPPvxqhPj-wMItM-v-xQSPTRnT9PEWh6mpzqvKeyynUgc8xPdpjsMMF-dedvuyPnkkqUVQDod9WRcxDgmsP6kiGx/s1600/project_structure.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIYXvsOqAEB4Ys0E_6jH260iN43eWURYt7Mkabs1PsdAAXlHGIsDTqQPPvxqhPj-wMItM-v-xQSPTRnT9PEWh6mpzqvKeyynUgc8xPdpjsMMF-dedvuyPnkkqUVQDod9WRcxDgmsP6kiGx/s320/project_structure.jpg&quot; width=&quot;313&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
The pom file will be like below,&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsuA6wXnYJH9OUsmfu2MDP3lAAdO6HqSwea1vcsv4DUpQAf4ED_dZd147olZ8JJM_S2gCnXMoOvWjJYFXc0YzdoltGh7UWwP0u-x5vG4HPs-dDdE2xKYsjOuSLxT825-0KujDZS2LvmlG6/s1600/pom_file.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;152&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsuA6wXnYJH9OUsmfu2MDP3lAAdO6HqSwea1vcsv4DUpQAf4ED_dZd147olZ8JJM_S2gCnXMoOvWjJYFXc0YzdoltGh7UWwP0u-x5vG4HPs-dDdE2xKYsjOuSLxT825-0KujDZS2LvmlG6/s320/pom_file.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now you can add any dependencies to the POM file and continue with your project. Happy Coding!&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dncodes.blogspot.com/feeds/1119247869435481366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dncodes.blogspot.com/2012/06/how-to-create-simple-maven-2-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3435429280123092588/posts/default/1119247869435481366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3435429280123092588/posts/default/1119247869435481366'/><link rel='alternate' type='text/html' href='http://dncodes.blogspot.com/2012/06/how-to-create-simple-maven-2-web.html' title='How to create a simple Maven 2 web project with Eclipse'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16789505062816668313</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirbS1xFDq5FzRhu7hYKTt32urItC8tmJ_5PdaN7pCVGpTUAIAdHgz-FIIgzUwb6TZQtZraXlpItQzD9eZYvRWco_4HTGwxNJI88xexPT9-iCFvZQzfHjuXiJiuC1ABuaxUMZifC9saCMap/s72-c/eclipse_IDE.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3435429280123092588.post-3352016829997359951</id><published>2012-06-16T22:47:00.001-07:00</published><updated>2012-06-23T23:25:43.715-07:00</updated><title type='text'>Java-Spring Security Authenticate through Facebook- OAuth 2</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUwQARVI-a3WMwdMdEFcXeEbvQLW4wBaErPcb3ziQ-E-3bKAQHRmi7DY1V_MnLjn6jvqEkU1xGySAZlWTtp-4b2HVxNdVVY1yEyESI7gV6ktwXqsjThGujix9aATSbi5HQ91JCk6pjWQVe/s1600/login_via_facebook.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;79&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUwQARVI-a3WMwdMdEFcXeEbvQLW4wBaErPcb3ziQ-E-3bKAQHRmi7DY1V_MnLjn6jvqEkU1xGySAZlWTtp-4b2HVxNdVVY1yEyESI7gV6ktwXqsjThGujix9aATSbi5HQ91JCk6pjWQVe/s320/login_via_facebook.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Recently I 
had a requirement of adding &quot;Login with facebook&quot; functionality to my 
existing spring-java web application. As I was not familiar with this 
before, tried to find some online examples or tutorials to get some 
help. But I couldn&#39;t find any good tutorial on this and finally had to 
go through the &lt;a href=&quot;http://developers.facebook.com/docs/guides/web/&quot; target=&quot;_blank&quot;&gt;facebook api&lt;/a&gt; and &lt;a href=&quot;http://restfb.com/&quot; target=&quot;_blank&quot;&gt;restfb&amp;nbsp;&lt;/a&gt;&amp;nbsp;by
 myself to find a solution. Since the solution I found is working fine 
so far, thought to share it hoping it might be useful to someone else 
too.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
My
 web application was a spring mvc (spring 3) configured and also spring 
security-3. I had a normal login form to the web app through spring 
security (/j_spring_security_check). All I wanted was to have a 
&quot;Login/Connect with Facebook button&quot;. My requirement was to authenticate
 the user in my spring security context after he has been&amp;nbsp;authenticated 
through Facebook. For this purpose I used a workaround since I couldn&#39;t 
find any other proper solution-even I tried various methods, even&amp;nbsp;&lt;a href=&quot;http://static.springsource.org/spring-social-facebook/docs/1.0.x/reference/html/&quot; target=&quot;_blank&quot;&gt;Spring social.&amp;nbsp;&lt;/a&gt;&amp;nbsp;In spring social they have specified a very convenient way to interact with Facebook&#39;s&amp;nbsp;&lt;a href=&quot;http://developers.facebook.com/docs/reference/api/&quot;&gt;Graph API&lt;/a&gt;&amp;nbsp;once
 we get the access token from facebook and the access token can be 
received from Facebook after OAuth authorization. This is exactly where I
 got stuck. So below is the way I got through it.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
I&#39;m going to use &lt;a href=&quot;https://developers.facebook.com/docs/authentication/server-side/&quot;&gt;server-side authentication&lt;/a&gt; with Facebook in this example.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
As the first step, we will have to create an application with Facebook. This application will represent our real application in Facebook, and will give the &quot;&lt;b&gt;&lt;i&gt;App ID/API Key&lt;/i&gt;&lt;/b&gt;&quot; &amp;nbsp;and &quot;&lt;b&gt;&lt;i&gt;App Secret&lt;/i&gt;&lt;/b&gt;&quot; which will be required to connect our application with Facebook.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
For this, go to &quot;&lt;a href=&quot;https://developers.facebook.com/apps&quot;&gt;https://developers.facebook.com/apps&lt;/a&gt;&quot; and create a new application by clicking on &quot;Create New App&quot;. After entering the required details, you will be given the App Id and App Secret.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Next, according to the Facebook API we have to redirect user to the URL-&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;&quot;https://www.facebook.com/dialog/oauth?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; client_id=YOUR_APP_ID&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;amp;redirect_uri=YOUR_REDIRECT_URI&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;amp;scope=COMMA_SEPARATED_LIST_OF_PERMISSION_NAMES&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;amp;state=SOME_ARBITRARY_BUT_UNIQUE_STRING&quot;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;in order to get the&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://developers.facebook.com/docs/reference/dialogs/oauth/&quot;&gt;OAuth Dialog&lt;/a&gt;&amp;nbsp;from facebook-(the user will enter the Facebook user name and the password here)&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
What I did was, first redirecting the user to my own controller and redirecting to the above url from my controller-In this way I thought we can get more control over constructing the above url.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
So, as the first step, add the something like below in your JSP where the login with Facebook button is required,&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #8ccce6; color: #051e4f; font-size: 16px; padding: 5px; width: 100%;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;lt;a href=&quot;facebookLogin.htm&quot;&amp;gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;lt;img src=&quot;images/fbconnect.png&quot; alt=&quot;Connect with Facebook&quot; /&amp;gt;&lt;/div&gt;
&lt;div class=&quot;&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;lt;/a&amp;gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
will appear like :-&amp;nbsp;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1s8WuwKnePQurvH2dquVqLQvrovBPDx9UjBnY4C7a2x-AYJq9xNr2s96jiQWygnOcj1ZmdNWIS5pVb2qc30-yjNsWkOfkOTe8JJhg1_BtQ73JbTzNlx2Q5HajKdb4bIkQ2VAyEM5AZMD1/s1600/login_with_facebook.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1s8WuwKnePQurvH2dquVqLQvrovBPDx9UjBnY4C7a2x-AYJq9xNr2s96jiQWygnOcj1ZmdNWIS5pVb2qc30-yjNsWkOfkOTe8JJhg1_BtQ73JbTzNlx2Q5HajKdb4bIkQ2VAyEM5AZMD1/s1600/login_with_facebook.png&quot; /&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now the code inside the controller will be like below;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: #8ccce6; color: #051e4f; font-size: 14px; padding: 5px; width: 100%;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
@RequestMapping(value = &quot;/facebookLogin&quot;)&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
public void getFacebookLogin(HttpServletRequest request,HttpServletResponse response) {&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String url=&quot;https://www.facebook.com/dialog/oauth/?&quot;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; &amp;nbsp;+ &quot;client_id=&quot; + ApplicationConstants.FACEBOOK_APP_ID&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; &amp;nbsp;+ &quot;&amp;amp;redirect_uri=&quot; + ApplicationConstants.FACEBOOK_REDIRECT_URL&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; &amp;nbsp;+ &quot;&amp;amp;scope=email,publish_stream,user_about_me,friends_about_me&quot;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; &amp;nbsp;+ &quot;&amp;amp;state=&quot; + ApplicationConstants.FACEBOOK_EXCHANGE_KEY&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; &amp;nbsp;+ &quot;&amp;amp;display=page&quot;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; &amp;nbsp;+ &quot;&amp;amp;response_type=code&quot;;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;try {&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;response.sendRedirect(url);&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;} catch (IOException e) {&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;// TODO Auto-generated catch block&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;e.printStackTrace();&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Lets have a look at the variables appended to the url,&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;client_id-&lt;/b&gt;this is the application id (&quot;&lt;b&gt;&lt;i&gt;App ID/API Key&lt;/i&gt;&lt;/b&gt;&quot;) mentioned above, since this will not change throughout the application, i have put it as a constant in my ApplicationConstants.java interface.&lt;br /&gt;
&lt;b&gt;redirect_uri- &lt;/b&gt;this will be the url, to which the user will be redirected by Facebook after login/cancellation from the&amp;nbsp;&lt;a href=&quot;https://developers.facebook.com/docs/reference/dialogs/oauth/&quot;&gt;OAuth Dialog&lt;/a&gt;. Our next set of code needs to be put here, how to handle the post authentication process. I used like &quot;http://localhost:8080/your_app_name/facebookAuthentication.htm&quot;&lt;br /&gt;
&lt;b&gt;scope-&lt;/b&gt;The scope parameter allows us to specify a comma separated list of additional permissions which we need the user to grant our application, the complete list can be found &lt;a href=&quot;https://developers.facebook.com/docs/authentication/permissions/&quot;&gt;here&lt;/a&gt;. Add these according to your requirements.&lt;br /&gt;
&lt;b&gt;state-&lt;/b&gt;this is like a key we used to keep the conversation between our application and Facebook safe, &quot;to ensure the security of the response when the user returns to your app after the authentication step&quot;. This can be any string eg:- &quot;justtotestfbresponseafterlogin&quot;-this too is a constant&lt;br /&gt;
&lt;b&gt;display-&lt;/b&gt;&amp;nbsp;The display mode with which to render the Dialog&lt;br /&gt;
&lt;b&gt;response_type-&lt;/b&gt;The requested response type, one of code or token, I tried to get the token staright, but I failed, so I&#39;m getting the &quot;code&quot; and using the code we&amp;nbsp;receive, we can get the access token.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://developers.facebook.com/docs/reference/dialogs/oauth/&quot;&gt;Here&lt;/a&gt; can be found a complete list of parameters with details to the above URL.&lt;br /&gt;
&lt;br /&gt;
Now its time to see howto handle the response we&amp;nbsp;receive&amp;nbsp;from Facebook when the user redirect to our application from the above URL. this is my code in the controller,&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: #8ccce6; padding: 5px; width: 100%;&quot;&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
@RequestMapping(value = &quot;/facebookAuthentication&quot;, method=RequestMethod.GET)&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public String facebookAuthentication(HttpServletRequest request,HttpServletResponse response) {&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;        //Get the parameter &quot;code&quot; from the request &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;String code=request.getParameter(&quot;code&quot;);&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b style=&quot;color: #38761d; white-space: pre;&quot;&gt;//Check if its null or blank or empty&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(StringUtils.isNotEmpty(code)){&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;color: #051e4f; font-size: 16px; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #051e4f;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;//If we received a valid code, we can continue to the next step&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;//Next we want to get the access_token from Facebook using the code we got,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;               //use the following url for that, in this url,&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;               //&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;b&gt;client_id-our app id(same as above), &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;b&gt;redirect_uri-same as above, client_secret-same as                //above, code-the code we just got&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String url=&quot;https://graph.facebook.com/oauth/access_token?&quot;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &quot;client_id=&quot; + ApplicationConstants.FACEBOOK_APP_ID&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &quot;&amp;amp;redirect_uri=&quot; + ApplicationConstants.FACEBOOK_REDIRECT_URL&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &quot;&amp;amp;client_secret=&quot; + ApplicationConstants.FACEBOOK_SECRET_KEY&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+ &quot;&amp;amp;code=&quot; + code;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;color: #051e4f; white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;// Create an instance of HttpClient.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; HttpClient client = new HttpClient();&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;// Create a method instance.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GetMethod method = new GetMethod(url);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;// Provide custom retry handler is necessary&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;new DefaultHttpMethodRetryHandler(3, false));&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try {&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&amp;nbsp;// Execute the method.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;int statusCode = client.executeMethod(method);&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (statusCode != HttpStatus.SC_OK) {&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.err.println(&quot;Method failed: &quot; + method.getStatusLine());&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&amp;nbsp;// Read the response body.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;byte[] responseBody = method.getResponseBody();&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;// &lt;b&gt;Deal with the response&lt;/b&gt;.&lt;b&gt;Use caution: ensure correct character encoding and is&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // not binary data&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;String responseBodyString=new String(responseBody);&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt; &amp;nbsp;//will be like below,&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //access_token=AAADD1QFhDlwBADrKkn87ZABAz6ZCBQZ//DZD&amp;amp;expires=5178320&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt; //now get the access_token from the response&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(responseBodyString.contains(&quot;access_token&quot;)){&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&amp;nbsp;//success&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;String[] mainResponseArray=responseBodyString.split(&quot;&amp;amp;&quot;);&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;//like //{&quot;access_token=&lt;/b&gt;&lt;/span&gt;
&lt;b style=&quot;color: #38761d;&quot;&gt;AAADD1QFhDlwBADrKkn87ZABAz6ZCBQZ//DZD&lt;/b&gt;&amp;nbsp;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&quot;,&quot;expires=5178320&quot;}&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;String accesstoken=&quot;&quot;;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;for (String string : mainResponseArray) {&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if(string.contains(&quot;access_token&quot;)){&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;accesstoken=string.replace(&quot;access_token=&quot;, &quot;&quot;).trim();&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;}&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt; &amp;nbsp; }&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&amp;nbsp;//now we have the access token :)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Great. Now we have the access token, I have used restfb to get the user details here&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;FacebookClient facebookClient = new DefaultFacebookClient(accesstoken);&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;User user = facebookClient.fetchObject(&quot;me&quot;, User.class);&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;//In this user object, you will have the details you want from Facebook, &amp;nbsp;Since we have &amp;nbsp; &amp;nbsp;the &amp;nbsp;access token with us, can play around and see what more can be done&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: #051e4f;&quot;&gt;            &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt; //CAME UP TO HERE AND WE KNOW THE USER HAS BEEN AUTHENTICATED BY FACEBOOK, LETS AUTHENTICATE HIM IN OUR APPLICATION&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: #051e4f;&quot;&gt;             &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #38761d;&quot;&gt; //NOW I WILL CALL MY doAutoLogin METHOD TO AUTHENTICATE THE USER IN MY SPRING SECURITY CONTEXT&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;}else{&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&amp;nbsp;//failed&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return &quot;redirect:loginPage.htm&quot;;&lt;/span&gt;&lt;span style=&quot;color: #051e4f; white-space: pre;&quot;&gt; &lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;} catch (HttpException e) {&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.err.println(&quot;Fatal protocol violation: &quot; + e.getMessage());&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.printStackTrace();&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;} catch (IOException e) {&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.err.println(&quot;Fatal transport error: &quot; + e.getMessage());&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.printStackTrace();&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;} finally {&lt;/div&gt;
&lt;div style=&quot;font-size: 16px;&quot;&gt;
&lt;span style=&quot;color: #051e4f;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;// Release the connection.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;method.releaseConnection();&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&amp;nbsp; &amp;nbsp; }&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}else{&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b style=&quot;color: #38761d;&quot;&gt;&amp;nbsp;//failed&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return &quot;redirect:loginPage.htm&quot;;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f; font-size: 16px;&quot;&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Now I will show the code i used to authenticate the user in my spring security context,&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: #8ccce6; font-size: 16px; padding: 5px; width: 100%;&quot;&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
public String doAutoLogin(String username, String password, HttpServletRequest request)throws Exception {&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;try {&lt;/div&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: #051e4f;&quot;&gt;       &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;  &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;// Must be called from request filtered by Spring Security,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// otherwise SecurityContextHolder is not updated&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;&amp;nbsp;               &lt;/span&gt;UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;token.setDetails(new WebAuthenticationDetails(request));&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Authentication authentication = this.authenticationProvider.authenticate(token);&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;SecurityContextHolder.getContext().setAuthentication(authentication);&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return ApplicationConstants.SUCCESS;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;} catch (Exception e) {&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;SecurityContextHolder.getContext().setAuthentication(null);&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.println(&quot;Failure in autoLogin&quot; + &amp;nbsp;e);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return null;&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;color: #051e4f;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Hope this tutorial helps, any feedback is highly appriciated.&lt;br /&gt;
&lt;br /&gt;
In the next tutorial, lets see how to access various information from Facebook and how to publish to Facebook using restfb api and hopefully Spring social too.&amp;nbsp;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dncodes.blogspot.com/feeds/3352016829997359951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dncodes.blogspot.com/2012/06/java-spring-security-authenticate.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3435429280123092588/posts/default/3352016829997359951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3435429280123092588/posts/default/3352016829997359951'/><link rel='alternate' type='text/html' href='http://dncodes.blogspot.com/2012/06/java-spring-security-authenticate.html' title='Java-Spring Security Authenticate through Facebook- OAuth 2'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/16789505062816668313</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUwQARVI-a3WMwdMdEFcXeEbvQLW4wBaErPcb3ziQ-E-3bKAQHRmi7DY1V_MnLjn6jvqEkU1xGySAZlWTtp-4b2HVxNdVVY1yEyESI7gV6ktwXqsjThGujix9aATSbi5HQ91JCk6pjWQVe/s72-c/login_via_facebook.png" height="72" width="72"/><thr:total>6</thr:total></entry></feed>