1 /*
2  *
3  *  * Copyright 2019-2020 the original author or authors.
4  *  *
5  *  * Licensed under the Apache License, Version 2.0 (the "License");
6  *  * you may not use this file except in compliance with the License.
7  *  * You may obtain a copy of the License at
8  *  *
9  *  *      https://www.apache.org/licenses/LICENSE-2.0
10  *  *
11  *  * Unless required by applicable law or agreed to in writing, software
12  *  * distributed under the License is distributed on an "AS IS" BASIS,
13  *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  * See the License for the specific language governing permissions and
15  *  * limitations under the License.
16  *
17  */

18
19 package org.springdoc.core;
20
21
22 import java.util.List;
23 import java.util.Map;
24 import java.util.TreeMap;
25
26 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
27 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
28 import org.springframework.boot.context.properties.ConfigurationProperties;
29 import org.springframework.context.annotation.Configuration;
30
31 import static org.springdoc.core.Constants.SPRINGDOC_SWAGGER_UI_ENABLED;
32
33 /**
34  * Please refer to the swagger
35  * <a href="https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/oauth2.md">configuration.md</a>
36  * to get the idea what each parameter does.
37  */

38 @Configuration
39 @ConfigurationProperties(prefix = "springdoc.swagger-ui.oauth")
40 @ConditionalOnProperty(name = SPRINGDOC_SWAGGER_UI_ENABLED, matchIfMissing = true)
41 @ConditionalOnBean(SpringDocConfiguration.class)
42 public class SwaggerUiOAuthProperties {
43
44     private String clientId;
45
46     private String clientSecret;
47
48     private String realm;
49
50     private String appName;
51
52     private String scopeSeparator;
53
54     private List<String> additionalQueryStringParams;
55
56     private String useBasicAuthenticationWithAccessCodeGrant;
57
58     private Boolean usePkceWithAuthorizationCodeGrant;
59
60     public Map<String, Object> getConfigParameters() {
61         final Map<String, Object> params = new TreeMap<>();
62         SpringDocPropertiesUtils.put("clientId", clientId, params);
63         SpringDocPropertiesUtils.put("clientSecret", clientSecret, params);
64         SpringDocPropertiesUtils.put("realm", realm, params);
65         SpringDocPropertiesUtils.put("scopeSeparator", scopeSeparator, params);
66         SpringDocPropertiesUtils.put("appName", appName, params);
67         SpringDocPropertiesUtils.put("useBasicAuthenticationWithAccessCodeGrant", useBasicAuthenticationWithAccessCodeGrant, params);
68         SpringDocPropertiesUtils.put("usePkceWithAuthorizationCodeGrant", usePkceWithAuthorizationCodeGrant, params);
69         SpringDocPropertiesUtils.put("additionalQueryStringParams", additionalQueryStringParams, params);
70         return params;
71     }
72
73     public String getClientId() {
74         return clientId;
75     }
76
77     public void setClientId(String clientId) {
78         this.clientId = clientId;
79     }
80
81     public String getClientSecret() {
82         return clientSecret;
83     }
84
85     public void setClientSecret(String clientSecret) {
86         this.clientSecret = clientSecret;
87     }
88
89     public String getRealm() {
90         return realm;
91     }
92
93     public void setRealm(String realm) {
94         this.realm = realm;
95     }
96
97     public String getAppName() {
98         return appName;
99     }
100
101     public void setAppName(String appName) {
102         this.appName = appName;
103     }
104
105     public String getScopeSeparator() {
106         return scopeSeparator;
107     }
108
109     public void setScopeSeparator(String scopeSeparator) {
110         this.scopeSeparator = scopeSeparator;
111     }
112
113     public List<String> getAdditionalQueryStringParams() {
114         return additionalQueryStringParams;
115     }
116
117     public void setAdditionalQueryStringParams(List<String> additionalQueryStringParams) {
118         this.additionalQueryStringParams = additionalQueryStringParams;
119     }
120
121     public String getUseBasicAuthenticationWithAccessCodeGrant() {
122         return useBasicAuthenticationWithAccessCodeGrant;
123     }
124
125     public void setUseBasicAuthenticationWithAccessCodeGrant(String useBasicAuthenticationWithAccessCodeGrant) {
126         this.useBasicAuthenticationWithAccessCodeGrant = useBasicAuthenticationWithAccessCodeGrant;
127     }
128
129     public Boolean getUsePkceWithAuthorizationCodeGrant() {
130         return usePkceWithAuthorizationCodeGrant;
131     }
132
133     public void setUsePkceWithAuthorizationCodeGrant(Boolean usePkceWithAuthorizationCodeGrant) {
134         this.usePkceWithAuthorizationCodeGrant = usePkceWithAuthorizationCodeGrant;
135     }
136 }