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    private Boolean inHeader;
040
041    @XmlAttribute(name = "inQuery")
042    private Boolean inQuery;
043
044    public RestSecurityApiKey() {
045    }
046
047    public RestSecurityApiKey(RestDefinition rest) {
048        super(rest);
049    }
050
051    public String getName() {
052        return name;
053    }
054
055    /**
056     * The name of the header or query parameter to be used.
057     */
058    public void setName(String name) {
059        this.name = name;
060    }
061
062    public Boolean getInHeader() {
063        return inHeader;
064    }
065
066    /**
067     * To use header as the location of the API key.
068     */
069    public void setInHeader(Boolean inHeader) {
070        this.inHeader = inHeader;
071    }
072
073    public Boolean getInQuery() {
074        return inQuery;
075    }
076
077    /**
078     * To use query parameter as the location of the API key.
079     */
080    public void setInQuery(Boolean inQuery) {
081        this.inQuery = inQuery;
082    }
083
084    public RestSecurityApiKey withHeader(String name) {
085        setName(name);
086        setInHeader(true);
087        setInQuery(false);
088        return this;
089    }
090
091    public RestSecurityApiKey withQuery(String name) {
092        setName(name);
093        setInQuery(true);
094        setInHeader(false);
095        return this;
096    }
097
098    public RestSecuritiesDefinition end() {
099        return rest.getSecurityDefinitions();
100    }
101}