You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bu...@apache.org on 2015/07/14 10:19:35 UTC
svn commit: r958249 [2/2] - in /websites/production/camel/content:
cache/main.pageCache camel-2160-release.html tutorial-oauth.html
Modified: websites/production/camel/content/tutorial-oauth.html
==============================================================================
--- websites/production/camel/content/tutorial-oauth.html (original)
+++ websites/production/camel/content/tutorial-oauth.html Tue Jul 14 08:19:35 2015
@@ -85,77 +85,13 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="Tutorial-OAuth-CamelOAuthTutorial">Camel OAuth Tutorial</h2>
-
-<h3 id="Tutorial-OAuth-Overview">Overview</h3>
-
-<p>Goal of this tutorial is to demonstrate how to implement an <a shape="rect" class="external-link" href="http://code.google.com/apis/accounts/docs/OAuth.html" rel="nofollow">OAuth</a> consumer with Apache Camel. In this tutorial, the OAuth consumer is a simple web application running on Google App Engine. It reads data from a user's Google Calendar i.e. it displays the names of the user's public and private calendars. The OAuth-based authorization process that allows the application to access a user's calendars is implemented using Camel's <a shape="rect" href="gauth.html">gauth</a> component. The application is accessible online at <a shape="rect" class="external-link" href="http://gauthcloud.appspot.com/oauth/calendar" rel="nofollow">http://gauthcloud.appspot.com/oauth/calendar</a> (<a shape="rect" href="tutorial-oauth.html">later</a>, it will be explained how to build and deploy the application yourself). Play with it by following these steps: </p>
-
-<ul><li>Goto the application's main page at <a shape="rect" class="external-link" href="http://gauthcloud.appspot.com/oauth/calendar" rel="nofollow">http://gauthcloud.appspot.com/oauth/calendar</a>. If you haven't used the application before, you'll see a message that no OAuth access token is available. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-01.png"></span> <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"></li></ul>
-
-
-<ul><li>Follow the link next to this message to start the OAuth authorization process. You will be redirected to Google Accounts. A message is shown that a third party application is requesting access permissions. In order to grant (or deny) access, login to your Google account. This step may be skipped by Google if you already logged into Google Accounts before. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-02.png"></span> <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"></li></ul>
-
-
-<ul><li>After login, Google displays a message that <code>gauthcloud.appspot.com</code> wants to access your Google Calendar. Press the <code>Grant access</code> button to continue. No worries, the sample application will only read the names of your public and private Google calendars. No further reads or updates are made to your calendars. If you don't want <code>gauthcloud.appspot.com</code> to access your calendar, press <code>Deny access</code>. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-03.png"></span> <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"></li></ul>
-
-
-<ul><li>If you presses <code>Grant access</code>, Google redirects you back to the application that now displays the names of your public and private calendars. The following screenshot shows the list of <a shape="rect" class="external-link" href="http://people.apache.org/~krasserm">my</a> calendars (some of them have German names). Using OAUth, the web application gained access to your calendar data without ever having seen your Google username and password. These have been entered at a Google site directly. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-04.png"></span> <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"></li></ul>
-
-
-<ul><li>The result of a successful OAuth authorization process is an OAuth access token that is issued to the web application. The application stores this token for the duration of one hour. However, you can invalidate the access token at any time by either following the link below the calendar list or by going directly to <a shape="rect" class="external-link" href="https://www.google.com/accounts/IssuedAuthSubTokens" rel="nofollow">https://www.google.com/accounts/IssuedAuthSubTokens</a>. This will display a list of applications for which you granted access to your Google account. Among these, there's also an entry for <code>gauthcloud.appspot.com</code>. Click <code>Revoke Access</code> to invalidate the access token immediately. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-05.png"></span> <
br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"></li></ul>
-
-
-<ul><li>If you go back to the application or reload the page with the calendar list, a message is shown that the OAuth access token is invalid. Follow the OAuth authorization process again to renew the token. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-06.png"></span> <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"></li></ul>
-
-
-<div class="confluence-information-macro confluence-information-macro-information"><p class="title">Standalone web applications</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
-<p>Camel's OAuth support is not limited to web applications running on Google App Engine. It works for standalone web applications as well as long as they are accessible from the internet so that Google can make OAuth callbacks.</p></div></div>
-
-<h3 id="Tutorial-OAuth-Architecture">Architecture</h3>
-
-<p>The following figure sketches the architcture of the distributed web application and an example sequence of interactions.</p>
-
-<p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="tutorial-oauth.data/gauth-arch-01.png"></span></p>
-
-<h4 id="Tutorial-OAuth-Applicationcomponents">Application components</h4>
-
-<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Component</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>OAuth demo application</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>A Spring MVC-based web application with a single controller (<code>TutorialController</code>) and a facade for accessing the Google calendar service (<code>TutorialService</code>). The <code>TutorialController</code> selects views for either displaying calendar data or error messages.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>OAuth integration layer</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>A Camel-based integration layer for doing all the OAuth-specific interactions with Google Accounts.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Google Accounts</p></td><td colspan="
1" rowspan="1" class="confluenceTd"><p>The <a shape="rect" class="external-link" href="http://code.google.com/apis/accounts/" rel="nofollow">Google Accounts</a> service.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Google Calendar</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The <a shape="rect" class="external-link" href="http://code.google.com/apis/calendar/" rel="nofollow">Google Calendar</a> service.</p></td></tr></tbody></table></div>
-
-
-<h4 id="Tutorial-OAuth-Sequenceofactions">Sequence of actions</h4>
-
-<div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Step</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>1</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The user navigates to the main page of the demo application. The <code>TutorialController</code> detects that there's no OAuth access token available and renders a corresponding error message including a link for initiating an OAuth authorization process. The link is targeted at an HTTP endpoint implemented by the OAuth integration layer.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>2a</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The user triggers the authorization process by following that link. </p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>2b</p></td><td colspan="1" rowspan="1" class="confluenceTd">
<p>The integration layer obtains an unauthorized request token from the Google Accounts API</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>3</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>It then redirects the user to a Google Accounts web page for login.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>4</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The user logs in and grants <code>gauthcloud.appspot.com</code> access to his Google calendar.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>5a</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Google redirects the user back to the OAUth integration layer together with an authorized request token.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>5b</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The integration layer upgrades the token to an OAuth access token and stores this token in a cookie. The cookie
expiration time is set to one hour.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>6</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The user is redirected to the <code>TutorialController</code>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>7a</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The <code>TutorialController</code> can now obtain a valid access token from the cookie and uses it to obtain the user's calendar data (via the <code>TutorialService</code>).</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>7b</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>After having obtained the calendar data, the <code>TutorialController</code> selects a view for rendering the list of calendar names.</p></td></tr></tbody></table></div>
-
-
-<div class="confluence-information-macro confluence-information-macro-note"><p class="title">Storage of access tokens</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
-<p>In production systems it is <strong>not</strong> recommended to store access tokens in cookies. The recommended approach is to store them in a database. The demo application is only doing that to keep the example as simple as possible. However, an attacker could not use an access token alone to get access to a user's calendar data because the application's consumer secret is necessary for that as well. The consumer secret never leaves the demo application.</p></div></div>
-
-<h3 id="Tutorial-OAuth-Deployment">Deployment</h3>
-
-<p>This section explains how to build and deploy the web application yourself.</p>
-
-<h4 id="Tutorial-OAuth-Prerequisites">Prerequisites</h4>
-
-<ul><li><a shape="rect" class="external-link" href="https://appengine.google.com/" rel="nofollow">Sign up</a> for a Google App Engine account if you don't have one.</li><li>Create a new application via the <a shape="rect" class="external-link" href="https://appengine.google.com/" rel="nofollow">admin console</a> or reuse an existing one for uploading the example.</li><li>Optional: <a shape="rect" class="external-link" href="http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html" rel="nofollow">register</a> the application for use with Google's OAuth. After registration you should have access to a <em>consumer key</em> and a <em>consumer secret</em>. If you decide not to register your application, use <code>anonymous</code> for the consumer key and the consumer secret. In this case Google will display a warning message on the authorization page which is acceptable for testing-purposes.</li><li>Install the <a shape="rect" class="external-link" href="http://code.goo
gle.com/appengine/downloads.html" rel="nofollow">Google App Engine SDK for Java</a>. This tutorial has been tested with version 1.3.6.</li></ul>
-
-
-<h4 id="Tutorial-OAuth-Buildfromsources">Build from sources</h4>
-
-<p>Checkout the sources with</p>
-
-<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
+<div class="wiki-content maincontent"><h2 id="Tutorial-OAuth-CamelOAuthTutorial">Camel OAuth Tutorial</h2><h3 id="Tutorial-OAuth-Overview">Overview</h3><p>Goal of this tutorial is to demonstrate how to implement an <a shape="rect" class="external-link" href="http://code.google.com/apis/accounts/docs/OAuth.html" rel="nofollow">OAuth</a> consumer with Apache Camel. In this tutorial, the OAuth consumer is a simple web application running on Google App Engine. It reads data from a user's Google Calendar i.e. it displays the names of the user's public and private calendars. The OAuth-based authorization process that allows the application to access a user's calendars is implemented using Camel's <a shape="rect" href="gauth.html">gauth</a> component. The application was accessible online at <span class="nolink">http://gauthcloud.appspot.com/oauth/calendar (but not any more in year 2015 onwards)</span> (<a shape="rect" href="#Tutorial-OAuth-Deployment">later</a>, it will be explained
how to build and deploy the application yourself). Play with it by following these steps:</p><ul><li>Goto the application's main page at <a shape="rect" class="external-link" href="http://gauthcloud.appspot.com/oauth/calendar" rel="nofollow">http://gauthcloud.appspot.com/oauth/calendar</a> (no longer online). If you haven't used the application before, you'll see a message that no OAuth access token is available. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-01.png" data-image-src="/confluence/download/attachments/16416889/gauth-01.png?version=1&modificationDate=1270822585000&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="16515085" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="gauth-01.png" data-base
-url="https://cwiki.apache.org/confluence" data-linked-resource-content-type="image/png" data-linked-resource-container-id="16416889" data-linked-resource-container-version="10"></span> </li></ul><ul><li>Follow the link next to this message to start the OAuth authorization process. You will be redirected to Google Accounts. A message is shown that a third party application is requesting access permissions. In order to grant (or deny) access, login to your Google account. This step may be skipped by Google if you already logged into Google Accounts before. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-02.png" data-image-src="/confluence/download/attachments/16416889/gauth-02.png?version=1&modificationDate=1270822585000&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="1
6515086" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="gauth-02.png" data-base-url="https://cwiki.apache.org/confluence" data-linked-resource-content-type="image/png" data-linked-resource-container-id="16416889" data-linked-resource-container-version="10"></span> </li></ul><ul><li>After login, Google displays a message that <code>gauthcloud.appspot.com</code> wants to access your Google Calendar. Press the <code>Grant access</code> button to continue. No worries, the sample application will only read the names of your public and private Google calendars. No further reads or updates are made to your calendars. If you don't want <code>gauthcloud.appspot.com</code> to access your calendar, press <code>Deny access</code>. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border"
src="tutorial-oauth.data/gauth-03.png" data-image-src="/confluence/download/attachments/16416889/gauth-03.png?version=1&modificationDate=1270822585000&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="16515087" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="gauth-03.png" data-base-url="https://cwiki.apache.org/confluence" data-linked-resource-content-type="image/png" data-linked-resource-container-id="16416889" data-linked-resource-container-version="10"></span> </li></ul><ul><li>If you presses <code>Grant access</code>, Google redirects you back to the application that now displays the names of your public and private calendars. The following screenshot shows the list of <a shape="rect" class="external-link" href="http://people.apache.org/~krasserm">my</a> calendars (some of them have German names). Using OAUth, the web application gained access to your calendar data without ever having seen your
Google username and password. These have been entered at a Google site directly. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-04.png" data-image-src="/confluence/download/attachments/16416889/gauth-04.png?version=1&modificationDate=1270822585000&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="16515084" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="gauth-04.png" data-base-url="https://cwiki.apache.org/confluence" data-linked-resource-content-type="image/png" data-linked-resource-container-id="16416889" data-linked-resource-container-version="10"></span> </li></ul><ul><li>The result of a successful OAuth authorization process is an OAuth access token that is issued to the web application. The application s
tores this token for the duration of one hour. However, you can invalidate the access token at any time by either following the link below the calendar list or by going directly to <a shape="rect" class="external-link" href="https://www.google.com/accounts/IssuedAuthSubTokens" rel="nofollow">https://www.google.com/accounts/IssuedAuthSubTokens</a>. This will display a list of applications for which you granted access to your Google account. Among these, there's also an entry for <code>gauthcloud.appspot.com</code>. Click <code>Revoke Access</code> to invalidate the access token immediately. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-05.png" data-image-src="/confluence/download/attachments/16416889/gauth-05.png?version=1&modificationDate=1270822585000&api=v2" data-unresolved-comment-c
ount="0" data-linked-resource-id="16515083" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="gauth-05.png" data-base-url="https://cwiki.apache.org/confluence" data-linked-resource-content-type="image/png" data-linked-resource-container-id="16416889" data-linked-resource-container-version="10"></span> </li></ul><ul><li>If you go back to the application or reload the page with the calendar list, a message is shown that the OAuth access token is invalid. Follow the OAuth authorization process again to renew the token. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> <span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-content-image-border" src="tutorial-oauth.data/gauth-06.png" data-image-src="/confluence/download/attachments/16416889/gauth-06.png?version=1&modificationDate=1270822601000&api=v2" data-unresolved-comment-count="0" data-lin
ked-resource-id="16515088" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="gauth-06.png" data-base-url="https://cwiki.apache.org/confluence" data-linked-resource-content-type="image/png" data-linked-resource-container-id="16416889" data-linked-resource-container-version="10"></span> </li></ul><div class="confluence-information-macro confluence-information-macro-information"><p class="title">Standalone web applications</p><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Camel's OAuth support is not limited to web applications running on Google App Engine. It works for standalone web applications as well as long as they are accessible from the internet so that Google can make OAuth callbacks.</p></div></div><h3 id="Tutorial-OAuth-Architecture">Architecture</h3><p>The following figure sketches the architcture of the distributed we
b application and an example sequence of interactions.</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="tutorial-oauth.data/gauth-arch-01.png" data-image-src="/confluence/download/attachments/16416889/gauth-arch-01.png?version=1&modificationDate=1270822601000&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="16515089" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="gauth-arch-01.png" data-base-url="https://cwiki.apache.org/confluence" data-linked-resource-content-type="image/png" data-linked-resource-container-id="16416889" data-linked-resource-container-version="10"></span></p><h4 id="Tutorial-OAuth-Applicationcomponents">Application components</h4><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Component</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></t
h></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>OAuth demo application</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>A Spring MVC-based web application with a single controller (<code>TutorialController</code>) and a facade for accessing the Google calendar service (<code>TutorialService</code>). The <code>TutorialController</code> selects views for either displaying calendar data or error messages.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>OAuth integration layer</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>A Camel-based integration layer for doing all the OAuth-specific interactions with Google Accounts.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>Google Accounts</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The <a shape="rect" class="external-link" href="http://code.google.com/apis/accounts/" rel="nofollow">Google Accounts</a> service.</p></td></tr><tr><td colspan="1" row
span="1" class="confluenceTd"><p>Google Calendar</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The <a shape="rect" class="external-link" href="http://code.google.com/apis/calendar/" rel="nofollow">Google Calendar</a> service.</p></td></tr></tbody></table></div><h4 id="Tutorial-OAuth-Sequenceofactions">Sequence of actions</h4><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Step</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>1</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The user navigates to the main page of the demo application. The <code>TutorialController</code> detects that there's no OAuth access token available and renders a corresponding error message including a link for initiating an OAuth authorization process. The link is targeted at an HTTP endpoint implemented by the OAuth integrat
ion layer.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>2a</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The user triggers the authorization process by following that link.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>2b</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The integration layer obtains an unauthorized request token from the Google Accounts API</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>3</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>It then redirects the user to a Google Accounts web page for login.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>4</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The user logs in and grants <code>gauthcloud.appspot.com</code> access to his Google calendar.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>5a</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Google r
edirects the user back to the OAUth integration layer together with an authorized request token.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>5b</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The integration layer upgrades the token to an OAuth access token and stores this token in a cookie. The cookie expiration time is set to one hour.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>6</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The user is redirected to the <code>TutorialController</code>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>7a</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The <code>TutorialController</code> can now obtain a valid access token from the cookie and uses it to obtain the user's calendar data (via the <code>TutorialService</code>).</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>7b</p></td><td colspan="1" rowspan="1" class="conf
luenceTd"><p>After having obtained the calendar data, the <code>TutorialController</code> selects a view for rendering the list of calendar names.</p></td></tr></tbody></table></div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Storage of access tokens</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>In production systems it is <strong>not</strong> recommended to store access tokens in cookies. The recommended approach is to store them in a database. The demo application is only doing that to keep the example as simple as possible. However, an attacker could not use an access token alone to get access to a user's calendar data because the application's consumer secret is necessary for that as well. The consumer secret never leaves the demo application.</p></div></div><h3 id="Tutorial-OAuth-Deployment">Deployment</h3><p>This section ex
plains how to build and deploy the web application yourself.</p><h4 id="Tutorial-OAuth-Prerequisites">Prerequisites</h4><ul><li><a shape="rect" class="external-link" href="https://appengine.google.com/" rel="nofollow">Sign up</a> for a Google App Engine account if you don't have one.</li><li>Create a new application via the <a shape="rect" class="external-link" href="https://appengine.google.com/" rel="nofollow">admin console</a> or reuse an existing one for uploading the example.</li><li>Optional: <a shape="rect" class="external-link" href="http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html" rel="nofollow">register</a> the application for use with Google's OAuth. After registration you should have access to a <em>consumer key</em> and a <em>consumer secret</em>. If you decide not to register your application, use <code>anonymous</code> for the consumer key and the consumer secret. In this case Google will display a warning message on the authorization page wh
ich is acceptable for testing-purposes.</li><li>Install the <a shape="rect" class="external-link" href="http://code.google.com/appengine/downloads.html" rel="nofollow">Google App Engine SDK for Java</a>. This tutorial has been tested with version 1.3.6.</li></ul><h4 id="Tutorial-OAuth-Buildfromsources">Build from sources</h4><p>Checkout the sources with</p><div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>svn co http://svn.apache.org/repos/asf/camel/trunk/examples/camel-example-gauth camel-example-gauth
</pre>
-</div></div>
-
-<p>Open <code>camel-example-gauth/pom.xml</code> file and define values for the application properties e.g.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>pom.xml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+</div></div><p>Open <code>camel-example-gauth/pom.xml</code> file and define values for the application properties e.g.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>pom.xml</b></div><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
...
<properties>
@@ -168,16 +104,11 @@
...
</project>
-</pre>
-</div></div>
-
-<p>or </p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>pom.xml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+]]></script>
+</div></div><p>or</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>pom.xml</b></div><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
...
<properties>
@@ -190,41 +121,15 @@
...
</project>
-</pre>
-</div></div>
-
-<p>if you don't want to register your application. Then go to the <code>camel-example-gauth</code> directory and enter</p>
-
-<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
+]]></script>
+</div></div><p>if you don't want to register your application. Then go to the <code>camel-example-gauth</code> directory and enter</p><div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>mvn install
</pre>
-</div></div>
-
-<p>This will create the application <code>war</code> file in the target directory. </p>
-
-<h4 id="Tutorial-OAuth-DeploytoAppengine">Deploy to Appengine</h4>
-
-<p>Finally use the <code>appcfg</code> command-line tool of the App Engine SDK to deploy the application.</p>
-
-<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
+</div></div><p>This will create the application <code>war</code> file in the target directory.</p><h4 id="Tutorial-OAuth-DeploytoAppengine">Deploy to Appengine</h4><p>Finally use the <code>appcfg</code> command-line tool of the App Engine SDK to deploy the application.</p><div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>appcfg update target/camel-example-gauth-<version>
</pre>
-</div></div>
-
-<p>where <code>version</code> needs to be replaced with the version of Camel you're using. You will be prompted for the email address and password of your Google App Engine account. After deployment the example application is ready to use. </p>
-
-<div class="confluence-information-macro confluence-information-macro-note"><p class="title">Potential issue when using appcfg from the GAE SDK</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
-<p>It is important that you run <code>appcfg</code> with a <code>java</code> executable that is part of a JDK. If it is part of a JRE only then JSP compilation won't work. This is explained on the <a shape="rect" class="external-link" href="http://groups.google.com/group/google-appengine-java/msg/9b2f85fdff04c5ef" rel="nofollow">appengine-java mailing list</a>. Editing <code>appcfg.sh</code> or <code>appcfg.cmd</code> and pointing to an appropriate <code>java</code> executable should do the trick.</p></div></div>
-
-<h3 id="Tutorial-OAuth-Codewalkthrough">Code walkthrough</h3>
-
-<h4 id="Tutorial-OAuth-Applicationcontroller">Application controller</h4>
-
-<p>Entry point to the demo application is the <code>TutorialController</code>. It tries to obtain an OAuth access token from a cookie and interacts with the <code>TutorialService</code> for getting a user's calendar data from the Google Calendar API. Error messages (authentication failures) are displayed to the user by selecting the <code>authorize.jsp</code> view. This view also contains a link for starting the OAuth authorization process as shown above. A list of calendar names is displayed to the user by selecting the <code>calendar.jsp</code> view.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>TutorialController.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
-package org.apache.camel.example.gauth;
+</div></div><p>where <code>version</code> needs to be replaced with the version of Camel you're using. You will be prompted for the email address and password of your Google App Engine account. After deployment the example application is ready to use.</p><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Potential issue when using appcfg from the GAE SDK</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>It is important that you run <code>appcfg</code> with a <code>java</code> executable that is part of a JDK. If it is part of a JRE only then JSP compilation won't work. This is explained on the <a shape="rect" class="external-link" href="http://groups.google.com/group/google-appengine-java/msg/9b2f85fdff04c5ef" rel="nofollow">appengine-java mailing list</a>. Editing <code>appcfg.sh</code> or <code>appcfg.cmd</code> and pointing to an appropr
iate <code>java</code> executable should do the trick.</p></div></div><h3 id="Tutorial-OAuth-Codewalkthrough">Code walkthrough</h3><h4 id="Tutorial-OAuth-Applicationcontroller">Application controller</h4><p>Entry point to the demo application is the <code>TutorialController</code>. It tries to obtain an OAuth access token from a cookie and interacts with the <code>TutorialService</code> for getting a user's calendar data from the Google Calendar API. Error messages (authentication failures) are displayed to the user by selecting the <code>authorize.jsp</code> view. This view also contains a link for starting the OAuth authorization process as shown above. A list of calendar names is displayed to the user by selecting the <code>calendar.jsp</code> view.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>TutorialController.java</b></div><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[package org.apache.camel.example.gauth;
import java.util.List;
import javax.servlet.http.Cookie;
@@ -248,17 +153,17 @@ import org.springframework.web.bind.anno
* In production systems it is <em>not</em> recommended to store access tokens in cookies. The
* recommended approach is to store them in a database. The demo application is only doing that
* to keep the example as simple as possible. However, an attacker could not use an access token
- * alone to get access to a user's calendar data because the application's consumer secret is
+ * alone to get access to a user's calendar data because the application's consumer secret is
* necessary for that as well. The consumer secret never leaves the demo application.
*/
@Controller
-@RequestMapping("/calendar")
+@RequestMapping("/calendar")
public class TutorialController {
@Autowired
private TutorialService service;
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET)
public String handleGet(
HttpServletRequest request,
@@ -272,43 +177,36 @@ public class TutorialController {
String accessTokenSecret = getAccessTokenSecret(request);
if (accessToken == null) {
- model.put("message", "No OAuth access token available");
- return "/WEB-INF/jsp/authorize.jsp";
+ model.put("message", "No OAuth access token available");
+ return "/WEB-INF/jsp/authorize.jsp";
}
try {
// Get calendar names from Google Calendar API
calendarNames = service.getCalendarNames(accessToken, accessTokenSecret);
} catch (AuthenticationException e) {
- model.put("message", "OAuth access token invalid");
- return "/WEB-INF/jsp/authorize.jsp";
+ model.put("message", "OAuth access token invalid");
+ return "/WEB-INF/jsp/authorize.jsp";
}
- model.put("calendarNames", calendarNames);
- return "/WEB-INF/jsp/calendar.jsp";
+ model.put("calendarNames", calendarNames);
+ return "/WEB-INF/jsp/calendar.jsp";
}
private static String getAccessToken(HttpServletRequest request) {
- return getCookieValue(request.getCookies(), "TUTORIAL-ACCESS-TOKEN");
+ return getCookieValue(request.getCookies(), "TUTORIAL-ACCESS-TOKEN");
}
private static String getAccessTokenSecret(HttpServletRequest request) {
- return getCookieValue(request.getCookies(), "TUTORIAL-ACCESS-TOKEN-SECRET");
+ return getCookieValue(request.getCookies(), "TUTORIAL-ACCESS-TOKEN-SECRET");
}
// rest of code not shown ...
}
-</pre>
-</div></div>
-
-<h4 id="Tutorial-OAuth-Applicationservice">Application service</h4>
-
-<p>Access to the Google Calendar API is encapsulated in the <code>TutorialService</code> class. It uses Google's <a shape="rect" class="external-link" href="http://code.google.com/p/gdata-java-client/" rel="nofollow">GData client library</a> for abstracting from low-level protocol details. The <code>getCalendarNames</code> method is paramterized with an OAuth access token and access token secret. If the access token is invalid then an <code>AuthenticationException</code> is thrown by the GData client. The exception is handled by the <code>TutorialController</code>.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>TutorialService.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
-package org.apache.camel.example.gauth;
+]]></script>
+</div></div><h4 id="Tutorial-OAuth-Applicationservice">Application service</h4><p>Access to the Google Calendar API is encapsulated in the <code>TutorialService</code> class. It uses Google's <a shape="rect" class="external-link" href="http://code.google.com/p/gdata-java-client/" rel="nofollow">GData client library</a> for abstracting from low-level protocol details. The <code>getCalendarNames</code> method is paramterized with an OAuth access token and access token secret. If the access token is invalid then an <code>AuthenticationException</code> is thrown by the GData client. The exception is handled by the <code>TutorialController</code>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>TutorialService.java</b></div><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[package org.apache.camel.example.gauth;
import java.net.URL;
import java.util.ArrayList;
@@ -330,7 +228,7 @@ public class TutorialService {
private Properties credentials;
/**
- * Sets properties that contains the application's consumer key and consumer secret.
+ * Sets properties that contains the application's consumer key and consumer secret.
*
* @param credentials consumer key and consumer secret.
*/
@@ -339,18 +237,18 @@ public class TutorialService {
}
/**
- * Obtains a list of names of a user's public and private calendars from the Google
+ * Obtains a list of names of a user's public and private calendars from the Google
* Calendar API.
*
* @param accessToken OAuth access token.
* @param accessTokenSecret OAuth access token secret.
- * @return list of names of a user's public and private calendars.
+ * @return list of names of a user's public and private calendars.
*/
public List<String> getCalendarNames(String accessToken, String accessTokenSecret) throws Exception {
- CalendarService calendarService = new CalendarService("apache-camel-2.3");
+ CalendarService calendarService = new CalendarService("apache-camel-2.3");
OAuthParameters params = getOAuthParams(accessToken, accessTokenSecret);
calendarService.setOAuthCredentials(params, new OAuthHmacSha1Signer());
- URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/");
+ URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/");
CalendarFeed resultFeed = calendarService.getFeed(feedUrl, CalendarFeed.class);
ArrayList<String> result = new ArrayList<String>();
@@ -363,26 +261,17 @@ public class TutorialService {
private OAuthParameters getOAuthParams(String accessToken, String accessTokenSecret) {
OAuthParameters params = new OAuthParameters();
- params.setOAuthConsumerKey(credentials.getProperty("consumer.key"));
- params.setOAuthConsumerSecret(credentials.getProperty("consumer.secret"));
+ params.setOAuthConsumerKey(credentials.getProperty("consumer.key"));
+ params.setOAuthConsumerSecret(credentials.getProperty("consumer.secret"));
params.setOAuthToken(accessToken);
params.setOAuthTokenSecret(accessTokenSecret);
return params;
}
}
-</pre>
-</div></div>
-
-<p>The </p>
-
-<h4 id="Tutorial-OAuth-Integrationlayer">Integration layer</h4>
-
-<p>The integration layer uses Camel's <a shape="rect" href="gauth.html">gauth</a> component to implement the consumer part of the OAuth authorization process. It cleanly separates OAuth integration logic from other parts of the application and is implemented by the <code>TutorialRouteBuilder</code> class.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>TutorialRouteBuilder.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
-package org.apache.camel.example.gauth;
+]]></script>
+</div></div><p>The</p><h4 id="Tutorial-OAuth-Integrationlayer">Integration layer</h4><p>The integration layer uses Camel's <a shape="rect" href="gauth.html">gauth</a> component to implement the consumer part of the OAuth authorization process. It cleanly separates OAuth integration logic from other parts of the application and is implemented by the <code>TutorialRouteBuilder</code> class.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>TutorialRouteBuilder.java</b></div><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[package org.apache.camel.example.gauth;
import java.net.URLEncoder;
@@ -409,41 +298,31 @@ public class TutorialRouteBuilder extend
// Callback URL for sending back an authorized access token.
String encodedCallback = URLEncoder.encode(
- String.format("https://%s.appspot.com/camel/handler", application), "UTF-8");
+ String.format("https://%s.appspot.com/camel/handler", application), "UTF-8");
// Google should issue an access token that is scoped to calendar feeds.
- String encodedScope = URLEncoder.encode("http://www.google.com/calendar/feeds/", "UTF-8");
+ String encodedScope = URLEncoder.encode("http://www.google.com/calendar/feeds/", "UTF-8");
// Route for obtaining an unauthorized request token from Google Accounts. The
// response redirects the browser to an authorization page provided by Google.
- from("ghttp:///authorize")
- .to("gauth:authorize?callback=" + encodedCallback + "&scope=" + encodedScope);
+ from("ghttp:///authorize")
+ .to("gauth:authorize?callback=" + encodedCallback + "&scope=" + encodedScope);
// Handles callbacks from Google Accounts which contain an authorized request token.
// The authorized request token is upgraded to an access token which is stored in
// the response message header. The TutorialTokenProcessor is application-specific
// and stores the access token (plus access token secret) is cookies. It further
- // redirects the user to the application's main location (/oauth/calendar).
- from("ghttp:///handler")
- .to("gauth:upgrade")
+ // redirects the user to the application's main location (/oauth/calendar).
+ from("ghttp:///handler")
+ .to("gauth:upgrade")
.process(new TutorialTokenProcessor());
}
}
-</pre>
-</div></div>
-
-<p>This class implements two routes:</p>
-
-<ol><li>The first route obtains an unauthorized access token from Google Accounts and redirects the user to an authorization page provided by Google.</li><li>The second route handles OAuth callbacks from Google and upgrades an authorized request tokens to access tokens.</li></ol>
-
-
-<p>The last step in the second route is an application-specific processor (<code>TutorialTokenProcessor</code>) that stores the access token in a cookie and redirects the user to the main page of the demo application (which is served by the <code>TutorialController</code>).</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>TutorialTokenProcessor.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
-package org.apache.camel.example.gauth;
+]]></script>
+</div></div><p>This class implements two routes:</p><ol><li>The first route obtains an unauthorized access token from Google Accounts and redirects the user to an authorization page provided by Google.</li><li>The second route handles OAuth callbacks from Google and upgrades an authorized request tokens to access tokens.</li></ol><p>The last step in the second route is an application-specific processor (<code>TutorialTokenProcessor</code>) that stores the access token in a cookie and redirects the user to the main page of the demo application (which is served by the <code>TutorialController</code>).</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>TutorialTokenProcessor.java</b></div><div class="codeContent panelContent pdl">
+<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[package org.apache.camel.example.gauth;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
@@ -457,14 +336,14 @@ import static org.apache.camel.component
/**
* Reads an OAuth access token plus access token secret from a Camel message and stores them in
* cookies. These cookies are needed by {@link org.apache.camel.example.gauth.TutorialController}
- * for accessing a user's calendar via the Google Calendar API. The cookies are valid for one
- * hour. Finally, it generates an HTTP 302 response that redirects the user to the application's
+ * for accessing a user's calendar via the Google Calendar API. The cookies are valid for one
+ * hour. Finally, it generates an HTTP 302 response that redirects the user to the application's
* main location (/oauth/calendar).
* <p>
* In production systems it is <em>not</em> recommended to store access tokens in cookies. The
* recommended approach is to store them in a database. The demo application is only doing that
* to keep the example as simple as possible. However, an attacker could not use an access token
- * alone to get access to a user's calendar data because the application's consumer secret is
+ * alone to get access to a user's calendar data because the application's consumer secret is
* necessary for that as well. The consumer secret never leaves the demo application.
*/
public class TutorialTokenProcessor implements Processor {
@@ -479,13 +358,13 @@ public class TutorialTokenProcessor impl
HttpServletResponse servletResponse = exchange.getIn().getHeader(
Exchange.HTTP_SERVLET_RESPONSE, HttpServletResponse.class);
- Cookie accessTokenCookie = new Cookie("TUTORIAL-ACCESS-TOKEN", accessToken);
- Cookie accessTokenSecretCookie = new Cookie("TUTORIAL-ACCESS-TOKEN-SECRET", accessTokenSecret);
+ Cookie accessTokenCookie = new Cookie("TUTORIAL-ACCESS-TOKEN", accessToken);
+ Cookie accessTokenSecretCookie = new Cookie("TUTORIAL-ACCESS-TOKEN-SECRET", accessTokenSecret);
- accessTokenCookie.setPath("/oauth/");
+ accessTokenCookie.setPath("/oauth/");
accessTokenCookie.setMaxAge(ONE_HOUR);
- accessTokenSecretCookie.setPath("/oauth/");
+ accessTokenSecretCookie.setPath("/oauth/");
accessTokenSecretCookie.setMaxAge(ONE_HOUR);
servletResponse.addCookie(accessTokenCookie);
@@ -493,92 +372,73 @@ public class TutorialTokenProcessor impl
}
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302);
- exchange.getOut().setHeader("Location", "/oauth/calendar");
+ exchange.getOut().setHeader("Location", "/oauth/calendar");
}
}
-</pre>
-</div></div>
-
-<p>For further details about implementing OAuth integration layers in web application refer to the <a shape="rect" href="gauth.html">gauth</a> component documentation.</p>
-
-<h4 id="Tutorial-OAuth-Configuration">Configuration</h4>
-
-<p>The <code>TutorialController</code> and <code>TutorialService</code> are set up in their own Spring application context. The <code>TutorialController</code> is scanned from the classpath using Spring's <code><ctx:component-scan></code> element. It is an <a shape="rect" class="external-link" href="http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-annotation" rel="nofollow">annotation-based Spring MVC controller</a>.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>context-web.xml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:ctx="http://www.springframework.org/schema/context"
- xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="
+]]></script>
+</div></div><p>For further details about implementing OAuth integration layers in web application refer to the <a shape="rect" href="gauth.html">gauth</a> component documentation.</p><h4 id="Tutorial-OAuth-Configuration">Configuration</h4><p>The <code>TutorialController</code> and <code>TutorialService</code> are set up in their own Spring application context. The <code>TutorialController</code> is scanned from the classpath using Spring's <code><ctx:component-scan></code> element. It is an <a shape="rect" class="external-link" href="http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-annotation" rel="nofollow">annotation-based Spring MVC controller</a>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>context-web.xml</b></div><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ctx="http://www.springframework.org/schema/context"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util
-http://www.springframework.org/schema/util/spring-util-2.5.xsd">
+http://www.springframework.org/schema/util/spring-util-2.5.xsd">
- <ctx:component-scan base-package="org.apache.camel.example.gauth"/>
+ <ctx:component-scan base-package="org.apache.camel.example.gauth"/>
- <util:properties id="credentials" location="classpath:context.properties"/>
+ <util:properties id="credentials" location="classpath:context.properties"/>
- <bean id="tutorialService" class="org.apache.camel.example.gauth.TutorialService">
- <property name="credentials" ref="credentials" />
+ <bean id="tutorialService" class="org.apache.camel.example.gauth.TutorialService">
+ <property name="credentials" ref="credentials" />
</bean>
-</beans></pre>
-</div></div>
-
-<p>The integration layer and its <code>CamelContext</code> is configured in <code>context-camel.xml</code>. This application context also configures the <a shape="rect" href="gauth.html">gauth</a> component with an application specific consumer key and consumer secret. These are read from a <code>context.properties</code> file.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>context-camel.xml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:camel="http://camel.apache.org/schema/spring"
- xsi:schemaLocation="
+</beans>]]></script>
+</div></div><p>The integration layer and its <code>CamelContext</code> is configured in <code>context-camel.xml</code>. This application context also configures the <a shape="rect" href="gauth.html">gauth</a> component with an application specific consumer key and consumer secret. These are read from a <code>context.properties</code> file.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>context-camel.xml</b></div><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://camel.apache.org/schema/spring
-http://camel.apache.org/schema/spring/camel-spring.xsd">
+http://camel.apache.org/schema/spring/camel-spring.xsd">
- <context:property-placeholder location="classpath:context.properties"/>
+ <context:property-placeholder location="classpath:context.properties"/>
- <camel:camelContext id="camelContext">
- <camel:jmxAgent id="agent" disabled="true" />
- <camel:routeBuilder ref="tutorialRouteBuilder"/>
+ <camel:camelContext id="camelContext">
+ <camel:jmxAgent id="agent" disabled="true" />
+ <camel:routeBuilder ref="tutorialRouteBuilder"/>
</camel:camelContext>
- <bean id="tutorialRouteBuilder"
- class="org.apache.camel.example.gauth.TutorialRouteBuilder">
- <property name="application" value="${application.name}" />
+ <bean id="tutorialRouteBuilder"
+ class="org.apache.camel.example.gauth.TutorialRouteBuilder">
+ <property name="application" value="${application.name}" />
</bean>
- <bean id="gauth" class="org.apache.camel.component.gae.auth.GAuthComponent">
- <property name="consumerKey" value="${consumer.key}" />
- <property name="consumerSecret" value="${consumer.secret}" />
+ <bean id="gauth" class="org.apache.camel.component.gae.auth.GAuthComponent">
+ <property name="consumerKey" value="${consumer.key}" />
+ <property name="consumerSecret" value="${consumer.secret}" />
</bean>
</beans>
-</pre>
-</div></div>
-
-<p>Both application contexts are referenced in the application's <code>web.xml</code>.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>web.xml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">
-<web-app
-xmlns="http://java.sun.com/xml/ns/javaee"
-xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
-xsi:schemaLocation="
+]]></script>
+</div></div><p>Both application contexts are referenced in the application's <code>web.xml</code>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>web.xml</b></div><div class="codeContent panelContent pdl">
+<script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<web-app
+xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
-http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
+http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>CamelServlet</servlet-name>
@@ -608,14 +468,14 @@ http://java.sun.com/xml/ns/javaee/web-ap
</servlet-mapping>
</web-app>
-</pre>
+]]></script>
</div></div></div>
</td>
<td valign="top">
<div class="navigation">
<div class="navigation_top">
<!-- NavigationBar -->
-<div class="navigation_bottom" id="navigation_bottom"><h3 id="Navigation-Overviewhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49132"><a shape="rect" href="overview.html">Overview</a></h3><ul class="alternate"><li><a shape="rect" href="index.html">Home</a></li><li><a shape="rect" href="download.html">Download</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li><li><a shape="rect" href="faq.html">FAQ</a></li></ul><h3 id="Navigation-Documentationhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49534"><a shape="rect" href="documentation.html">Documentation</a></h3><ul class="alternate"><li><a shape="rect" href="user-guide.html">User Guide</a></li><li><a shape="rect" href="manual.html">Manual</a></li><li><a shape="rect" href="books.html">Books</a></li><li><a shape="rect" href="tutorials.html">Tutorials</a></li><li><a shape="rect" href="examples.html">Examples</a></li><li><a shape="rect" href="cookbook.html">Cookbook</a></li>
<li><a shape="rect" href="architecture.html">Architecture</a></li><li><a shape="rect" href="enterprise-integration-patterns.html">Enterprise Integration Patterns</a></li><li><a shape="rect" href="dsl.html">DSL</a></li><li><a shape="rect" href="components.html">Components</a></li><li><a shape="rect" href="data-format.html">Data Format</a></li><li><a shape="rect" href="languages.html">Languages</a></li><li><a shape="rect" href="security.html">Security</a></li><li><a shape="rect" href="security-advisories.html">Security Advisories</a></li></ul><h3 id="Navigation-Search">Search</h3><form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
+<div class="navigation_bottom" id="navigation_bottom"><h3 id="Navigation-Overview"><a shape="rect" href="overview.html">Overview</a></h3><ul class="alternate"><li><a shape="rect" href="index.html">Home</a></li><li><a shape="rect" href="download.html">Download</a></li><li><a shape="rect" href="getting-started.html">Getting Started</a></li><li><a shape="rect" href="faq.html">FAQ</a></li></ul><h3 id="Navigation-Documentation"><a shape="rect" href="documentation.html">Documentation</a></h3><ul class="alternate"><li><a shape="rect" href="user-guide.html">User Guide</a></li><li><a shape="rect" href="manual.html">Manual</a></li><li><a shape="rect" href="books.html">Books</a></li><li><a shape="rect" href="tutorials.html">Tutorials</a></li><li><a shape="rect" href="examples.html">Examples</a></li><li><a shape="rect" href="cookbook.html">Cookbook</a></li><li><a shape="rect" href="architecture.html">Architecture</a></li><li><a shape="rect" href="enterprise-integration-patterns.html">Enterprise
Integration Patterns</a></li><li><a shape="rect" href="dsl.html">DSL</a></li><li><a shape="rect" href="components.html">Components</a></li><li><a shape="rect" href="data-format.html">Data Format</a></li><li><a shape="rect" href="languages.html">Languages</a></li><li><a shape="rect" href="security.html">Security</a></li><li><a shape="rect" href="security-advisories.html">Security Advisories</a></li></ul><h3 id="Navigation-Search">Search</h3><form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="007878419884033443453:m5nhvy4hmyq">
<input type="hidden" name="ie" value="UTF-8">
@@ -623,7 +483,7 @@ http://java.sun.com/xml/ns/javaee/web-ap
<input type="submit" name="sa" value="Search">
</div>
</form>
-<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script><h3 id="Navigation-Communityhttps://cwiki.apache.org/confluence/pages/viewpage.action?pageId=49115"><a shape="rect" href="community.html">Community</a></h3><ul class="alternate"><li><a shape="rect" href="support.html">Support</a></li><li><a shape="rect" href="contributing.html">Contributing</a></li><li><a shape="rect" href="discussion-forums.html">Discussion Forums</a></li><li><a shape="rect" href="mailing-lists.html">Mailing Lists</a></li><li><a shape="rect" href="user-stories.html">User Stories</a></li><li><a shape="rect" href="news.html">News</a></li><li><a shape="rect" href="articles.html">Articles</a></li><li><a shape="rect" href="site.html">Site</a></li><li><a shape="rect" href="team.html">Team</a></li><li><a shape="rect" class="external-link" href="http://camel-extra.googlecode.com/" rel="nofollow">Camel Extra</a></li></ul><h3 id="Navigation-Developershttps://cwi
ki.apache.org/confluence/pages/viewpage.action?pageId=49124"><a shape="rect" href="developers.html">Developers</a></h3><ul class="alternate"><li><a shape="rect" href="developers.html">Developer Guide</a></li><li><a shape="rect" href="source.html">Source</a></li><li><a shape="rect" href="building.html">Building</a></li><li><a shape="rect" href="javadoc.html">JavaDoc</a></li><li><a shape="rect" href="irc-room.html">IRC Room</a></li></ul><h3 id="Navigation-ApacheSoftwareFoundation">Apache Software Foundation</h3><ul class="alternate"><li><a shape="rect" class="external-link" href="http://www.apache.org/licenses/">License</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/foundation/thanks.html">Thanks</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/security/">Security</a></li></ul></div>
+<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script><h3 id="Navigation-Community"><a shape="rect" href="community.html">Community</a></h3><ul class="alternate"><li><a shape="rect" href="support.html">Support</a></li><li><a shape="rect" href="contributing.html">Contributing</a></li><li><a shape="rect" href="discussion-forums.html">Discussion Forums</a></li><li><a shape="rect" href="mailing-lists.html">Mailing Lists</a></li><li><a shape="rect" href="user-stories.html">User Stories</a></li><li><a shape="rect" href="news.html">News</a></li><li><a shape="rect" href="articles.html">Articles</a></li><li><a shape="rect" href="site.html">Site</a></li><li><a shape="rect" href="team.html">Team</a></li><li><a shape="rect" class="external-link" href="http://camel-extra.googlecode.com/" rel="nofollow">Camel Extra</a></li></ul><h3 id="Navigation-Developers"><a shape="rect" href="developers.html">Developers</a></h3><ul class="alternate"
><li><a shape="rect" href="developers.html">Developer Guide</a></li><li><a shape="rect" href="source.html">Source</a></li><li><a shape="rect" href="building.html">Building</a></li><li><a shape="rect" href="javadoc.html">JavaDoc</a></li><li><a shape="rect" href="irc-room.html">IRC Room</a></li></ul><h3 id="Navigation-ApacheSoftwareFoundation">Apache Software Foundation</h3><ul class="alternate"><li><a shape="rect" class="external-link" href="http://www.apache.org/licenses/">License</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/foundation/thanks.html">Thanks</a></li><li><a shape="rect" class="external-link" href="http://www.apache.org/security/">Security</a></li></ul></div>
<!-- NavigationBar -->
</div>
</div>