3f1673c9379aec66d13fc100a83a5ec83463f8ef
[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 clientId;
33     private String secret;
34     private String id;
35     private String title;
36     private String scope;
37     private OAuthProvider type;
38     private Map<String,String> roleMapping;
39
40     public OAuthProvider getType() {
41         return type;
42     }
43
44     public OAuthProviderConfig(String id, String url, String clientId, String secret, String scope,
45             String title) {
46         this.id = id;
47         this.url = url;
48         this.clientId = clientId;
49         this.secret = secret;
50         this.scope = scope;
51         this.title = title;
52         this.roleMapping = new HashMap<>();
53     }
54
55     @Override
56     public String toString() {
57         return "OAuthProviderConfig [host=" + url + ", clientId=" + clientId + ", secret=" + secret + ", id=" + id
58                 + ", title=" + title + ", scope=" + scope + ", type=" + type + "]";
59     }
60
61     public void setType(OAuthProvider type) {
62         this.type = type;
63     }
64
65     public OAuthProviderConfig() {
66         this(null, null, null, null, null, null);
67     }
68
69     public void setUrl(String url) {
70         this.url = url;
71     }
72
73     public void setClientId(String clientId) {
74         this.clientId = clientId;
75     }
76
77     public void setSecret(String secret) {
78         this.secret = secret;
79     }
80
81     public void setId(String id) {
82         this.id = id;
83     }
84
85     public void setTitle(String title) {
86         this.title = title;
87     }
88
89     public void setScope(String scope) {
90         this.scope = scope;
91     }
92
93     public String getId() {
94         return this.id;
95     }
96
97     public String getUrl() {
98         return this.url;
99     }
100
101     public String getClientId() {
102         return this.clientId;
103     }
104
105     public String getSecret() {
106         return this.secret;
107     }
108
109     public String getTitle() {
110         return this.title;
111     }
112
113     public String getScope() {
114         return this.scope;
115     }
116
117     public Map<String, String> getRoleMapping() {
118         return roleMapping;
119     }
120
121     public void setRoleMapping(Map<String, String> roleMapping) {
122         this.roleMapping = roleMapping;
123     }
124
125     @JsonIgnore
126     public void handleEnvironmentVars() {
127         if (Config.isEnvExpression(id)) {
128             this.id = Config.getProperty(id, null);
129         }
130         if (Config.isEnvExpression(url)) {
131             this.url = Config.getProperty(url, null);
132         }
133         if (Config.isEnvExpression(clientId)) {
134             this.clientId = Config.getProperty(clientId, null);
135         }
136         if (Config.isEnvExpression(secret)) {
137             this.secret = Config.getProperty(secret, null);
138         }
139         if (Config.isEnvExpression(scope)) {
140             this.scope = Config.getProperty(scope, null);
141         }
142         if (Config.isEnvExpression(title)) {
143             this.title = Config.getProperty(title, null);
144         }
145     }
146
147 }