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