001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.component.gae.auth;
018    
019    import java.util.Map;
020    
021    import org.apache.camel.CamelContext;
022    import org.apache.camel.Endpoint;
023    import org.apache.camel.component.gae.bind.OutboundBinding;
024    import org.apache.camel.impl.DefaultComponent;
025    
026    /**
027     * The <a href="http://camel.apache.org/gauth.html">GAuth Component</a>
028     * implements a Google-specific OAuth comsumer. This component supports OAuth
029     * 1.0a. For background information refer to <a
030     * href="http://code.google.com/apis/accounts/docs/OAuth.html">OAuth for Web
031     * Applications</a> and the <a
032     * href="http://code.google.com/apis/gdata/docs/auth/oauth.html">GData developer
033     * guide for OAuth.</a>.
034     */
035    public class GAuthComponent extends DefaultComponent {
036    
037        private String consumerKey;
038        
039        private String consumerSecret;
040    
041        private GAuthKeyLoader keyLoader;
042    
043        public GAuthComponent() {
044            this(null);
045        }
046    
047        public GAuthComponent(CamelContext context) {
048            super(context);
049        }
050    
051        public String getConsumerKey() {
052            return consumerKey;
053        }
054    
055        public void setConsumerKey(String consumerKey) {
056            this.consumerKey = consumerKey;
057        }
058    
059        public String getConsumerSecret() {
060            return consumerSecret;
061        }
062    
063        public void setConsumerSecret(String consumerSecret) {
064            this.consumerSecret = consumerSecret;
065        }
066    
067        public GAuthKeyLoader getKeyLoader() {
068            return keyLoader;
069        }
070    
071        public void setKeyLoader(GAuthKeyLoader keyLoader) {
072            this.keyLoader = keyLoader;
073        }
074    
075        @Override
076        public GAuthEndpoint createEndpoint(String uri) throws Exception {
077            return (GAuthEndpoint)super.createEndpoint(uri);
078        }
079    
080        @Override
081        @SuppressWarnings("unchecked")
082        protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
083            GAuthEndpoint endpoint = new GAuthEndpoint(uri, this, remaining);
084            OutboundBinding authorizeBinding = resolveAndRemoveReferenceParameter(
085                    parameters, "authorizeBindingRef", GAuthAuthorizeBinding.class, new GAuthAuthorizeBinding());
086            OutboundBinding upgradeBinding = resolveAndRemoveReferenceParameter(
087                    parameters, "upgradeBindingRef", GAuthUpgradeBinding.class, new GAuthUpgradeBinding());
088            GAuthService service = resolveAndRemoveReferenceParameter(
089                    parameters, "serviceRef", GAuthService.class, new GAuthServiceImpl(endpoint));
090            GAuthKeyLoader keyLoader = resolveAndRemoveReferenceParameter(
091                    parameters, "keyLoaderRef", GAuthKeyLoader.class);
092            endpoint.setAuthorizeBinding(authorizeBinding);
093            endpoint.setUpgradeBinding(upgradeBinding);
094            endpoint.setService(service);
095            endpoint.setKeyLoader(keyLoader);
096            return endpoint;
097        }
098    
099    }