001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014 ForgeRock AS
026 */
027
028package org.opends.quicksetup;
029import org.forgerock.i18n.LocalizableMessage;
030
031import java.security.cert.X509Certificate;
032
033/**
034 * This exception is used when there is a certificate issue and the user must
035 * be asked to accept it or not.
036 * It will be thrown by the class that is in charge of validating the user data
037 * (the Application class).
038 *
039 */
040public class UserDataCertificateException extends UserDataException
041{
042  private String host;
043  private int port;
044  private X509Certificate[] chain;
045  private String authType;
046  private Type type;
047  /**
048   * The enumeration for the different types of the exception.
049   */
050  public enum Type
051  {
052    /**
053     * The certificate was not trusted.
054     */
055    NOT_TRUSTED,
056    /**
057     * The certificate's subject DN's value and the host name we tried to
058     * connect to do not match.
059     */
060    HOST_NAME_MISMATCH
061  }
062
063  private static final long serialVersionUID = 6404258710409027956L;
064
065  /**
066   * Constructor for UserDataCertificateException.
067   * @param step the step in the wizard where the exception occurred.
068   * @param message describing the error.
069   * @param t the root cause for this exception.
070   * @param host the host we tried to connect to.
071   * @param port the port we tried to connect to.
072   * @param chain the certificate chain.
073   * @param authType the authentication type.
074   * @param type the type of the exception.
075   */
076  public UserDataCertificateException(WizardStep step, LocalizableMessage message,
077      Throwable t, String host, int port, X509Certificate[] chain,
078      String authType, Type type)
079  {
080    super(step, message, t);
081    this.host = host;
082    this.port = port;
083    this.chain = chain;
084    this.authType = authType;
085    this.type = type;
086  }
087
088  /**
089   * Returns the host we tried to connect to when this exception was generated.
090   * @return the host we tried to connect to when this exception was generated.
091   */
092  public String getHost()
093  {
094    return host;
095  }
096
097  /**
098   * Returns the port we tried to connect to when this exception was generated.
099   * @return the port we tried to connect to when this exception was generated.
100   */
101  public int getPort()
102  {
103    return port;
104  }
105
106  /**
107   * Returns the auth type used when this certificate exception occurred.
108   * @return the auth type used when this certificate exception occurred.
109   */
110  public String getAuthType()
111  {
112    return authType;
113  }
114
115  /**
116   * Returns the type of exception.
117   * @return the type of exception.
118   */
119  public Type getType()
120  {
121    return type;
122  }
123
124  /**
125   * Returns the certificate chain received when this exception was generated.
126   * @return the certificate chain received when this exception was generated.
127   */
128  public X509Certificate[] getChain()
129  {
130    return chain;
131  }
132}
133
134