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 2013-2015 ForgeRock AS. 026 */ 027 028package org.opends.admin.ads; 029import org.opends.server.types.OpenDsException; 030 031import javax.naming.NamingException; 032 033import org.opends.admin.ads.util.ApplicationTrustManager; 034 035/** 036 * This class represents the Exception that can occur while reading server 037 * configuration through the TopologyCache class. 038 */ 039public class TopologyCacheException extends OpenDsException { 040 041 private static final long serialVersionUID = 1709535837273360382L; 042 private Type type; 043 private String ldapUrl; 044 private ApplicationTrustManager trustManager; 045 046 /** 047 * Error type. 048 */ 049 public enum Type 050 { 051 /** 052 * Error reading the ADS. 053 */ 054 GENERIC_READING_ADS, 055 /** 056 * Creating connection to a particular server. 057 */ 058 GENERIC_CREATING_CONNECTION, 059 /** 060 * Error reading the configuration of a particular server. 061 */ 062 GENERIC_READING_SERVER, 063 /** 064 * The DN provided in the DirContext of ADS is not of a global 065 * administrator. 066 */ 067 NOT_GLOBAL_ADMINISTRATOR, 068 /** 069 * Not enough permissions to read the server configuration. 070 */ 071 NO_PERMISSIONS, 072 /** 073 * Timeout reading the configuration of a particular server. 074 */ 075 TIMEOUT, 076 /** 077 * Unexpected error. 078 */ 079 BUG 080 } 081 082 /** 083 * Constructor for the exception that must be generated when an 084 * ADSContextException occurs. 085 * @param ace the exception which is the cause of this exception. 086 */ 087 public TopologyCacheException(ADSContextException ace) 088 { 089 super(ace); 090 type = Type.GENERIC_READING_ADS; 091 } 092 093 /** 094 * Constructor for a generic Exception. 095 * @param type the type of this exception. 096 * @param t the cause of this exception. 097 */ 098 public TopologyCacheException(Type type, Throwable t) 099 { 100 super(t); 101 this.type = type; 102 } 103 104 /** 105 * Constructor for the exception that must be generated when a 106 * NamingException occurs. 107 * @param type the type of this exception. 108 * @param ne the NamingException that generated this exception. 109 * @param trustManager the ApplicationTrustManager used when the 110 * NamingException occurred. 111 * @param ldapUrl the LDAP URL of the server we where connected to (or trying 112 * to connect) when the NamingException was generated. 113 */ 114 public TopologyCacheException(Type type, NamingException ne, 115 ApplicationTrustManager trustManager, String ldapUrl) 116 { 117 super(ne); 118 this.type = type; 119 this.ldapUrl = ldapUrl; 120 this.trustManager = trustManager; 121 } 122 123 /** 124 * Returns the type of this exception. 125 * @return the type of this exception. 126 */ 127 public Type getType() 128 { 129 return type; 130 } 131 132 /** 133 * Returns the LDAP URL of the server we where connected to (or trying 134 * to connect) when this exception was generated. 135 * @return the LDAP URL of the server we where connected to (or trying 136 * to connect) when this exception was generated. 137 */ 138 public String getLdapUrl() 139 { 140 return ldapUrl; 141 } 142 143 /** 144 * Returns the host port representation of the server we where connected to 145 * (or trying to connect) when this exception was generated. 146 * @return the host port representation of the server we where connected to 147 * (or trying to connect) when this exception was generated. 148 */ 149 public String getHostPort() 150 { 151 int index = ldapUrl.indexOf("//"); 152 return ldapUrl.substring(index + 2); 153 } 154 155 /** 156 * Returns the ApplicationTrustManager that we were using when this exception 157 * was generated. 158 * @return the ApplicationTrustManager that we were using when this exception 159 * was generated. 160 */ 161 public ApplicationTrustManager getTrustManager() 162 { 163 return trustManager; 164 } 165}