11e13e226ceb0c249ef737b6fa1e824464a4fc33
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.oauthprovider.data;
23
24 import com.fasterxml.jackson.annotation.JsonIgnore;
25 import java.util.HashMap;
26 import java.util.Map;
27 import org.onap.ccsdk.features.sdnr.wt.oauthprovider.providers.OAuthProviderFactory.OAuthProvider;
28
29 public class OAuthProviderConfig {
30
31     private String url;
32     private String internalUrl;
33     private String clientId;
34     private String secret;
35     private String id;
36     private String title;
37     private String scope;
38     private String realmName;
39     private boolean trustAll;
40     private OAuthProvider type;
41     private Map<String, String> roleMapping;
42
43     public OAuthProvider getType() {
44         return type;
45     }
46
47     public OAuthProviderConfig(String id, String url, String internalUrl, String clientId, String secret, String scope,
48             String title, String realmName, boolean trustAll) {
49         this.id = id;
50         this.url = url;
51         this.internalUrl = internalUrl;
52         this.clientId = clientId;
53         this.secret = secret;
54         this.scope = scope;
55         this.title = title;
56         this.realmName = realmName;
57         this.trustAll = trustAll;
58         this.roleMapping = new HashMap<>();
59     }
60
61     @Override
62     public String toString() {
63         return "OAuthProviderConfig [url=" + url + ", clientId=" + clientId + ", secret=" + secret + ", id=" + id
64                 + ", title=" + title + ", scope=" + scope + ", realmName=" + realmName + ", trustAll=" + trustAll
65                 + ", type=" + type + ", roleMapping=" + roleMapping + "]";
66     }
67
68     public void setType(OAuthProvider type) {
69         this.type = type;
70     }
71
72     public OAuthProviderConfig() {
73         this(null, null, null, null, null, null, null, null, false);
74     }
75
76     public void setUrl(String url) {
77         this.url = url;
78     }
79
80     public void setClientId(String clientId) {
81         this.clientId = clientId;
82     }
83
84     public void setSecret(String secret) {
85         this.secret = secret;
86     }
87
88     public void setId(String id) {
89         this.id = id;
90     }
91
92     public void setTitle(String title) {
93         this.title = title;
94     }
95
96     public void setScope(String scope) {
97         this.scope = scope;
98     }
99
100     public String getId() {
101         return this.id;
102     }
103
104     public String getUrl() {
105         return this.url;
106     }
107
108     public String getClientId() {
109         return this.clientId;
110     }
111
112     public String getSecret() {
113         return this.secret;
114     }
115
116     public String getTitle() {
117         return this.title;
118     }
119
120     public String getScope() {
121         return this.scope;
122     }
123
124     public String getRealmName() {
125         return realmName;
126     }
127
128     public void setRealmName(String realmName) {
129         this.realmName = realmName;
130     }
131
132     public boolean trustAll() {
133         return trustAll;
134     }
135
136     public void setTrustAll(boolean trustAll) {
137         this.trustAll = trustAll;
138     }
139
140     public Map<String, String> getRoleMapping() {
141         return roleMapping;
142     }
143
144     public void setRoleMapping(Map<String, String> roleMapping) {
145         this.roleMapping = roleMapping;
146     }
147
148     public String getInternalUrl() {
149         return internalUrl;
150     }
151
152     public void setInternalUrl(String internalUrl) {
153         this.internalUrl = internalUrl;
154     }
155
156     @JsonIgnore
157     public void handleEnvironmentVars() {
158         if (Config.isEnvExpression(this.id)) {
159             this.id = Config.getProperty(this.id, null);
160         }
161         if (Config.isEnvExpression(this.url)) {
162             this.url = Config.getProperty(this.url, null);
163         }
164         if (Config.isEnvExpression(this.internalUrl)) {
165             this.internalUrl = Config.getProperty(this.internalUrl, null);
166         }
167         if (Config.isEnvExpression(this.clientId)) {
168             this.clientId = Config.getProperty(this.clientId, null);
169         }
170         if (Config.isEnvExpression(this.secret)) {
171             this.secret = Config.getProperty(this.secret, null);
172         }
173         if (Config.isEnvExpression(this.scope)) {
174             this.scope = Config.getProperty(this.scope, null);
175         }
176         if (Config.isEnvExpression(this.title)) {
177             this.title = Config.getProperty(this.title, null);
178         }
179         if (Config.isEnvExpression(this.realmName)) {
180             this.realmName = Config.getProperty(this.realmName, null);
181         }
182     }
183
184     @JsonIgnore
185     public String getUrlOrInternal() {
186         return this.internalUrl != null && this.internalUrl.length() > 0 ? this.internalUrl : this.url;
187     }
188
189 }