001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2015-2016 ForgeRock AS.
016 */
017package org.opends.admin.ads.util;
018
019import java.security.cert.CertificateException;
020import java.security.cert.X509Certificate;
021
022/**
023 * When a remote client (dsconfig for instance) wants to establish a
024 * remote connection with opends server through a secure connection,
025 * and if the certificate is not known, the SSL handcheck fails and
026 * this exception is thrown. This allows to get the certificate chain
027 * which is unknown.
028 */
029public class OpendsCertificateException extends CertificateException
030{
031  /** The serial version UUID. */
032  private static final long serialVersionUID = 1151044344529478436L;
033
034  /** Private certificate chain. */
035  private final X509Certificate[] chain;
036
037  // ------------------
038  // Constructor
039  // ------------------
040
041  /**
042   * Build a new OpendsCertificationException object.
043   *
044   * @param chain the certificate chain which is unknown and has caused
045   *        the SSL handcheck failure.
046   */
047  public OpendsCertificateException(X509Certificate[] chain)
048  {
049    super();
050    this.chain = chain;
051  }
052
053  /**
054   * Build a new OpendsCertificationException object.
055   *
056   * @param msg the detail message string of this exception.
057   *
058   * @param chain the certificate chain which is unknown and has caused
059   *        the SSL handcheck failure.
060   */
061  public OpendsCertificateException(String msg, X509Certificate[] chain)
062  {
063    super(msg);
064    this.chain = chain;
065  }
066
067  /**
068   * Build a new OpendsCertificationException object.
069   *
070   * @param chain the certificate chain which is unknown and has caused
071   *        the SSL handcheck failure.
072   * @param cause the cause
073   */
074  public OpendsCertificateException(X509Certificate[] chain, CertificateException cause)
075  {
076    super(cause);
077    this.chain = chain;
078  }
079
080  /**
081   * Return the certificate chain which is unknown and has caused
082   * the SSL handcheck failure.
083   *
084   * @return the certificate chain which is unknown and has caused
085   *        the SSL handcheck failure.
086   */
087  public X509Certificate[] getChain()
088  {
089    return chain;
090  }
091}