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 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 * 029 */ 030public class UserDataCertificateException extends UserDataException 031{ 032 private String host; 033 private int port; 034 private X509Certificate[] chain; 035 private String authType; 036 private Type type; 037 /** 038 * The enumeration for the different types of the exception. 039 */ 040 public enum Type 041 { 042 /** 043 * The certificate was not trusted. 044 */ 045 NOT_TRUSTED, 046 /** 047 * The certificate's subject DN's value and the host name we tried to 048 * connect to do not match. 049 */ 050 HOST_NAME_MISMATCH 051 } 052 053 private static final long serialVersionUID = 6404258710409027956L; 054 055 /** 056 * Constructor for UserDataCertificateException. 057 * @param step the step in the wizard where the exception occurred. 058 * @param message describing the error. 059 * @param t the root cause for this exception. 060 * @param host the host we tried to connect to. 061 * @param port the port we tried to connect to. 062 * @param chain the certificate chain. 063 * @param authType the authentication type. 064 * @param type the type of the exception. 065 */ 066 public UserDataCertificateException(WizardStep step, LocalizableMessage message, 067 Throwable t, String host, int port, X509Certificate[] chain, 068 String authType, Type type) 069 { 070 super(step, message, t); 071 this.host = host; 072 this.port = port; 073 this.chain = chain; 074 this.authType = authType; 075 this.type = type; 076 } 077 078 /** 079 * Returns the host we tried to connect to when this exception was generated. 080 * @return the host we tried to connect to when this exception was generated. 081 */ 082 public String getHost() 083 { 084 return host; 085 } 086 087 /** 088 * Returns the port we tried to connect to when this exception was generated. 089 * @return the port we tried to connect to when this exception was generated. 090 */ 091 public int getPort() 092 { 093 return port; 094 } 095 096 /** 097 * Returns the auth type used when this certificate exception occurred. 098 * @return the auth type used when this certificate exception occurred. 099 */ 100 public String getAuthType() 101 { 102 return authType; 103 } 104 105 /** 106 * Returns the type of exception. 107 * @return the type of exception. 108 */ 109 public Type getType() 110 { 111 return type; 112 } 113 114 /** 115 * Returns the certificate chain received when this exception was generated. 116 * @return the certificate chain received when this exception was generated. 117 */ 118 public X509Certificate[] getChain() 119 { 120 return chain; 121 } 122} 123 124