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.login;
018
019 import org.apache.camel.Exchange;
020 import org.apache.camel.component.gae.bind.OutboundBinding;
021 import org.apache.camel.impl.DefaultProducer;
022
023 public class GLoginProducer extends DefaultProducer {
024
025 public GLoginProducer(GLoginEndpoint endpoint) {
026 super(endpoint);
027 }
028
029 @Override
030 public GLoginEndpoint getEndpoint() {
031 return (GLoginEndpoint)super.getEndpoint();
032 }
033
034 public OutboundBinding<GLoginEndpoint, GLoginData, GLoginData> getOutboundBinding() {
035 return getEndpoint().getOutboundBinding();
036 }
037
038 public GLoginService getService() {
039 return getEndpoint().getService();
040 }
041
042 /**
043 * First obtains an authentication token and then exchanges the token against
044 * an authorization cookie.
045 *
046 * @param exchange
047 *
048 * @see GLoginBinding
049 * @see GLoginServiceImpl
050 */
051 public void process(Exchange exchange) throws Exception {
052 GLoginData data = getOutboundBinding().writeRequest(getEndpoint(), exchange, null);
053 getService().authenticate(data);
054 getOutboundBinding().readResponse(getEndpoint(), exchange, data);
055 getService().authorize(data);
056 getOutboundBinding().readResponse(getEndpoint(), exchange, data);
057 }
058
059 }