2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.common.http.config;
22 import fj.data.Either;
23 import lombok.EqualsAndHashCode;
27 import org.apache.commons.lang3.StringUtils;
28 import org.onap.sdc.security.SecurityUtil;
33 public class ClientCertificate {
35 private String keyStore;
36 private String keyStorePassword;
37 private String trustStore;
38 private String trustStorePassword;
40 public ClientCertificate() {
43 public ClientCertificate(ClientCertificate clientCertificate) {
44 setKeyStore(clientCertificate.getKeyStore());
45 setKeyStorePassword(clientCertificate.getKeyStorePassword(), false);
46 setTrustStore(clientCertificate.getTrustStore());
47 setTrustStorePassword(clientCertificate.getTrustStorePassword());
50 public void setKeyStorePassword(String keyStorePassword, boolean isEncoded) {
51 validate(keyStorePassword);
53 Either<String, String> passkey = SecurityUtil.decrypt(keyStorePassword);
54 if (passkey.isLeft()) {
55 this.keyStorePassword = passkey.left().value();
57 throw new IllegalArgumentException(passkey.right().value());
60 this.keyStorePassword = keyStorePassword;
64 public void setKeyStore(String keyStore) {
66 this.keyStore = keyStore;
69 public void setKeyStorePassword(String keyStorePassword) {
70 setKeyStorePassword(keyStorePassword, true);
73 private void validate(String str) {
74 if (StringUtils.isEmpty(str)) {
75 throw new IllegalArgumentException("ClientCertificate keystore and/or kestorePassword cannot be empty");