2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.dal.aai.config;
28 import java.util.Properties;
30 import org.eclipse.jetty.util.security.Password;
31 import org.openecomp.sparky.util.ConfigHelper;
32 import org.openecomp.sparky.util.Encryptor;
33 import org.openecomp.sparky.viewandinspect.config.TierSupportUiConstants;
36 * The Class ActiveInventorySslConfig.
38 public class ActiveInventorySslConfig {
40 private Encryptor encryptor;
42 private boolean enableSslDebug;
43 private boolean validateServerHostName;
44 private boolean validateServerCertificateChain;
46 private String keystoreType;
47 private String keystoreFilename;
48 private String keystorePassword;
49 private String truststoreType;
50 private String truststoreFilename;
52 private String basicAuthUsername;
53 private String basicAuthPassword;
56 * Instantiates a new active inventory ssl config.
58 * @param props the props
60 public ActiveInventorySslConfig(Properties props, Encryptor encryptor) {
66 Properties sslProps = ConfigHelper.getConfigWithPrefix("aai.ssl", props);
68 enableSslDebug = Boolean.parseBoolean(sslProps.getProperty("enableDebug", "false"));
69 validateServerHostName =
70 Boolean.parseBoolean(sslProps.getProperty("validateServerHostName", "false"));
71 validateServerCertificateChain =
72 Boolean.parseBoolean(sslProps.getProperty("validateServerCertificateChain", "false"));
75 System.setProperty("javax.net.debug", "ssl");
77 System.setProperty("javax.net.debug", "");
80 this.encryptor = encryptor;
83 keystoreType = sslProps.getProperty("keystore.type", "pkcs12");
86 TierSupportUiConstants.CONFIG_AUTH_LOCATION + sslProps.getProperty("keystore.filename");
87 keystorePassword = encryptor.decryptValue(sslProps.getProperty("keystore.pass", ""));
88 truststoreType = sslProps.getProperty("truststore.type", "jks");
91 TierSupportUiConstants.CONFIG_AUTH_LOCATION + sslProps.getProperty("truststore.filename");
93 basicAuthUsername = sslProps.getProperty("basicAuth.username");
94 basicAuthPassword = decryptPassword(sslProps.getProperty("basicAuth.password"));
98 private String decryptPassword(String encryptedPassword) {
102 if (encryptedPassword == null) {
106 return Password.deobfuscate(encryptedPassword);
108 } catch (Exception exc) {
110 return encryptedPassword;
116 public String getBasicAuthUsername() {
117 return basicAuthUsername;
120 public void setBasicAuthUsername(String basicAuthUsername) {
121 this.basicAuthUsername = basicAuthUsername;
124 public String getBasicAuthPassword() {
125 return basicAuthPassword;
128 public void setBasicAuthPassword(String basicAuthPassword) {
129 this.basicAuthPassword = basicAuthPassword;
133 public Encryptor getEncryptor() {
137 public void setEncryptor(Encryptor encryptor) {
138 this.encryptor = encryptor;
141 public String getKeystoreType() {
145 public void setKeystoreType(String keystoreType) {
146 this.keystoreType = keystoreType;
149 public String getKeystoreFilename() {
150 return keystoreFilename;
153 public void setKeystoreFilename(String keystoreFilename) {
154 this.keystoreFilename = keystoreFilename;
157 public String getKeystorePassword() {
158 return keystorePassword;
161 public void setKeystorePassword(String keystorePassword) {
162 this.keystorePassword = keystorePassword;
165 public String getTruststoreType() {
166 return truststoreType;
169 public void setTruststoreType(String truststoreType) {
170 this.truststoreType = truststoreType;
173 public String getTruststoreFilename() {
174 return truststoreFilename;
177 public void setTruststoreFilename(String truststoreFilename) {
178 this.truststoreFilename = truststoreFilename;
181 public boolean isValidateServerHostName() {
182 return validateServerHostName;
185 public void setValidateServerHostName(boolean validateServerHostName) {
186 this.validateServerHostName = validateServerHostName;
189 public boolean isValidateServerCertificateChain() {
190 return validateServerCertificateChain;
193 public void setValidateServerCertificateChain(boolean validateServerCertificateChain) {
194 this.validateServerCertificateChain = validateServerCertificateChain;
197 public String getBasicAuthenticationCredentials() {
199 String usernameAndPassword = getBasicAuthUsername() + ":"
200 + getBasicAuthPassword();
201 return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes());
205 * @see java.lang.Object#toString()
208 public String toString() {
209 return "ActiveInventorySslConfig [enableSslDebug=" + enableSslDebug
210 + ", validateServerHostName=" + validateServerHostName + ", validateServerCertificateChain="
211 + validateServerCertificateChain + ", keystoreType=" + keystoreType + ", keystoreFilename="
212 + keystoreFilename + ", truststoreType=" + truststoreType + ", truststoreFilename="
213 + truststoreFilename + "]";