001/*
002 * Copyright 2021-2022 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2021-2022 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-2022 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 * the server should handle updating trust information for a new listener
058 * certificate chain.
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 ReplaceCertificateTrustBehavior
073       implements Serializable
074{
075  /**
076   * The serial version UID for this serializable class.
077   */
078  private static final long serialVersionUID = 2978084206955241218L;
079
080
081
082  /**
083   * Encodes this trust behavior object to an ASN.1 element suitable for
084   * inclusion in a replace listener certificate request.
085   *
086   * @return  The ASN.1 element containing an encoded representation of this
087   *          trust behavior object.
088   */
089  @NotNull()
090  public abstract ASN1Element encode();
091
092
093
094  /**
095   * Decodes the provided ASN.1 element as a trust behavior object.
096   *
097   * @param  element  An ASN.1 element that contains an encoded representation
098   *                  of a trust behavior element.  It must not be {@code null}.
099   *
100   * @return  The decoded trust behavior object.
101   *
102   * @throws  LDAPException  If the provided element cannot be decoded as a
103   *                         trust behavior object.
104   */
105  @NotNull()
106  public static ReplaceCertificateTrustBehavior decode(
107              @NotNull final ASN1Element element)
108         throws LDAPException
109  {
110    switch (element.getType())
111    {
112      case TrustManagerProviderReplaceCertificateTrustBehavior.
113           TYPE_TRUST_BEHAVIOR:
114        return new TrustManagerProviderReplaceCertificateTrustBehavior(
115             element.decodeAsOctetString().stringValue());
116      case JVMDefaultReplaceCertificateTrustBehavior.TYPE_TRUST_BEHAVIOR:
117        return JVMDefaultReplaceCertificateTrustBehavior.getInstance();
118      default:
119        throw new LDAPException(ResultCode.DECODING_ERROR,
120             ERR_TB_DECODE_UNRECOGNIZED_TYPE.get(
121                  StaticUtils.toHex(element.getType())));
122    }
123  }
124
125
126
127  /**
128   * Retrieves a string representation of this trust behavior object.
129   *
130   * @return  A string representation of this trust behavior object.
131   */
132  @Override()
133  @NotNull()
134  public final String toString()
135  {
136    final StringBuilder buffer = new StringBuilder();
137    toString(buffer);
138    return buffer.toString();
139  }
140
141
142
143  /**
144   * Appends a string representation of this trust behavior object to the
145   * provided buffer.
146   *
147   * @param  buffer  The buffer to which the encoded representation should be
148   *                 appended.  It must not be {@code null}.
149   */
150  public abstract void toString(@NotNull final StringBuilder buffer);
151}