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 */
017package org.apache.camel.model.rest;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023
024import org.apache.camel.spi.Metadata;
025
026/**
027 * Rest security basic auth definition
028 */
029@Metadata(label = "rest")
030@XmlRootElement(name = "apiKey")
031@XmlAccessorType(XmlAccessType.FIELD)
032public class RestSecurityApiKey extends RestSecurityDefinition {
033
034    @XmlAttribute(name = "name", required = true)
035    @Metadata(required = true)
036    private String name;
037
038    @XmlAttribute(name = "inHeader")
039    @Metadata(javaType = "java.lang.Boolean")
040    private String inHeader;
041
042    @XmlAttribute(name = "inQuery")
043    @Metadata(javaType = "java.lang.Boolean")
044    private String inQuery;
045
046    public RestSecurityApiKey() {
047    }
048
049    public RestSecurityApiKey(RestDefinition rest) {
050        super(rest);
051    }
052
053    public String getName() {
054        return name;
055    }
056
057    /**
058     * The name of the header or query parameter to be used.
059     */
060    public void setName(String name) {
061        this.name = name;
062    }
063
064    public String getInHeader() {
065        return inHeader;
066    }
067
068    /**
069     * To use header as the location of the API key.
070     */
071    public void setInHeader(String inHeader) {
072        this.inHeader = inHeader;
073    }
074
075    public String getInQuery() {
076        return inQuery;
077    }
078
079    /**
080     * To use query parameter as the location of the API key.
081     */
082    public void setInQuery(String inQuery) {
083        this.inQuery = inQuery;
084    }
085
086    public RestSecurityApiKey withHeader(String name) {
087        setName(name);
088        setInHeader(Boolean.toString(true));
089        setInQuery(Boolean.toString(false));
090        return this;
091    }
092
093    public RestSecurityApiKey withQuery(String name) {
094        setName(name);
095        setInQuery(Boolean.toString(true));
096        setInHeader(Boolean.toString(false));
097        return this;
098    }
099
100    public RestSecuritiesDefinition end() {
101        return rest.getSecurityDefinitions();
102    }
103}