org.apache.juneau.dto.swagger.SecurityScheme Maven / Gradle / Ivy
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
// * with the License. You may obtain a copy of the License at *
// * *
// * http://www.apache.org/licenses/LICENSE-2.0 *
// * *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
// * specific language governing permissions and limitations under the License. *
// ***************************************************************************************************************************
package org.apache.juneau.dto.swagger;
import static org.apache.juneau.internal.ArrayUtils.*;
import java.util.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
/**
* Allows the definition of a security scheme that can be used by the operations.
*
*
* Supported schemes are basic authentication, an API key (either as a header or as a query parameter) and OAuth2's
* common flows (implicit, password, application and access code).
*
*
Example:
*
* // Basic authentication sample
* {
* "type" : "basic"
* }
*
* // API key sample
* {
* "type" : "apiKey" ,
* "name" : "api_key" ,
* "in" : "header"
* }
*
* // Implicit OAuth2 sample
* {
* "type" : "oauth2" ,
* "authorizationUrl" : "http://swagger.io/api/oauth/dialog" ,
* "flow" : "implicit" ,
* "scopes" : {
* "write:pets" : "modify pets in your account" ,
* "read:pets" : "read your pets"
* }
* }
*
*
* Additional Information
*
* -
* Juneau Data Transfer Objects
* (org.apache.juneau.dto)
*
* -
* Swagger
*
*
* -
* org.apache.juneau.dto.swagger
*
*
*/
@Bean(properties="type,description,name,in,flow,authorizationUrl,tokenUrl,scopes")
public class SecurityScheme extends SwaggerElement {
private static final String[] VALID_TYPES = {"basic", "apiKey", "oauth2"};
private String type;
private String description;
private String name;
private String in;
private String flow;
private String authorizationUrl;
private String tokenUrl;
private Map scopes;
@Override /* SwaggerElement */
protected SecurityScheme strict() {
super.strict();
return this;
}
/**
* Bean property getter: type .
*
*
* Required. The type of the security scheme.
*
*
* Valid values are "basic" , "apiKey" or "oauth2" .
*
* @return The value of the type property on this bean, or null if it is not set.
*/
public String getType() {
return type;
}
/**
* Bean property setter: type .
*
*
* Required. The type of the security scheme.
*
*
* Valid values are "basic" , "apiKey" or "oauth2" .
*
* @param type The new value for the type property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme setType(String type) {
if (isStrict() && ! contains(type, VALID_TYPES))
throw new FormattedRuntimeException(
"Invalid value passed in to setType(String). Value=''{0}'', valid values={1}",
type, VALID_TYPES
);
this.type = type;
return this;
}
/**
* Synonym for {@link #setType(String)}.
*
* @param type The new value for the type property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme type(String type) {
return setType(type);
}
/**
* Bean property getter: description .
*
*
* A short description for security scheme.
*
* @return
* The value of the description property on this bean, or null if it is not set.
*/
public String getDescription() {
return description;
}
/**
* Bean property setter: description .
*
*
* A short description for security scheme.
*
* @param description The new value for the description property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme setDescription(String description) {
this.description = description;
return this;
}
/**
* Synonym for {@link #setDescription(String)}.
*
* @param description The new value for the description property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme description(String description) {
return setDescription(description);
}
/**
* Bean property getter: name .
*
*
* The name of the header or query parameter to be used.
*
* @return The value of the name property on this bean, or null if it is not set.
*/
public String getName() {
return name;
}
/**
* Bean property setter: name .
*
*
* The name of the header or query parameter to be used.
*
* @param name The new value for the name property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme setName(String name) {
this.name = name;
return this;
}
/**
* Synonym for {@link #setName(String)}.
*
* @param name The new value for the name property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme name(String name) {
return setName(name);
}
/**
* Bean property getter: in .
*
*
* The location of the API key. Valid values are "query" or "header" .
*
* @return The value of the in property on this bean, or null if it is not set.
*/
public String getIn() {
return in;
}
/**
* Bean property setter: in .
*
*
* The location of the API key. Valid values are "query" or "header" .
*
* @param in The new value for the in property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme setIn(String in) {
this.in = in;
return this;
}
/**
* Synonym for {@link #setIn(String)}.
*
* @param in The new value for the in property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme in(String in) {
return setIn(in);
}
/**
* Bean property getter: flow .
*
*
* The flow used by the OAuth2 security scheme.
*
*
* Valid values are "implicit" , "password" , "application" or "accessCode" .
*
* @return The value of the flow property on this bean, or null if it is not set.
*/
public String getFlow() {
return flow;
}
/**
* Bean property setter: flow .
*
*
* The flow used by the OAuth2 security scheme.
*
*
* Valid values are "implicit" , "password" , "application" or "accessCode" .
*
* @param flow The new value for the flow property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme setFlow(String flow) {
this.flow = flow;
return this;
}
/**
* Synonym for {@link #setFlow(String)}.
*
* @param flow The new value for the flow property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme flow(String flow) {
return setFlow(flow);
}
/**
* Bean property getter: authorizationUrl .
*
*
* The authorization URL to be used for this flow.
*
*
* This SHOULD be in the form of a URL.
*
* @return
* The value of the authorizationUrl property on this bean, or null if it
* is not set.
*/
public String getAuthorizationUrl() {
return authorizationUrl;
}
/**
* Bean property setter: authorizationUrl .
*
*
* The authorization URL to be used for this flow.
*
*
* This SHOULD be in the form of a URL.
*
* @param authorizationUrl The new value for the authorizationUrl property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme setAuthorizationUrl(String authorizationUrl) {
this.authorizationUrl = authorizationUrl;
return this;
}
/**
* Synonym for {@link #setAuthorizationUrl(String)}.
*
* @param authorizationUrl The new value for the authorizationUrl property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme authorizationUrl(String authorizationUrl) {
return setAuthorizationUrl(authorizationUrl);
}
/**
* Bean property getter: tokenUrl .
*
*
* The token URL to be used for this flow.
*
*
* This SHOULD be in the form of a URL.
*
* @return The value of the tokenUrl property on this bean, or null if it is not set.
*/
public String getTokenUrl() {
return tokenUrl;
}
/**
* Bean property setter: tokenUrl .
*
*
* The token URL to be used for this flow.
*
*
* This SHOULD be in the form of a URL.
*
* @param tokenUrl The new value for the tokenUrl property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme setTokenUrl(String tokenUrl) {
this.tokenUrl = tokenUrl;
return this;
}
/**
* Synonym for {@link #setTokenUrl(String)}.
*
* @param tokenUrl The new value for the tokenUrl property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme tokenUrl(String tokenUrl) {
return setTokenUrl(tokenUrl);
}
/**
* Bean property getter: scopes .
*
*
* The available scopes for the OAuth2 security scheme.
*
* @return The value of the scopes property on this bean, or null if it is not set.
*/
public Map getScopes() {
return scopes;
}
/**
* Bean property setter: scopes .
*
*
* The available scopes for the OAuth2 security scheme.
*
* @param scopes The new value for the scopes property on this bean.
* @return This object (for method chaining).
*/
public SecurityScheme setScopes(Map scopes) {
this.scopes = scopes;
return this;
}
/**
* Bean property adder: scopes .
*
*
* The available scopes for the OAuth2 security scheme.
*
* @param name The name of the scope.
* @param description A short description of the scope.
* @return This object (for method chaining).
*/
public SecurityScheme addScope(String name, String description) {
if (scopes == null)
scopes = new TreeMap();
scopes.put(name, description);
return this;
}
/**
* Synonym for {@link #addScope(String,String)}.
*
* @param name The name of the scope.
* @param description A short description of the scope.
* @return This object (for method chaining).
*/
public SecurityScheme scope(String name, String description) {
return addScope(name, description);
}
}