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();
56 throw new IllegalArgumentException(passkey.right().value());
60 this.keyStorePassword = keyStorePassword;
64 public String getKeyStore() {
68 public String getKeyStorePassword() {
69 return keyStorePassword;
73 public int hashCode() {
76 result = prime * result + ((keyStore == null) ? 0 : keyStore.hashCode());
77 result = prime * result + ((keyStorePassword == null) ? 0 : keyStorePassword.hashCode());
82 public boolean equals(Object obj) {
87 if (getClass() != obj.getClass())
89 ClientCertificate other = (ClientCertificate) obj;
90 if (keyStore == null) {
91 if (other.keyStore != null)
94 else if (!keyStore.equals(other.keyStore))
96 if (keyStorePassword == null) {
97 if (other.keyStorePassword != null)
100 else if (!keyStorePassword.equals(other.keyStorePassword))
106 public String toString() {
107 StringBuilder builder = new StringBuilder();
108 builder.append("ClientCertificate [keyStore=");
109 builder.append(keyStore);
111 return builder.toString();
114 private void validate(String str) {
115 if(StringUtils.isEmpty(str)) {
116 throw new IllegalArgumentException("ClientCertificate keystore and/or kestorePassword cannot be empty");