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