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=========================================================
21 package org.openecomp.sdc.common.http.config;
23 import fj.data.Either;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openecomp.sdc.security.SecurityUtil;
27 public class ClientCertificate {
28 private String keyStore;
29 private String keyStorePassword;
31 public ClientCertificate() {
34 public ClientCertificate(ClientCertificate clientCertificate) {
35 setKeyStore(clientCertificate.getKeyStore());
36 setKeyStorePassword(clientCertificate.getKeyStorePassword(), false);
39 public void setKeyStore(String keyStore) {
41 this.keyStore = keyStore;
44 public void setKeyStorePassword(String keyStorePassword) {
45 setKeyStorePassword(keyStorePassword, true);
48 private void setKeyStorePassword(String keyStorePassword, boolean isEncoded) {
49 validate(keyStorePassword);
51 Either<String, String> passkey = SecurityUtil.INSTANCE.decrypt(keyStorePassword);
52 if (passkey.isLeft()) {
53 this.keyStorePassword = passkey.left().value();
55 throw new IllegalArgumentException(passkey.right().value());
58 this.keyStorePassword = keyStorePassword;
62 public String getKeyStore() {
66 public String getKeyStorePassword() {
67 return keyStorePassword;
71 public int hashCode() {
74 result = prime * result + ((keyStore == null) ? 0 : keyStore.hashCode());
75 result = prime * result + ((keyStorePassword == null) ? 0 : keyStorePassword.hashCode());
80 public boolean equals(Object obj) {
87 if (getClass() != obj.getClass()) {
90 ClientCertificate other = (ClientCertificate) obj;
91 if (keyStore == null) {
92 if (other.keyStore != null) {
95 } else if (!keyStore.equals(other.keyStore)) {
98 if (keyStorePassword == null) {
99 return other.keyStorePassword == null;
101 return keyStorePassword.equals(other.keyStorePassword);
106 public String toString() {
107 return "ClientCertificate [keyStore=" + keyStore + "]";
110 private void validate(String str) {
111 if (StringUtils.isEmpty(str)) {
112 throw new IllegalArgumentException("ClientCertificate keystore and/or kestorePassword cannot be empty");