001/* 002 * Copyright 2021-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2021-2024 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2021-2024 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.unboundidds.extensions; 037 038 039 040import java.io.Serializable; 041 042import com.unboundid.asn1.ASN1Element; 043import com.unboundid.ldap.sdk.LDAPException; 044import com.unboundid.ldap.sdk.ResultCode; 045import com.unboundid.util.NotExtensible; 046import com.unboundid.util.NotNull; 047import com.unboundid.util.StaticUtils; 048import com.unboundid.util.ThreadSafety; 049import com.unboundid.util.ThreadSafetyLevel; 050 051import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 052 053 054 055/** 056 * This class acts as a superclass for objects that may be used to indicate how 057 * a certificate key store may be made available to a server instance when 058 * replacing listener or inter-server certificates. 059 * <BR> 060 * <BLOCKQUOTE> 061 * <B>NOTE:</B> This class, and other classes within the 062 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 063 * supported for use against Ping Identity, UnboundID, and 064 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 065 * for proprietary functionality or for external specifications that are not 066 * considered stable or mature enough to be guaranteed to work in an 067 * interoperable way with other types of LDAP servers. 068 * </BLOCKQUOTE> 069 */ 070@NotExtensible() 071@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 072public abstract class ReplaceCertificateKeyStoreContent 073 implements Serializable 074{ 075 /** 076 * The serial version UID for this serializable class. 077 */ 078 private static final long serialVersionUID = 352192622190846396L; 079 080 081 082 /** 083 * Encodes this key store content object to an ASN.1 element suitable for 084 * inclusion in either a replace listener certificate or replace inter-server 085 * certificate request. 086 * 087 * @return The ASN.1 element containing an encoded representation of this 088 * key store content object. 089 */ 090 @NotNull() 091 public abstract ASN1Element encode(); 092 093 094 095 /** 096 * Decodes the provided ASN.1 element as a key store content object. 097 * 098 * @param element An ASN.1 element that contains an encoded representation 099 * of a key store content element. It must not be 100 * {@code null}. 101 * 102 * @return The decoded key store content object. 103 * 104 * @throws LDAPException If the provided element cannot be decoded as a 105 * key store content object. 106 */ 107 @NotNull() 108 public static ReplaceCertificateKeyStoreContent decode( 109 @NotNull final ASN1Element element) 110 throws LDAPException 111 { 112 switch (element.getType()) 113 { 114 case KeyStoreFileReplaceCertificateKeyStoreContent.TYPE_KEY_STORE_CONTENT: 115 return KeyStoreFileReplaceCertificateKeyStoreContent. 116 decodeInternal(element); 117 case KeyStoreDataReplaceCertificateKeyStoreContent.TYPE_KEY_STORE_CONTENT: 118 return KeyStoreDataReplaceCertificateKeyStoreContent. 119 decodeInternal(element); 120 case CertificateDataReplaceCertificateKeyStoreContent. 121 TYPE_KEY_STORE_CONTENT: 122 return CertificateDataReplaceCertificateKeyStoreContent. 123 decodeInternal(element); 124 default: 125 throw new LDAPException(ResultCode.DECODING_ERROR, 126 ERR_KSC_DECODE_UNRECOGNIZED_TYPE.get( 127 StaticUtils.toHex(element.getType()))); 128 } 129 } 130 131 132 133 /** 134 * Retrieves a string representation of this key store content object. 135 * 136 * @return A string representation of this key store content object. 137 */ 138 @Override() 139 @NotNull() 140 public final String toString() 141 { 142 final StringBuilder buffer = new StringBuilder(); 143 toString(buffer); 144 return buffer.toString(); 145 } 146 147 148 149 /** 150 * Appends a string representation of this key store content object to the 151 * provided buffer. 152 * 153 * @param buffer The buffer to which the encoded representation should be 154 * appended. It must not be {@code null}. 155 */ 156 public abstract void toString(@NotNull final StringBuilder buffer); 157}