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 2014-2016 ForgeRock AS.
016 */
017
018package org.opends.quicksetup;
019import org.forgerock.i18n.LocalizableMessage;
020
021import java.security.cert.X509Certificate;
022
023/**
024 * This exception is used when there is a certificate issue and the user must
025 * be asked to accept it or not.
026 * It will be thrown by the class that is in charge of validating the user data
027 * (the Application class).
028 */
029public class UserDataCertificateException extends UserDataException
030{
031  private String host;
032  private int port;
033  private X509Certificate[] chain;
034  private String authType;
035  private Type type;
036  /** The enumeration for the different types of the exception. */
037  public enum Type
038  {
039    /** The certificate was not trusted. */
040    NOT_TRUSTED,
041    /** The certificate's subject DN's value and the host name we tried to connect to do not match. */
042    HOST_NAME_MISMATCH
043  }
044
045  private static final long serialVersionUID = 6404258710409027956L;
046
047  /**
048   * Constructor for UserDataCertificateException.
049   * @param step the step in the wizard where the exception occurred.
050   * @param message describing the error.
051   * @param t the root cause for this exception.
052   * @param host the host we tried to connect to.
053   * @param port the port we tried to connect to.
054   * @param chain the certificate chain.
055   * @param authType the authentication type.
056   * @param type the type of the exception.
057   */
058  public UserDataCertificateException(WizardStep step, LocalizableMessage message,
059      Throwable t, String host, int port, X509Certificate[] chain,
060      String authType, Type type)
061  {
062    super(step, message, t);
063    this.host = host;
064    this.port = port;
065    this.chain = chain;
066    this.authType = authType;
067    this.type = type;
068  }
069
070  /**
071   * Returns the host we tried to connect to when this exception was generated.
072   * @return the host we tried to connect to when this exception was generated.
073   */
074  public String getHost()
075  {
076    return host;
077  }
078
079  /**
080   * Returns the port we tried to connect to when this exception was generated.
081   * @return the port we tried to connect to when this exception was generated.
082   */
083  public int getPort()
084  {
085    return port;
086  }
087
088  /**
089   * Returns the auth type used when this certificate exception occurred.
090   * @return the auth type used when this certificate exception occurred.
091   */
092  public String getAuthType()
093  {
094    return authType;
095  }
096
097  /**
098   * Returns the type of exception.
099   * @return the type of exception.
100   */
101  public Type getType()
102  {
103    return type;
104  }
105
106  /**
107   * Returns the certificate chain received when this exception was generated.
108   * @return the certificate chain received when this exception was generated.
109   */
110  public X509Certificate[] getChain()
111  {
112    return chain;
113  }
114}
115
116