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;
24 import org.apache.commons.lang3.StringUtils;
25 import org.onap.sdc.security.SecurityUtil;
28 public class ClientCertificate {
30 private String keyStore;
31 private String keyStorePassword;
33 public ClientCertificate() {
36 public ClientCertificate(ClientCertificate clientCertificate) {
37 setKeyStore(clientCertificate.getKeyStore());
38 setKeyStorePassword(clientCertificate.getKeyStorePassword(), false);
41 private void setKeyStorePassword(String keyStorePassword, boolean isEncoded) {
42 validate(keyStorePassword);
44 Either<String, String> passkey = SecurityUtil.decrypt(keyStorePassword);
45 if (passkey.isLeft()) {
46 this.keyStorePassword = passkey.left().value();
48 throw new IllegalArgumentException(passkey.right().value());
51 this.keyStorePassword = keyStorePassword;
55 public String getKeyStore() {
59 public void setKeyStore(String keyStore) {
61 this.keyStore = keyStore;
64 public String getKeyStorePassword() {
65 return keyStorePassword;
68 public void setKeyStorePassword(String keyStorePassword) {
69 setKeyStorePassword(keyStorePassword, true);
73 public String toString() {
74 StringBuilder builder = new StringBuilder();
75 builder.append("ClientCertificate [keyStore=");
76 builder.append(keyStore);
78 return builder.toString();
81 private void validate(String str) {
82 if (StringUtils.isEmpty(str)) {
83 throw new IllegalArgumentException("ClientCertificate keystore and/or kestorePassword cannot be empty");