2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
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=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sparky.dal.aai.config;
25 import java.util.Properties;
27 import org.eclipse.jetty.util.security.Password;
28 import org.onap.aai.sparky.util.ConfigHelper;
29 import org.onap.aai.sparky.util.Encryptor;
30 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
33 * The Class ActiveInventorySslConfig.
35 public class ActiveInventorySslConfig {
37 private Encryptor encryptor;
39 private boolean enableSslDebug;
40 private boolean validateServerHostName;
41 private boolean validateServerCertificateChain;
43 private String keystoreType;
44 private String keystoreFilename;
45 private String keystorePassword;
46 private String truststoreType;
47 private String truststoreFilename;
49 private String basicAuthUsername;
50 private String basicAuthPassword;
53 * Instantiates a new active inventory ssl config.
55 * @param props the props
57 public ActiveInventorySslConfig(Properties props, Encryptor encryptor) {
59 if (props == null || props.isEmpty()) {
63 Properties sslProps = ConfigHelper.getConfigWithPrefix("aai.ssl", props);
65 enableSslDebug = Boolean.parseBoolean(sslProps.getProperty("enableDebug", "false"));
66 validateServerHostName =
67 Boolean.parseBoolean(sslProps.getProperty("validateServerHostName", "false"));
68 validateServerCertificateChain =
69 Boolean.parseBoolean(sslProps.getProperty("validateServerCertificateChain", "false"));
72 System.setProperty("javax.net.debug", "ssl");
74 System.setProperty("javax.net.debug", "");
77 this.encryptor = encryptor;
80 keystoreType = sslProps.getProperty("keystore.type", "pkcs12");
83 TierSupportUiConstants.CONFIG_AUTH_LOCATION + sslProps.getProperty("keystore.filename");
84 keystorePassword = encryptor.decryptValue(sslProps.getProperty("keystore.pass", ""));
85 truststoreType = sslProps.getProperty("truststore.type", "jks");
88 TierSupportUiConstants.CONFIG_AUTH_LOCATION + sslProps.getProperty("truststore.filename");
90 basicAuthUsername = sslProps.getProperty("basicAuth.username");
91 basicAuthPassword = decryptPassword(sslProps.getProperty("basicAuth.password"));
95 private String decryptPassword(String encryptedPassword) {
99 if (encryptedPassword == null) {
103 return Password.deobfuscate(encryptedPassword);
105 } catch (Exception exc) {
107 return encryptedPassword;
113 public String getBasicAuthUsername() {
114 return basicAuthUsername;
117 public void setBasicAuthUsername(String basicAuthUsername) {
118 this.basicAuthUsername = basicAuthUsername;
121 public String getBasicAuthPassword() {
122 return basicAuthPassword;
125 public void setBasicAuthPassword(String basicAuthPassword) {
126 this.basicAuthPassword = basicAuthPassword;
130 public Encryptor getEncryptor() {
134 public void setEncryptor(Encryptor encryptor) {
135 this.encryptor = encryptor;
138 public String getKeystoreType() {
142 public void setKeystoreType(String keystoreType) {
143 this.keystoreType = keystoreType;
146 public String getKeystoreFilename() {
147 return keystoreFilename;
150 public void setKeystoreFilename(String keystoreFilename) {
151 this.keystoreFilename = keystoreFilename;
154 public String getKeystorePassword() {
155 return keystorePassword;
158 public void setKeystorePassword(String keystorePassword) {
159 this.keystorePassword = keystorePassword;
162 public String getTruststoreType() {
163 return truststoreType;
166 public void setTruststoreType(String truststoreType) {
167 this.truststoreType = truststoreType;
170 public String getTruststoreFilename() {
171 return truststoreFilename;
174 public void setTruststoreFilename(String truststoreFilename) {
175 this.truststoreFilename = truststoreFilename;
178 public boolean isValidateServerHostName() {
179 return validateServerHostName;
182 public void setValidateServerHostName(boolean validateServerHostName) {
183 this.validateServerHostName = validateServerHostName;
186 public boolean isValidateServerCertificateChain() {
187 return validateServerCertificateChain;
190 public void setValidateServerCertificateChain(boolean validateServerCertificateChain) {
191 this.validateServerCertificateChain = validateServerCertificateChain;
194 public String getBasicAuthenticationCredentials() {
196 String usernameAndPassword = getBasicAuthUsername() + ":" + getBasicAuthPassword();
197 return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes());
203 * @see java.lang.Object#toString()
206 public String toString() {
207 return "ActiveInventorySslConfig [enableSslDebug=" + enableSslDebug
208 + ", validateServerHostName=" + validateServerHostName + ", validateServerCertificateChain="
209 + validateServerCertificateChain + ", keystoreType=" + keystoreType + ", keystoreFilename="
210 + keystoreFilename + ", truststoreType=" + truststoreType + ", truststoreFilename="
211 + truststoreFilename + "]";