1 /**
2 * Copyright 2017 SmartBear Software
3 * <p>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * <p>
8 * http://www.apache.org/licenses/LICENSE-2.0
9 * <p>
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package io.swagger.v3.oas.annotations.security;
18
19 import java.lang.annotation.Inherited;
20 import java.lang.annotation.Repeatable;
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 import java.lang.annotation.Target;
24
25 import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
26 import static java.lang.annotation.ElementType.TYPE;
27 import static java.lang.annotation.ElementType.METHOD;
28
29 /**
30 * The annotation may be applied at class or method level, or in {@link io.swagger.v3.oas.annotations.Operation#security()} ()} to define security requirements for the
31 * single operation (when applied at method level) or for all operations of a class (when applied at class level).
32 * <p>It can also be used in {@link io.swagger.v3.oas.annotations.OpenAPIDefinition#security()} to define spec level security.</p>
33 *
34 * @see <a target="_new" href="https://github.com/OAI/OpenAPI-Specification/blob/3.0.1/versions/3.0.1.md#securityRequirementObject">Security Requirement (OpenAPI specification)</a>
35 * @see io.swagger.v3.oas.annotations.OpenAPIDefinition
36 * @see io.swagger.v3.oas.annotations.Operation
37 **/
38 @Target({METHOD, TYPE, ANNOTATION_TYPE})
39 @Retention(RetentionPolicy.RUNTIME)
40 @Repeatable(SecurityRequirements.class)
41 @Inherited
42 public @interface SecurityRequirement {
43 /**
44 * This name must correspond to a declared SecurityRequirement.
45 *
46 * @return String name
47 */
48 String name();
49
50 /**
51 * If the security scheme is of type "oauth2" or "openIdConnect", then the value is a list of scope names required for the execution.
52 * For other security scheme types, the array must be empty.
53 *
54 * @return String array of scopes
55 */
56 String[] scopes() default {};
57 }
58