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 java.util.ArrayList; 020import java.util.List; 021import javax.xml.bind.annotation.XmlAccessType; 022import javax.xml.bind.annotation.XmlAccessorType; 023import javax.xml.bind.annotation.XmlElement; 024import javax.xml.bind.annotation.XmlElements; 025import javax.xml.bind.annotation.XmlRootElement; 026import javax.xml.bind.annotation.XmlTransient; 027 028import org.apache.camel.spi.Metadata; 029 030/** 031 * To configure security definition 032 */ 033@Metadata(label = "rest,security", title = "Security Definitions") 034@XmlRootElement(name = "securityDefinitions") 035@XmlAccessorType(XmlAccessType.FIELD) 036public class RestSecuritiesDefinition { 037 038 @XmlTransient 039 private RestDefinition rest; 040 041 @XmlElements({ 042 @XmlElement(name = "apiKey", type = RestSecurityApiKey.class), 043 @XmlElement(name = "basicAuth", type = RestSecurityBasicAuth.class), 044 @XmlElement(name = "oauth2", type = RestSecurityOAuth2.class) 045 }) 046 private List<RestSecurityDefinition> securityDefinitions = new ArrayList<>(); 047 048 public RestSecuritiesDefinition() { 049 } 050 051 public RestSecuritiesDefinition(RestDefinition rest) { 052 this.rest = rest; 053 } 054 055 public List<RestSecurityDefinition> getSecurityDefinitions() { 056 return securityDefinitions; 057 } 058 059 public void setSecurityDefinitions(List<RestSecurityDefinition> securityDefinitions) { 060 this.securityDefinitions = securityDefinitions; 061 } 062 063 public RestSecurityApiKey apiKey(String key) { 064 return apiKey(key, null); 065 } 066 067 public RestSecurityApiKey apiKey(String key, String description) { 068 RestSecurityApiKey auth = new RestSecurityApiKey(rest); 069 auth.setKey(key); 070 auth.setDescription(description); 071 securityDefinitions.add(auth); 072 return auth; 073 } 074 075 public RestSecuritiesDefinition basicAuth(String key) { 076 return basicAuth(key, null); 077 } 078 079 public RestSecuritiesDefinition basicAuth(String key, String description) { 080 RestSecurityBasicAuth auth = new RestSecurityBasicAuth(rest); 081 securityDefinitions.add(auth); 082 auth.setKey(key); 083 auth.setDescription(description); 084 return this; 085 } 086 087 public RestSecurityOAuth2 oauth2(String key) { 088 return oauth2(key, null); 089 } 090 091 public RestSecurityOAuth2 oauth2(String key, String description) { 092 RestSecurityOAuth2 auth = new RestSecurityOAuth2(rest); 093 auth.setKey(key); 094 auth.setDescription(description); 095 securityDefinitions.add(auth); 096 return auth; 097 } 098 099 public RestDefinition end() { 100 return rest; 101 } 102 103}