You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by kr...@apache.org on 2010/02/07 10:38:43 UTC
svn commit: r907402 [1/2] - in /camel/trunk/components/camel-gae: ./
src/main/java/org/apache/camel/component/gae/auth/
src/main/java/org/apache/camel/component/gae/bind/
src/main/java/org/apache/camel/component/gae/http/
src/main/java/org/apache/camel...
Author: krasserm
Date: Sun Feb 7 09:38:41 2010
New Revision: 907402
URL: http://svn.apache.org/viewvc?rev=907402&view=rev
Log:
CAMEL-2370 (glogin component) and CAMEL-2409 (gauth component)
Added:
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthAuthorizeBinding.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthComponent.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthEndpoint.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthException.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthJksLoader.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthKeyLoader.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthPk8Loader.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthProducer.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthService.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthServiceImpl.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthTokenSecret.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginBinding.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginComponent.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginData.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginEndpoint.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginProducer.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginService.java (with props)
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginServiceImpl.java (with props)
camel/trunk/components/camel-gae/src/main/resources/META-INF/services/org/apache/camel/component/gauth
camel/trunk/components/camel-gae/src/main/resources/META-INF/services/org/apache/camel/component/glogin
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthAuthorizeBindingTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthEndpointTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthJksLoaderTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthPk8LoaderTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthRouteBuilder.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthRouteBuilderTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthServiceMock.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthTestUtils.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthTokenSecretTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/auth/GAuthUpgradeBindingTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/login/
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/login/GLoginBindingTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/login/GLoginEndpointTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/login/GLoginRouteBuilder.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/login/GLoginRouteBuilderTest.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/login/GLoginServiceMock.java (with props)
camel/trunk/components/camel-gae/src/test/java/org/apache/camel/component/gae/login/GLoginTestUtils.java (with props)
camel/trunk/components/camel-gae/src/test/resources/org/apache/camel/component/gae/auth/
camel/trunk/components/camel-gae/src/test/resources/org/apache/camel/component/gae/auth/context.xml (with props)
camel/trunk/components/camel-gae/src/test/resources/org/apache/camel/component/gae/auth/test1.jks (with props)
camel/trunk/components/camel-gae/src/test/resources/org/apache/camel/component/gae/auth/test2.pk8
camel/trunk/components/camel-gae/src/test/resources/org/apache/camel/component/gae/login/
camel/trunk/components/camel-gae/src/test/resources/org/apache/camel/component/gae/login/context.xml (with props)
Modified:
camel/trunk/components/camel-gae/pom.xml
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/bind/HttpBindingInvocationHandler.java
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpBinding.java
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpEndpoint.java
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailComponent.java
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/mail/GMailEndpoint.java
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/task/GTaskBinding.java
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/task/GTaskComponent.java
camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/task/GTaskEndpoint.java
Modified: camel/trunk/components/camel-gae/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/pom.xml?rev=907402&r1=907401&r2=907402&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/pom.xml (original)
+++ camel/trunk/components/camel-gae/pom.xml Sun Feb 7 09:38:41 2010
@@ -33,6 +33,7 @@
<properties>
<camel.osgi.export.pkg>org.apache.camel.component.gae.*</camel.osgi.export.pkg>
<appengine-sdk-version>1.3.0</appengine-sdk-version>
+ <gdata-version>1.40.2</gdata-version>
</properties>
<dependencies>
@@ -40,6 +41,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
@@ -50,6 +55,16 @@
<artifactId>appengine-api-labs</artifactId>
<version>${appengine-sdk-version}</version>
</dependency>
+ <dependency>
+ <groupId>com.google.gdata</groupId>
+ <artifactId>gdata-core</artifactId>
+ <version>${gdata-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>${commons-io-version}</version>
+ </dependency>
<!-- testing -->
<dependency>
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthAuthorizeBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthAuthorizeBinding.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthAuthorizeBinding.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthAuthorizeBinding.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import com.google.gdata.client.authn.oauth.GoogleOAuthParameters;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+
+/**
+ * Binds {@link GoogleOAuthParameters} to a Camel {@link Exchange}. This binding
+ * is used by <code>gauth:authorize</code> endpoints by default.
+ */
+public class GAuthAuthorizeBinding implements OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> {
+
+ /**
+ * Name of the Camel header defining the access scope. Overrides the scope
+ * parameter defined in a <code>gauth:authorize</code> endpoint URI.
+ */
+ public static final String GAUTH_SCOPE = "CamelGauthScope";
+
+ /**
+ * Name of the Camel header containing a callback URL. Overrides the
+ * callback parameter defined in a <code>gauth:authorize</code> endpoint
+ * URI.
+ */
+ public static final String GAUTH_CALLBACK = "CamelGauthCallback";
+
+ /**
+ * Creates a {@link GoogleOAuthParameters} object from endpoint and
+ * <code>exchange.getIn()</code> data. The created parameter object is
+ * used to fetch an unauthorized request token from Google.
+ *
+ * @param endpoint
+ * @param exchange
+ * @param request
+ * ignored.
+ * @return
+ */
+ public GoogleOAuthParameters writeRequest(GAuthEndpoint endpoint, Exchange exchange, GoogleOAuthParameters request) {
+ String callback = exchange.getIn().getHeader(GAUTH_CALLBACK, String.class);
+ if (callback == null) {
+ callback = endpoint.getCallback();
+ }
+ String scope = exchange.getIn().getHeader(GAUTH_SCOPE, String.class);
+ if (scope == null) {
+ scope = endpoint.getScope();
+ }
+ request = new GoogleOAuthParameters();
+ request.setOAuthConsumerKey(endpoint.getConsumerKey());
+ request.setOAuthConsumerSecret(endpoint.getConsumerSecret());
+ request.setOAuthCallback(callback);
+ request.setScope(scope);
+ return request;
+ }
+
+ /**
+ * Creates an <code>exchange.getOut()</code> message that represents an HTTP
+ * redirect to Google's OAuth confirmation page. Additionally, if the
+ * {@link GAuthComponent} is configured to use the HMAC_SHA1 signature
+ * method, a cookie is created containing the request token secret. It is
+ * needed later to upgrade an authorized request token to an access token.
+ *
+ * @param endpoint
+ * @param exchange
+ * @param response
+ * @return
+ */
+ public Exchange readResponse(GAuthEndpoint endpoint, Exchange exchange, GoogleOAuthParameters response) throws Exception {
+ String authrUrl = endpoint.newOAuthHelper().createUserAuthorizationUrl(response);
+ exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302);
+ exchange.getOut().setHeader("Location", authrUrl);
+
+ if (endpoint.getComponent().getKeyLoader() == null) {
+ // HMAC_SHA1 signature is used and this requires a
+ // token secret. Add it to a cookie because it is
+ // later needed for getting an access token.
+ String secret = response.getOAuthTokenSecret();
+ String cookie = new GAuthTokenSecret(secret).toCookie();
+ exchange.getOut().setHeader("Set-Cookie", cookie);
+ }
+ return exchange;
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthAuthorizeBinding.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthComponent.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthComponent.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthComponent.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * The <a href="http://camel.apache.org/gauth.html">GAuth Component</a>
+ * implements a Google-specific OAuth comsumer. This component supports OAuth
+ * 1.0a. For background information refer to <a
+ * href="http://code.google.com/apis/accounts/docs/OAuth.html">OAuth for Web
+ * Applications</a> and the <a
+ * href="http://code.google.com/apis/gdata/docs/auth/oauth.html">GData developer
+ * guide for OAuth.</a>.
+ */
+public class GAuthComponent extends DefaultComponent {
+
+ private String consumerKey;
+
+ private String consumerSecret;
+
+ private GAuthKeyLoader keyLoader;
+
+ public GAuthComponent() {
+ this(null);
+ }
+
+ public GAuthComponent(CamelContext context) {
+ super(context);
+ }
+
+ public String getConsumerKey() {
+ return consumerKey;
+ }
+
+ public void setConsumerKey(String consumerKey) {
+ this.consumerKey = consumerKey;
+ }
+
+ public String getConsumerSecret() {
+ return consumerSecret;
+ }
+
+ public void setConsumerSecret(String consumerSecret) {
+ this.consumerSecret = consumerSecret;
+ }
+
+ public GAuthKeyLoader getKeyLoader() {
+ return keyLoader;
+ }
+
+ public void setKeyLoader(GAuthKeyLoader keyLoader) {
+ this.keyLoader = keyLoader;
+ }
+
+ @Override
+ public GAuthEndpoint createEndpoint(String uri) throws Exception {
+ return (GAuthEndpoint)super.createEndpoint(uri);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ GAuthEndpoint endpoint = new GAuthEndpoint(uri, this, remaining);
+ OutboundBinding authorizeBinding = resolveAndRemoveReferenceParameter(
+ parameters, "authorizeBindingRef", GAuthAuthorizeBinding.class, new GAuthAuthorizeBinding());
+ OutboundBinding upgradeBinding = resolveAndRemoveReferenceParameter(
+ parameters, "upgradeBindingRef", GAuthUpgradeBinding.class, new GAuthUpgradeBinding());
+ GAuthService service = resolveAndRemoveReferenceParameter(
+ parameters, "serviceRef", GAuthService.class, new GAuthServiceImpl(endpoint));
+ GAuthKeyLoader keyLoader = resolveAndRemoveReferenceParameter(
+ parameters, "keyLoaderRef", GAuthKeyLoader.class);
+ endpoint.setAuthorizeBinding(authorizeBinding);
+ endpoint.setUpgradeBinding(upgradeBinding);
+ endpoint.setService(service);
+ endpoint.setKeyLoader(keyLoader);
+ return endpoint;
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthEndpoint.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthEndpoint.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthEndpoint.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,303 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import java.security.PrivateKey;
+
+import com.google.gdata.client.authn.oauth.GoogleOAuthHelper;
+import com.google.gdata.client.authn.oauth.GoogleOAuthParameters;
+import com.google.gdata.client.authn.oauth.OAuthHelper;
+import com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer;
+import com.google.gdata.client.authn.oauth.OAuthRsaSha1Signer;
+import com.google.gdata.client.authn.oauth.OAuthSigner;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Represents a <a href="http://camel.apache.org/gauth.html">GAuth Endpoint</a>.
+ * Instances can have one of two names, either <code>authorize</code> for
+ * requesting an unauthorized request token or <code>upgrade</code> for
+ * upgrading an authorized request token to an access token. The corresponding
+ * endpoint URIs are <code>gauth:authorize</code> and <code>gauth:upgrade</code>
+ * , respectively.
+ */
+public class GAuthEndpoint extends DefaultEndpoint {
+
+ public static enum Name {
+
+ /**
+ * Name of the endpoint for requesting an unauthorized request token.
+ */
+ AUTHORIZE,
+
+ /**
+ * Name of the endpoint for upgrading an authorized request token to an
+ * access token.
+ */
+ UPGRADE
+
+ }
+
+ private OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> authorizeBinding;
+
+ private OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> upgradeBinding;
+
+ private Name name;
+
+ private String callback;
+
+ private String scope;
+
+ private String consumerKey;
+
+ private String consumerSecret;
+
+ private GAuthKeyLoader keyLoader;
+
+ private GAuthService service;
+
+ private PrivateKey cachedKey;
+
+ /**
+ * Creates a new GAuthEndpoint.
+ *
+ * @param endpointUri
+ * @param component
+ * component that created this endpoint.
+ * @param name
+ * either <code>authorize</code> or <code>upgrade</code>.
+ * @throws IllegalArgumentException
+ * if the endpoint name is invalid.
+ */
+ public GAuthEndpoint(String endpointUri, Component component, String name) {
+ super(endpointUri, component);
+ this.name = Name.valueOf(name.toUpperCase());
+ this.service = new GAuthServiceImpl(this);
+ }
+
+ public OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> getAuthorizeBinding() {
+ return authorizeBinding;
+ }
+
+ /**
+ * Sets the binding for <code>gauth:authorize</code> endpoints.
+ *
+ * @param authorizeBinding
+ * @see GAuthAuthorizeBinding
+ */
+ public void setAuthorizeBinding(OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> authorizeBinding) {
+ this.authorizeBinding = authorizeBinding;
+ }
+
+ public OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> getUpgradeBinding() {
+ return upgradeBinding;
+ }
+
+ /**
+ * Sets the binding for <code>gauth:upgrade</code> endpoints.
+ *
+ * @param upgradeBinding
+ * @see GAuthUpgradeBinding
+ */
+ public void setUpgradeBinding(OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> upgradeBinding) {
+ this.upgradeBinding = upgradeBinding;
+ }
+
+ /**
+ * Returns the component instance that created this endpoint.
+ */
+ public GAuthComponent getComponent() {
+ return (GAuthComponent)super.getComponent();
+ }
+
+ /**
+ * Returns the endpoint name.
+ */
+ public Name getName() {
+ return name;
+ }
+
+ /**
+ * Returns the value of callback query parameter in the
+ * <code>gauth:authorize</code> endpoint URI.
+ */
+ public String getCallback() {
+ return callback;
+ }
+
+ public void setCallback(String callback) {
+ this.callback = callback;
+ }
+
+ /**
+ * Returns the value of the scope query parameter in
+ * <code>gauth:authorize</code> endpoint URI. This can be a single scope or
+ * a comma-separated list of scopes.
+ */
+ public String getScope() {
+ return scope;
+ }
+
+ public void setScope(String services) {
+ this.scope = services;
+ }
+
+ /**
+ * Returns the value of the scope query parameter as array.
+ * @see #getScope()
+ */
+ public String[] getScopeArray() {
+ return getScope().split(",");
+ }
+
+ /**
+ * Returns the consumer key. If this endpoint's consumer key is
+ * <code>null</code> then {@link GAuthComponent#getConsumerKey()} is
+ * returned.
+ */
+ public String getConsumerKey() {
+ if (consumerKey == null) {
+ return getComponent().getConsumerKey();
+ }
+ return consumerKey;
+ }
+
+ /**
+ * Sets the consumer key. This key is generated when a web application is
+ * registered at Google.
+ *
+ * @param consumerKey
+ * consumer key to set.
+ */
+ public void setConsumerKey(String consumerKey) {
+ this.consumerKey = consumerKey;
+ }
+
+ /**
+ * Returns the consumer secret. If this endpoint's consumer secret is
+ * <code>null</code> then {@link GAuthComponent#getConsumerSecret()} is
+ * returned.
+ */
+ public String getConsumerSecret() {
+ if (consumerSecret == null) {
+ return getComponent().getConsumerSecret();
+ }
+ return consumerSecret;
+ }
+
+ /**
+ * Sets the consumer secret. This secret is generated when a web application
+ * is registered at Google. Only set the consumer secret if the HMAC-SHA1
+ * signature method shall be used.
+ *
+ * @param consumerSecret
+ * consumer secret to set.
+ */
+ public void setConsumerSecret(String consumerSecret) {
+ this.consumerSecret = consumerSecret;
+ }
+
+ /**
+ * Returns the key loader. If this endpoint's key loader is
+ * <code>null</code> then {@link GAuthComponent#getKeyLoader()} is
+ * returned.
+ */
+ public GAuthKeyLoader getKeyLoader() {
+ if (keyLoader == null) {
+ return getComponent().getKeyLoader();
+ }
+ return keyLoader;
+ }
+
+ /**
+ * Sets a key loader for loading a private key. A private key is required
+ * when the RSA-SHA1 signature method shall be used.
+ *
+ * @param keyLoader
+ * key loader to set.
+ */
+ public void setKeyLoader(GAuthKeyLoader keyLoader) {
+ this.keyLoader = keyLoader;
+ }
+
+ public GAuthService getService() {
+ return service;
+ }
+
+ /**
+ * Sets the service that makes the remote calls to Google services. Testing
+ * code should inject a mock service here (using serviceRef in endpoint
+ * URI).
+ *
+ * @param service
+ */
+ public void setService(GAuthService service) {
+ this.service = service;
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ */
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("consumption from gauth endpoint not supported");
+ }
+
+ /**
+ * Returns a {@link GAuthProducer}
+ */
+ public Producer createProducer() throws Exception {
+ return new GAuthProducer(this);
+ }
+
+ /**
+ * Returns <code>true</code>.
+ */
+ public boolean isSingleton() {
+ return true;
+ }
+
+ /**
+ * Creates an {@link OAuthHelper} configured with either an
+ * {@link OAuthHmacSha1Signer} or an {@link OAuthRsaSha1Signer}, depending
+ * on this endpoint's properties.
+ *
+ * @return
+ * @throws Exception
+ */
+ OAuthHelper newOAuthHelper() throws Exception {
+ OAuthSigner signer = null;
+ if (getKeyLoader() == null) {
+ signer = new OAuthHmacSha1Signer();
+ } else {
+ signer = new OAuthRsaSha1Signer(getPrivateKey());
+ }
+ return new GoogleOAuthHelper(signer);
+ }
+
+ private synchronized PrivateKey getPrivateKey() throws Exception {
+ if (cachedKey == null) {
+ cachedKey = getKeyLoader().loadPrivateKey();
+ }
+ return cachedKey;
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthException.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthException.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthException.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthException.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+@SuppressWarnings("serial")
+public class GAuthException extends RuntimeException {
+
+ public GAuthException() {
+ super();
+ }
+
+ public GAuthException(String message) {
+ super(message);
+ }
+
+ public GAuthException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public GAuthException(Throwable cause) {
+ super(cause);
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthJksLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthJksLoader.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthJksLoader.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthJksLoader.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.KeyStore.PasswordProtection;
+import java.security.KeyStore.PrivateKeyEntry;
+import java.security.PrivateKey;
+
+import org.springframework.core.io.Resource;
+
+/**
+ * A Java keystore specific key loader.
+ */
+public class GAuthJksLoader implements GAuthKeyLoader {
+
+ private Resource keyStoreLocation;
+
+ private String storePass;
+
+ private String keyPass;
+
+ private String keyAlias;
+
+ public GAuthJksLoader() {
+ this(null, null, null, null);
+ }
+
+ public GAuthJksLoader(Resource keyStoreLocation, String storePass, String keyPass, String keyAlias) {
+ this.keyStoreLocation = keyStoreLocation;
+ this.storePass = storePass;
+ this.keyPass = keyPass;
+ this.keyAlias = keyAlias;
+ }
+
+ /**
+ * Set the location of the Java keystore.
+ *
+ * @param keyStoreLocation
+ */
+ public void setKeyStoreLocation(Resource keyStoreLocation) {
+ this.keyStoreLocation = keyStoreLocation;
+ }
+
+ /**
+ * Sets the password used to open the key store.
+ *
+ * @param storePass
+ */
+ public void setStorePass(String storePass) {
+ this.storePass = storePass;
+ }
+
+ /**
+ * Sets the password used to get access to a specific key.
+ *
+ * @param keyPass
+ */
+ public void setKeyPass(String keyPass) {
+ this.keyPass = keyPass;
+ }
+
+ /**
+ * Sets the alias of the key to be loaded.
+ *
+ * @param keyAlias
+ */
+ public void setKeyAlias(String keyAlias) {
+ this.keyAlias = keyAlias;
+ }
+
+ /**
+ * Loads a private key from a Java keystore depending on this loader's
+ * properties.
+ */
+ public PrivateKey loadPrivateKey() throws Exception {
+ InputStream input = keyStoreLocation.getInputStream();
+ try {
+ return loadPrivateKey(input);
+ } finally {
+ input.close();
+ }
+ }
+
+ private PrivateKey loadPrivateKey(InputStream input) throws Exception {
+ // Load keystore
+ KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
+ keystore.load(input, storePass.toCharArray());
+
+ // Retrieve private key
+ PrivateKeyEntry entry = (PrivateKeyEntry)keystore.getEntry(keyAlias, new PasswordProtection(keyPass.toCharArray()));
+ return entry.getPrivateKey();
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthJksLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthKeyLoader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthKeyLoader.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthKeyLoader.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthKeyLoader.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import java.security.PrivateKey;
+
+/**
+ * Interface used by {@link GAuthComponent} for loading private keys. The private
+ * key is needed for RSA-SHA1 signatures.
+ */
+public interface GAuthKeyLoader {
+
+ /**
+ * Loads a private key.
+ *
+ * @return the loaded private key.
+ * @throws Exception
+ * if key loading failed.
+ */
+ PrivateKey loadPrivateKey() throws Exception;
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthKeyLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthPk8Loader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthPk8Loader.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthPk8Loader.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthPk8Loader.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import java.security.KeyFactory;
+import java.security.PrivateKey;
+import java.security.spec.PKCS8EncodedKeySpec;
+
+import com.google.gdata.util.common.util.Base64;
+
+import org.apache.commons.io.IOUtils;
+import org.springframework.core.io.Resource;
+
+/**
+ * A Java PKCS#8-specific key loader.
+ */
+public class GAuthPk8Loader implements GAuthKeyLoader {
+
+ private static final String BEGIN = "-----BEGIN PRIVATE KEY-----";
+ private static final String END = "-----END PRIVATE KEY-----";
+
+ private Resource keyLocation;
+
+ /**
+ * Sets the location of the PKCS#8 file that contains a private key.
+ *
+ * @param keyLocation
+ */
+ public void setKeyLocation(Resource keyLocation) {
+ this.keyLocation = keyLocation;
+ }
+
+ /**
+ * Loads a private key from a PKCS#8 file.
+ */
+ public PrivateKey loadPrivateKey() throws Exception {
+ String str = IOUtils.toString(keyLocation.getInputStream());
+
+ if (str.contains(BEGIN) && str.contains(END)) {
+ str = str.substring(BEGIN.length(), str.lastIndexOf(END));
+ }
+
+ KeyFactory factory = KeyFactory.getInstance("RSA");
+ return factory.generatePrivate(new PKCS8EncodedKeySpec(Base64.decode(str)));
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthPk8Loader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthProducer.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthProducer.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthProducer.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import com.google.gdata.client.authn.oauth.GoogleOAuthParameters;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+import org.apache.camel.impl.DefaultProducer;
+
+import static org.apache.camel.component.gae.auth.GAuthEndpoint.Name.AUTHORIZE;
+
+public class GAuthProducer extends DefaultProducer {
+
+ public GAuthProducer(GAuthEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public GAuthEndpoint getEndpoint() {
+ return (GAuthEndpoint)super.getEndpoint();
+ }
+
+ public OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> getAuthorizeBinding() {
+ return getEndpoint().getAuthorizeBinding();
+ }
+
+ public OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> getUpgradeBinding() {
+ return getEndpoint().getUpgradeBinding();
+ }
+
+ /**
+ * Depending on the {@link GAuthEndpoint.Name}, this method either fetches
+ * an unauthorized request token and creates a redirect response, or
+ * upgrades an authorized request token to an access token.
+ *
+ * @param exchange
+ *
+ * @see GAuthAuthorizeBinding
+ * @see GAuthUpgradeBinding
+ * @see GAuthServiceImpl
+ */
+ public void process(Exchange exchange) throws Exception {
+ if (getEndpoint().getName() == AUTHORIZE) {
+ GoogleOAuthParameters params = getAuthorizeBinding().writeRequest(getEndpoint(), exchange, null);
+ getEndpoint().getService().getUnauthorizedRequestToken(params);
+ getAuthorizeBinding().readResponse(getEndpoint(), exchange, params);
+ } else {
+ GoogleOAuthParameters params = getUpgradeBinding().writeRequest(getEndpoint(), exchange, null);
+ getEndpoint().getService().getAccessToken(params);
+ getUpgradeBinding().readResponse(getEndpoint(), exchange, params);
+ }
+
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthService.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthService.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthService.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthService.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import com.google.gdata.client.authn.oauth.OAuthParameters;
+
+/**
+ * Interface to Google's OAuth services.
+ */
+public interface GAuthService {
+
+ /**
+ * Gets an unauthorized request token from Google.
+ *
+ * @param oauthParameters
+ * value object for providing input data and storing result data
+ * (unauthorized request token).
+ * @throws Exception
+ */
+ void getUnauthorizedRequestToken(OAuthParameters oauthParameters) throws Exception;
+
+ /**
+ * Gets an access token from Google.
+ *
+ * @param oauthParameters
+ * value object for providing input data (authorized request
+ * token) and storing result data (access token).
+ * @throws Exception
+ */
+ void getAccessToken(OAuthParameters oauthParameters) throws Exception;
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthServiceImpl.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthServiceImpl.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthServiceImpl.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthServiceImpl.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import com.google.gdata.client.authn.oauth.OAuthParameters;
+
+/**
+ * Implements the remote interaction to Google's OAuth services.
+ */
+class GAuthServiceImpl implements GAuthService {
+
+ private GAuthEndpoint endpoint;
+
+ public GAuthServiceImpl(GAuthEndpoint endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public void getUnauthorizedRequestToken(OAuthParameters oauthParameters) throws Exception {
+ endpoint.newOAuthHelper().getUnauthorizedRequestToken(oauthParameters);
+ }
+
+ public void getAccessToken(OAuthParameters oauthParameters) throws Exception {
+ endpoint.newOAuthHelper().getAccessToken(oauthParameters);
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthTokenSecret.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthTokenSecret.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthTokenSecret.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthTokenSecret.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+/**
+ * A request token secret container with marshalling/unmarshalling methods to
+ * and from a cookie.
+ *
+ * @see GAuthAuthorizeBinding
+ * @see GAuthUpgradeBinding
+ */
+public class GAuthTokenSecret {
+
+ /**
+ * Name of the request token secret cookie.
+ */
+ public static final String COOKIE_NAME = "gauth-token-secret";
+
+ private String value;
+
+ /**
+ * Creates a new {@link GAuthTokenSecret}
+ *
+ * @param value
+ * request token secret.
+ */
+ public GAuthTokenSecret(String value) {
+ this.value = value;
+ }
+
+ /**
+ * Returns the request token secret.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Creates a cookie from this {@link GAuthTokenSecret}.
+ */
+ public String toCookie() {
+ return COOKIE_NAME + "=" + value;
+ }
+
+ /**
+ * Create a {@link GAuthTokenSecret} from a cookies string.
+ *
+ * @param cookies
+ * cookies string.
+ * @return either an {@link GAuthTokenSecret} instance or <code>null</code>
+ * if there's no cookie with name {@link #COOKIE_NAME}.
+ */
+ public static GAuthTokenSecret fromCookie(String cookies) {
+ if (cookies == null) {
+ return null;
+ }
+ for (String cookie : cookies.split(";")) {
+ String[] pair = cookie.split("=");
+ if (pair[0].trim().equals(COOKIE_NAME)) {
+ return new GAuthTokenSecret(pair[1].trim());
+ }
+ }
+ return null;
+ }
+
+}
+
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthTokenSecret.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.auth;
+
+import java.io.IOException;
+
+import com.google.gdata.client.authn.oauth.GoogleOAuthParameters;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+
+/**
+ * Binds {@link GoogleOAuthParameters} to a Camel {@link Exchange}. This binding
+ * is used by <code>gauth:upgrade</code> endpoints by default.
+ */
+public class GAuthUpgradeBinding implements OutboundBinding<GAuthEndpoint, GoogleOAuthParameters, GoogleOAuthParameters> {
+
+ /**
+ * Name of the Camel header containing an access token.
+ */
+ public static final String GAUTH_ACCESS_TOKEN = "CamelGauthAccessToken";
+
+ /**
+ * Name of the Camel header containing an access token secret.
+ */
+ public static final String GAUTH_ACCESS_TOKEN_SECRET = "CamelGauthAccessTokenSecret";
+
+ /**
+ * Creates a {@link GoogleOAuthParameters} object from endpoint and
+ * <code>exchange.getIn()</code> data. The created parameter object is used
+ * to upgrade an authorized request token to an access token. If the
+ * {@link GAuthComponent} is configured to use the HMAC_SHA1 signature
+ * method, a request token secret is obtained from a
+ * {@link GAuthTokenSecret#COOKIE_NAME} cookie.
+ *
+ * @param endpoint
+ * @param exchange
+ * @param request
+ * ignored.
+ * @return
+ * @throws GAuthException
+ * if the {@link GAuthComponent} is configured to use the
+ * HMAC_SHA1 signature method but there's no cookie with the
+ * request token secret.
+ */
+ public GoogleOAuthParameters writeRequest(GAuthEndpoint endpoint, Exchange exchange, GoogleOAuthParameters request) throws Exception {
+ request = new GoogleOAuthParameters();
+ request.setOAuthConsumerKey(endpoint.getConsumerKey());
+ request.setOAuthConsumerSecret(endpoint.getConsumerSecret());
+ request.setOAuthToken(exchange.getIn().getHeader("oauth_token", String.class));
+ request.setOAuthVerifier(exchange.getIn().getHeader("oauth_verifier", String.class));
+
+ if (endpoint.getComponent().getKeyLoader() == null) {
+ // HMAC_SHA signature is used for getting an access token.
+ // The required token secret has been previously stored as cookie.
+ String cookie = exchange.getIn().getHeader("Cookie", String.class);
+ GAuthTokenSecret tokenSecret = GAuthTokenSecret.fromCookie(cookie);
+ if (tokenSecret == null) {
+ throw new GAuthException(GAuthTokenSecret.COOKIE_NAME + " cookie doesn't exist");
+ }
+ request.setOAuthTokenSecret(tokenSecret.getValue());
+ }
+ return request;
+ }
+
+ /**
+ * Creates an <code>exchange.getOut()</code> message that containing the
+ * access token and the access token secret in the message header.
+ *
+ * @param endpoint
+ * @param exchange
+ * @param response
+ * @return
+ * @see #GAUTH_ACCESS_TOKEN
+ * @see #GAUTH_ACCESS_TOKEN_SECRET
+ */
+ public Exchange readResponse(GAuthEndpoint endpoint, Exchange exchange, GoogleOAuthParameters response) throws IOException {
+ exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN, response.getOAuthToken());
+ exchange.getOut().setHeader(GAUTH_ACCESS_TOKEN_SECRET, response.getOAuthTokenSecret());
+ return exchange;
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/auth/GAuthUpgradeBinding.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/bind/HttpBindingInvocationHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/bind/HttpBindingInvocationHandler.java?rev=907402&r1=907401&r2=907402&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/bind/HttpBindingInvocationHandler.java (original)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/bind/HttpBindingInvocationHandler.java Sun Feb 7 09:38:41 2010
@@ -20,6 +20,7 @@
import java.lang.reflect.Method;
import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
import org.apache.camel.component.http.HttpBinding;
import org.apache.camel.component.http.HttpMessage;
@@ -46,9 +47,12 @@
HttpMessage message = (HttpMessage)args[1];
// prepare exchange for further inbound binding operations
message.getExchange().setIn(message);
- // delegate further binding operations to inbound binding
+ // delegate further request binding operations to inbound binding
inboundBinding.readRequest(endpoint, message.getExchange(), (S)args[0]);
- }
+ } else if (method.getName().equals("writeResponse") && (args.length == 2)) {
+ // delegate further response binding operations to inbound binding
+ inboundBinding.writeResponse(endpoint, (Exchange)args[0], (T)args[1]);
+ }
return result;
}
Modified: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpBinding.java?rev=907402&r1=907401&r2=907402&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpBinding.java (original)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpBinding.java Sun Feb 7 09:38:41 2010
@@ -107,11 +107,8 @@
return exchange;
}
- /**
- * @throws UnsupportedOperationException.
- */
public HttpServletResponse writeResponse(GHttpEndpoint endpoint, Exchange exchange, HttpServletResponse response) {
- throw new UnsupportedOperationException("gtask responses not supported");
+ return response;
}
// ----------------------------------------------------------------
@@ -146,7 +143,7 @@
exchange.getIn().removeHeader("Accept-Encoding");
exchange.getIn().removeHeader("Content-Encoding");
}
-
+
protected void writeRequestHeaders(GHttpEndpoint endpoint, Exchange exchange, HTTPRequest request) {
HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
for (String headerName : exchange.getIn().getHeaders().keySet()) {
Modified: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java?rev=907402&r1=907401&r2=907402&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java (original)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpComponent.java Sun Feb 7 09:38:41 2010
@@ -32,7 +32,7 @@
import org.apache.commons.httpclient.params.HttpClientParams;
/**
- * The <a href="http://camel.apache.org/todo.html">Google App Engine HTTP
+ * The <a href="http://camel.apache.org/ghttp.html">Google App Engine HTTP
* Component</a> supports HTTP-based inbound and outbound communication. Inbound
* HTTP communication is realized in terms of the <a
* href="http://camel.apache.org/servlet.html"> Servlet Component</a> component.
Modified: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpEndpoint.java?rev=907402&r1=907401&r2=907402&view=diff
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpEndpoint.java (original)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/http/GHttpEndpoint.java Sun Feb 7 09:38:41 2010
@@ -45,7 +45,7 @@
import org.apache.commons.httpclient.params.HttpClientParams;
/**
- * Represents a <a href="http://camel.apache.org/todo.html">Google App Engine
+ * Represents a <a href="http://camel.apache.org/ghttp.html">Google App Engine
* HTTP endpoint</a>.
*/
public class GHttpEndpoint extends ServletEndpoint implements OutboundBindingSupport<GHttpEndpoint, HTTPRequest, HTTPResponse> {
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginBinding.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginBinding.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginBinding.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.login;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+
+/**
+ * Binds {@link GLoginData} to a Camel {@link Exchange}.
+ */
+public class GLoginBinding implements OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> {
+
+ /**
+ * Name of the Camel header defining the host name. Overrides
+ * {@link GLoginEndpoint#getHostName()}.
+ */
+ public static final String GLOGIN_HOST_NAME = "CamelGloginHostName";
+
+ /**
+ * Name of the Camel header defining the login username. Overrides
+ * {@link GLoginEndpoint#getUserName()}.
+ */
+ public static final String GLOGIN_USER_NAME = "CamelGloginUserName";
+
+ /**
+ * Name of the Camel header defining the login password. Overrides
+ * {@link GLoginEndpoint#getPassword()}.
+ */
+ public static final String GLOGIN_PASSWORD = "CamelGloginPassword";
+
+ /**
+ * Name of the Camel header containing the resulting authentication token.
+ */
+ public static final String GLOGIN_TOKEN = "CamelGloginToken";
+
+ /**
+ * Name of the Camel header containing the resulting authorization cookie.
+ */
+ public static final String GLOGIN_COOKIE = "CamelGloginCookie";
+
+ /**
+ * Creates a {@link GLoginData} object from endpoint and
+ * <code>exchange.getIn()</code> header data. The created object is used to
+ * obtain an authentication token and an authorization cookie.
+ *
+ * @param endpoint
+ * @param exchange
+ * @param request
+ * ignored.
+ * @return
+ */
+ public GLoginData writeRequest(GLoginEndpoint endpoint, Exchange exchange, GLoginData request) {
+ String hostName = exchange.getIn().getHeader(GLOGIN_HOST_NAME, String.class);
+ String userName = exchange.getIn().getHeader(GLOGIN_USER_NAME, String.class);
+ String password = exchange.getIn().getHeader(GLOGIN_PASSWORD, String.class);
+
+ request = new GLoginData();
+ if (hostName == null) {
+ hostName = endpoint.getHostName();
+ }
+ if (userName == null) {
+ userName = endpoint.getUserName();
+ }
+ if (password == null) {
+ password = endpoint.getPassword();
+ }
+ request.setClientName(endpoint.getClientName());
+ request.setDevAdmin(endpoint.isDevAdmin());
+ request.setDevPort(endpoint.getDevPort());
+ request.setDevMode(endpoint.isDevMode());
+ request.setHostName(hostName);
+ request.setUserName(userName);
+ request.setPassword(password);
+ return request;
+ }
+
+ /**
+ * Creates an <code>exchange.getOut()</code> message with a
+ * {@link #GLOGIN_TOKEN} header containing an authentication token and a
+ * {@link #GLOGIN_COOKIE} header containing an authorization cookie. If the
+ * endpoint is configured to run in development mode, no authentication
+ * token will be set, only an authorization cookie.
+ *
+ * @param endpoint
+ * @param exchange
+ * @param response
+ * @return
+ */
+ public Exchange readResponse(GLoginEndpoint endpoint, Exchange exchange, GLoginData response) throws Exception {
+ if (response.getAuthenticationToken() != null) {
+ exchange.getOut().setHeader(GLOGIN_TOKEN, response.getAuthenticationToken());
+ }
+ if (response.getAuthorizationCookie() != null) {
+ exchange.getOut().setHeader(GLOGIN_COOKIE, response.getAuthorizationCookie());
+ }
+ return exchange;
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginBinding.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginComponent.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginComponent.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginComponent.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.login;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.component.gae.auth.GAuthComponent;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * The <a href="http://camel.apache.org/glogin.html">GLogin Component</a>
+ * encapsulates the required steps needed to login to an Google App Engine (GAE)
+ * application. This component uses <a
+ * href="http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html"
+ * >ClientLogin</a> for authentication and a GAE-specific mechanism for
+ * authorization. Result of the login procedure is an authorization cookie that
+ * should be included in HTTP requests targeted at GAE applications. This
+ * component is intended for being used by Java client applications that want to
+ * do a programmatic login to GAE applications. Web applications should use the
+ * {@link GAuthComponent} for access authorization to other web applications.
+ */
+public class GLoginComponent extends DefaultComponent {
+
+ public GLoginComponent() {
+ this(null);
+ }
+
+ public GLoginComponent(CamelContext context) {
+ super(context);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ OutboundBinding outboundBinding = resolveAndRemoveReferenceParameter(
+ parameters, "outboundBindingRef", GLoginBinding.class, new GLoginBinding());
+ GLoginService service = resolveAndRemoveReferenceParameter(
+ parameters, "serviceRef", GLoginService.class, new GLoginServiceImpl());
+ GLoginEndpoint endpoint = new GLoginEndpoint(uri, this,
+ getHostName(remaining),
+ getDevPort(remaining));
+ endpoint.setOutboundBinding(outboundBinding);
+ endpoint.setService(service);
+ return endpoint;
+ }
+
+ private static String getHostName(String remaining) {
+ if (remaining.contains(":")) {
+ return remaining.split(":")[0];
+ } else {
+ return remaining;
+ }
+ }
+
+ private static int getDevPort(String remaining) {
+ if (remaining.contains(":")) {
+ return Integer.parseInt(remaining.split(":")[1]);
+ } else {
+ return 8080;
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginData.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginData.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginData.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginData.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,133 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.login;
+
+/**
+ * Container for login request and response data.
+ */
+public class GLoginData {
+
+ private String hostName;
+
+ private String clientName;
+
+ private String userName;
+
+ private String password;
+
+ private int devPort;
+
+ private boolean devAdmin;
+
+ private boolean devMode;
+
+ private String authenticationToken;
+
+ private String authorizationCookie;
+
+ /**
+ * @see GLoginEndpoint#getHostName()
+ * @see GLoginBinding#GLOGIN_HOST_NAME
+ */
+ public String getHostName() {
+ return hostName;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ public String getClientName() {
+ return clientName;
+ }
+
+ public void setClientName(String clientName) {
+ this.clientName = clientName;
+ }
+
+ /**
+ * @see GLoginBinding#GLOGIN_USER_NAME
+ */
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ /**
+ * @see GLoginBinding#GLOGIN_PASSWORD
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * @see GLoginEndpoint#getDevPort()
+ */
+ public int getDevPort() {
+ return devPort;
+ }
+
+ public void setDevPort(int devPort) {
+ this.devPort = devPort;
+ }
+
+ public boolean isDevAdmin() {
+ return devAdmin;
+ }
+
+ public void setDevAdmin(boolean devAdmin) {
+ this.devAdmin = devAdmin;
+ }
+
+ public boolean isDevMode() {
+ return devMode;
+ }
+
+ public void setDevMode(boolean devMode) {
+ this.devMode = devMode;
+ }
+
+ public String getAuthenticationToken() {
+ return authenticationToken;
+ }
+
+ /**
+ * @see GLoginBinding#GLOGIN_TOKEN
+ */
+ public void setAuthenticationToken(String authenticationToken) {
+ this.authenticationToken = authenticationToken;
+ }
+
+ public String getAuthorizationCookie() {
+ return authorizationCookie;
+ }
+
+ /**
+ * @see GLoginBinding#GLOGIN_COOKIE
+ */
+ public void setAuthorizationCookie(String authorizationCookie) {
+ this.authorizationCookie = authorizationCookie;
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginData.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginEndpoint.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginEndpoint.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginEndpoint.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,210 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.login;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Represents a <a href="http://camel.apache.org/glogin.html">GLogin
+ * Endpoint</a>.
+ */
+public class GLoginEndpoint extends DefaultEndpoint {
+
+ private OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> outboundBinding;
+
+ private String hostName;
+
+ private String clientName;
+
+ private String userName;
+
+ private String password;
+
+ private int devPort;
+
+ private boolean devAdmin;
+
+ private boolean devMode;
+
+ private GLoginService service;
+
+ /**
+ * Creates a new GLoginEndpoint.
+ *
+ * @param endpointUri
+ * @param component
+ * component that created this endpoint.
+ * @param hostName
+ * internet hostname of a GAE application, for example
+ * <code>example.appspot.com</code>, or <code>localhost</code> if
+ * the application is running on a local development server.
+ * @param devPort
+ * port for connecting to the local development server.
+ */
+ public GLoginEndpoint(String endpointUri, Component component, String hostName, int devPort) {
+ super(endpointUri, component);
+ this.hostName = hostName;
+ this.clientName = "apache-camel-2.x";
+ this.devPort = devPort;
+ this.devAdmin = false;
+ }
+
+ /**
+ * Returns the component instance that created this endpoint.
+ */
+ @Override
+ public GLoginComponent getComponent() {
+ return (GLoginComponent)super.getComponent();
+ }
+
+ /**
+ * Returns the internet hostname of the GAE application where to login.
+ */
+ public String getHostName() {
+ return hostName;
+ }
+
+ public OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> getOutboundBinding() {
+ return outboundBinding;
+ }
+
+ /**
+ * Sets the outbound binding for <code>glogin</code> endpoints. Default binding
+ * is {@link GLoginBinding}.
+ */
+ public void setOutboundBinding(OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> outboundBinding) {
+ this.outboundBinding = outboundBinding;
+ }
+
+ public String getClientName() {
+ return clientName;
+ }
+
+ /**
+ * Sets the client name used for authentication. The default name is
+ * <code>apache-camel-2.x</code>.
+ *
+ * @param clientName
+ */
+ public void setClientName(String clientName) {
+ this.clientName = clientName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ /**
+ * Sets the login username (a Google mail address).
+ *
+ * @param userName
+ */
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Sets the login password.
+ *
+ * @param password
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * Returns the port for connecting to a development server. Only used
+ * if {@link #devMode} is <code>true</code>. Default is 8080.
+ */
+ public int getDevPort() {
+ return devPort;
+ }
+
+ public boolean isDevAdmin() {
+ return devAdmin;
+ }
+
+ /**
+ * Set to <code>true</code> for logging in as admin to a development server.
+ * Only used if {@link #devMode} is <code>true</code>. Default is
+ * <code>false</code>.
+ *
+ * @param devAdmin
+ */
+ public void setDevAdmin(boolean devAdmin) {
+ this.devAdmin = devAdmin;
+ }
+
+ public boolean isDevMode() {
+ return devMode;
+ }
+
+ /**
+ * Set to <code>true</code> for connecting to a development server.
+ *
+ * @param devMode
+ */
+ public void setDevMode(boolean devMode) {
+ this.devMode = devMode;
+ }
+
+ public GLoginService getService() {
+ return service;
+ }
+
+ /**
+ * Sets the service that makes the remote calls to Google services or the
+ * local development server. Testing code should inject a mock service here
+ * (using serviceRef in endpoint URI).
+ *
+ * @param service
+ */
+ public void setService(GLoginService service) {
+ this.service = service;
+ }
+
+ /**
+ * Creates a {@link GLoginProducer}.
+ */
+ public Producer createProducer() throws Exception {
+ return new GLoginProducer(this);
+ }
+
+ /**
+ * throws {@link UnsupportedOperationException}
+ */
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("consumption from glogin endpoint not supported");
+ }
+
+ /**
+ * Returns <code>true</code>.
+ */
+ public boolean isSingleton() {
+ return true;
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginProducer.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginProducer.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginProducer.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.login;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.gae.bind.OutboundBinding;
+import org.apache.camel.impl.DefaultProducer;
+
+public class GLoginProducer extends DefaultProducer {
+
+ public GLoginProducer(GLoginEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public GLoginEndpoint getEndpoint() {
+ return (GLoginEndpoint)super.getEndpoint();
+ }
+
+ public OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> getOutboundBinding() {
+ return getEndpoint().getOutboundBinding();
+ }
+
+ public GLoginService getService() {
+ return getEndpoint().getService();
+ }
+
+ /**
+ * First obtains an authentication token and then exchanges the token against
+ * an authorization cookie.
+ *
+ * @param exchange
+ *
+ * @see GLoginBinding
+ * @see GLoginServiceImpl
+ */
+ public void process(Exchange exchange) throws Exception {
+ GLoginData data = getOutboundBinding().writeRequest(getEndpoint(), exchange, null);
+ getService().authenticate(data);
+ getOutboundBinding().readResponse(getEndpoint(), exchange, data);
+ getService().authorize(data);
+ getOutboundBinding().readResponse(getEndpoint(), exchange, data);
+ }
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginService.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginService.java?rev=907402&view=auto
==============================================================================
--- camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginService.java (added)
+++ camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginService.java Sun Feb 7 09:38:41 2010
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.gae.login;
+
+/**
+ * Interface to login services.
+ */
+public interface GLoginService {
+
+ /**
+ * Authenticates a user and stores the authentication token to
+ * {@link GLoginData#setAuthenticationToken(String)} (only if needed by
+ * {@link #authorize(GLoginData)}).
+ *
+ * @param data
+ * authentication input data and response data (authentication
+ * token) container.
+ * @throws Exception
+ */
+ void authenticate(GLoginData data) throws Exception;
+
+ /**
+ * Authorizes access to an application and stores an authorization cookie to
+ * {@link GLoginData#setAuthorizationCookie(String)}.
+ *
+ * @param data
+ * authentication input data and response data (authorization
+ * cookie) container.
+ * @throws Exception
+ */
+ void authorize(GLoginData data) throws Exception;
+
+}
Propchange: camel/trunk/components/camel-gae/src/main/java/org/apache/camel/component/gae/login/GLoginService.java
------------------------------------------------------------------------------
svn:eol-style = native