4fb0d006996eb0320e807af41f7fbae2d6a087fb
[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 String openIdConfigUrl;
40
41     private boolean trustAll;
42     private OAuthProvider type;
43     private Map<String, String> roleMapping;
44
45     public OAuthProvider getType() {
46         return type;
47     }
48
49     public OAuthProviderConfig(String id, String url, String internalUrl, String clientId, String secret, String scope,
50             String title, String realmName, String openIdConfigUrl, boolean trustAll) {
51         this.id = id;
52         this.url = url;
53         this.internalUrl = internalUrl;
54         this.clientId = clientId;
55         this.secret = secret;
56         this.scope = scope;
57         this.title = title;
58         this.realmName = realmName;
59         this.trustAll = trustAll;
60         this.openIdConfigUrl = openIdConfigUrl;
61         this.roleMapping = new HashMap<>();
62     }
63
64     @Override
65     public String toString() {
66         return "OAuthProviderConfig [url=" + url + ", clientId=" + clientId + ", secret=" + secret + ", id=" + id
67                 + ", title=" + title + ", scope=" + scope + ", realmName=" + realmName + ", trustAll=" + trustAll
68                 + ", type=" + type + ", roleMapping=" + roleMapping + "]";
69     }
70
71     public void setType(OAuthProvider type) {
72         this.type = type;
73     }
74
75     public OAuthProviderConfig() {
76         this(null, null, null, null, null, null, null, null, null, false);
77     }
78
79     public void setUrl(String url) {
80         this.url = url;
81     }
82
83     public void setClientId(String clientId) {
84         this.clientId = clientId;
85     }
86
87     public void setSecret(String secret) {
88         this.secret = secret;
89     }
90
91     public void setId(String id) {
92         this.id = id;
93     }
94
95     public void setTitle(String title) {
96         this.title = title;
97     }
98
99     public void setScope(String scope) {
100         this.scope = scope;
101     }
102
103     public String getId() {
104         return this.id;
105     }
106
107     public String getUrl() {
108         return this.url;
109     }
110
111     public String getClientId() {
112         return this.clientId;
113     }
114
115     public String getSecret() {
116         return this.secret;
117     }
118
119     public String getTitle() {
120         return this.title;
121     }
122
123     public String getScope() {
124         return this.scope;
125     }
126
127     public String getRealmName() {
128         return realmName;
129     }
130
131     public void setRealmName(String realmName) {
132         this.realmName = realmName;
133     }
134
135     public boolean trustAll() {
136         return trustAll;
137     }
138
139     public void setTrustAll(boolean trustAll) {
140         this.trustAll = trustAll;
141     }
142
143     public Map<String, String> getRoleMapping() {
144         return roleMapping;
145     }
146
147     public void setRoleMapping(Map<String, String> roleMapping) {
148         this.roleMapping = roleMapping;
149     }
150
151     public String getInternalUrl() {
152         return internalUrl;
153     }
154
155     public void setInternalUrl(String internalUrl) {
156         this.internalUrl = internalUrl;
157     }
158
159     public void setOpenIdConfigUrl(String openIdConfigUrl){ this.openIdConfigUrl = openIdConfigUrl;}
160
161     public String getOpenIdConfigUrl() { return this.openIdConfigUrl;}
162     @JsonIgnore
163     public void handleEnvironmentVars() {
164         if (Config.isEnvExpression(this.id)) {
165             this.id = Config.getProperty(this.id, null);
166         }
167         if (Config.isEnvExpression(this.url)) {
168             this.url = Config.getProperty(this.url, null);
169         }
170         if (Config.isEnvExpression(this.internalUrl)) {
171             this.internalUrl = Config.getProperty(this.internalUrl, null);
172         }
173         if (Config.isEnvExpression(this.clientId)) {
174             this.clientId = Config.getProperty(this.clientId, null);
175         }
176         if (Config.isEnvExpression(this.secret)) {
177             this.secret = Config.getProperty(this.secret, null);
178         }
179         if (Config.isEnvExpression(this.scope)) {
180             this.scope = Config.getProperty(this.scope, null);
181         }
182         if (Config.isEnvExpression(this.title)) {
183             this.title = Config.getProperty(this.title, null);
184         }
185         if (Config.isEnvExpression(this.realmName)) {
186             this.realmName = Config.getProperty(this.realmName, null);
187         }
188         if (Config.isEnvExpression(this.openIdConfigUrl)) {
189             this.openIdConfigUrl = Config.getProperty(this.openIdConfigUrl, null);
190         }
191     }
192
193     @JsonIgnore
194     public String getUrlOrInternal() {
195         return this.internalUrl != null && this.internalUrl.length() > 0 ? this.internalUrl : this.url;
196     }
197
198     @JsonIgnore
199     public boolean hasToBeConfigured(){
200         return this.openIdConfigUrl!=null && this.openIdConfigUrl.length()>0;
201     }
202 }