2  * ============LICENSE_START=======================================================
 
   3  * ONAP : ccsdk features
 
   4  * ================================================================================
 
   5  * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
 
   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
 
  12  *     http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  22 package org.onap.ccsdk.features.sdnr.wt.oauthprovider.data;
 
  24 import com.fasterxml.jackson.annotation.JsonIgnore;
 
  25 import java.util.HashMap;
 
  27 import org.onap.ccsdk.features.sdnr.wt.oauthprovider.providers.OAuthProviderFactory.OAuthProvider;
 
  29 public class OAuthProviderConfig {
 
  32     private String internalUrl;
 
  33     private String clientId;
 
  34     private String secret;
 
  38     private String realmName;
 
  39     private String openIdConfigUrl;
 
  41     private boolean trustAll;
 
  42     private OAuthProvider type;
 
  43     private Map<String, String> roleMapping;
 
  45     public OAuthProvider getType() {
 
  49     public OAuthProviderConfig(String id, String url, String internalUrl, String clientId, String secret, String scope,
 
  50             String title, String realmName, String openIdConfigUrl, boolean trustAll) {
 
  53         this.internalUrl = internalUrl;
 
  54         this.clientId = clientId;
 
  58         this.realmName = realmName;
 
  59         this.trustAll = trustAll;
 
  60         this.openIdConfigUrl = openIdConfigUrl;
 
  61         this.roleMapping = new HashMap<>();
 
  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 + "]";
 
  71     public void setType(OAuthProvider type) {
 
  75     public OAuthProviderConfig() {
 
  76         this(null, null, null, null, null, null, null, null, null, false);
 
  79     public void setUrl(String url) {
 
  83     public void setClientId(String clientId) {
 
  84         this.clientId = clientId;
 
  87     public void setSecret(String secret) {
 
  91     public void setId(String id) {
 
  95     public void setTitle(String title) {
 
  99     public void setScope(String scope) {
 
 103     public String getId() {
 
 107     public String getUrl() {
 
 111     public String getClientId() {
 
 112         return this.clientId;
 
 115     public String getSecret() {
 
 119     public String getTitle() {
 
 123     public String getScope() {
 
 127     public String getRealmName() {
 
 131     public void setRealmName(String realmName) {
 
 132         this.realmName = realmName;
 
 135     public boolean trustAll() {
 
 139     public void setTrustAll(boolean trustAll) {
 
 140         this.trustAll = trustAll;
 
 143     public Map<String, String> getRoleMapping() {
 
 147     public void setRoleMapping(Map<String, String> roleMapping) {
 
 148         this.roleMapping = roleMapping;
 
 151     public String getInternalUrl() {
 
 155     public void setInternalUrl(String internalUrl) {
 
 156         this.internalUrl = internalUrl;
 
 159     public void setOpenIdConfigUrl(String openIdConfigUrl){ this.openIdConfigUrl = openIdConfigUrl;}
 
 161     public String getOpenIdConfigUrl() { return this.openIdConfigUrl;}
 
 163     public void handleEnvironmentVars() {
 
 164         if (Config.isEnvExpression(this.id)) {
 
 165             this.id = Config.getProperty(this.id, null);
 
 167         if (Config.isEnvExpression(this.url)) {
 
 168             this.url = Config.getProperty(this.url, null);
 
 170         if (Config.isEnvExpression(this.internalUrl)) {
 
 171             this.internalUrl = Config.getProperty(this.internalUrl, null);
 
 173         if (Config.isEnvExpression(this.clientId)) {
 
 174             this.clientId = Config.getProperty(this.clientId, null);
 
 176         if (Config.isEnvExpression(this.secret)) {
 
 177             this.secret = Config.getProperty(this.secret, null);
 
 179         if (Config.isEnvExpression(this.scope)) {
 
 180             this.scope = Config.getProperty(this.scope, null);
 
 182         if (Config.isEnvExpression(this.title)) {
 
 183             this.title = Config.getProperty(this.title, null);
 
 185         if (Config.isEnvExpression(this.realmName)) {
 
 186             this.realmName = Config.getProperty(this.realmName, null);
 
 188         if (Config.isEnvExpression(this.openIdConfigUrl)) {
 
 189             this.openIdConfigUrl = Config.getProperty(this.openIdConfigUrl, null);
 
 194     public String getUrlOrInternal() {
 
 195         return this.internalUrl != null && this.internalUrl.length() > 0 ? this.internalUrl : this.url;
 
 199     public boolean hasToBeConfigured(){
 
 200         return this.openIdConfigUrl!=null && this.openIdConfigUrl.length()>0;