Source for java.security.cert.CertPathValidatorException

   1: /* CertPathValidatorException.java -- wraps an exception during validation
   2:    of a CertPath
   3:    Copyright (C) 2002, 2005  Free Software Foundation, Inc.
   4: 
   5: This file is part of GNU Classpath.
   6: 
   7: GNU Classpath is free software; you can redistribute it and/or modify
   8: it under the terms of the GNU General Public License as published by
   9: the Free Software Foundation; either version 2, or (at your option)
  10: any later version.
  11: 
  12: GNU Classpath is distributed in the hope that it will be useful, but
  13: WITHOUT ANY WARRANTY; without even the implied warranty of
  14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15: General Public License for more details.
  16: 
  17: You should have received a copy of the GNU General Public License
  18: along with GNU Classpath; see the file COPYING.  If not, write to the
  19: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20: 02110-1301 USA.
  21: 
  22: Linking this library statically or dynamically with other modules is
  23: making a combined work based on this library.  Thus, the terms and
  24: conditions of the GNU General Public License cover the whole
  25: combination.
  26: 
  27: As a special exception, the copyright holders of this library give you
  28: permission to link this library with independent modules to produce an
  29: executable, regardless of the license terms of these independent
  30: modules, and to copy and distribute the resulting executable under
  31: terms of your choice, provided that you also meet, for each linked
  32: independent module, the terms and conditions of the license of that
  33: module.  An independent module is a module which is not derived from
  34: or based on this library.  If you modify this library, you may extend
  35: this exception to your version of the library, but you are not
  36: obligated to do so.  If you do not wish to do so, delete this
  37: exception statement from your version. */
  38: 
  39: 
  40: package java.security.cert;
  41: 
  42: import java.io.PrintStream;
  43: import java.io.PrintWriter;
  44: import java.security.GeneralSecurityException;
  45: 
  46: /**
  47:  * Indicates a problem while validating a certification path. In addition,
  48:  * it can store the path an index in that path that caused the problem. This
  49:  * class is not thread-safe.
  50:  *
  51:  * @author Eric Blake (ebb9@email.byu.edu)
  52:  * @see CertPathValidator
  53:  * @since 1.4
  54:  * @status updated to 1.4
  55: */
  56: public class CertPathValidatorException extends GeneralSecurityException
  57: {
  58:   /**
  59:    * Compatible with JDK 1.4+.
  60:    */
  61:   private static final long serialVersionUID = -3083180014971893139L;
  62: 
  63:   /**
  64:    * The index of the certificate path that failed, or -1.
  65:    *
  66:    * @serial the failed index
  67:    */
  68:   private final int index;
  69: 
  70:   /**
  71:    * The <code>CertPath</code> that failed.
  72:    *
  73:    * @serial the object being validated at time of failure
  74:    */
  75:   private final CertPath certPath;
  76: 
  77:   /**
  78:    * Create an exception without a message. The cause may be initialized. The
  79:    * index is set to -1 and the failed CertPath object to null.
  80:    */
  81:   public CertPathValidatorException()
  82:   {
  83:     this((String) null);
  84:   }
  85: 
  86:   /**
  87:    * Create an exception with a message. The cause may be initialized. The
  88:    * index is set to -1 and the failed CertPath object to null.
  89:    *
  90:    * @param msg a message to display with exception
  91:    */
  92:   public CertPathValidatorException(String msg)
  93:   {
  94:     super(msg);
  95:     index = -1;
  96:     certPath = null;
  97:   }
  98: 
  99:   /**
 100:    * Create an exception with a cause. The message will be
 101:    * <code>cause == null ? null : cause.toString()</code>. The index is set
 102:    * to -1 and the failed CertPath object to null.
 103:    *
 104:    * @param cause the cause
 105:    */
 106:   public CertPathValidatorException(Throwable cause)
 107:   {
 108:     this(cause == null ? null : cause.toString(), cause, null, -1);
 109:   }
 110: 
 111:   /**
 112:    * Create an exception with a cause and a message. The index is set to -1
 113:    * and the failed CertPath object to null.
 114:    *
 115:    * @param msg the message
 116:    * @param cause the cause
 117:    */
 118:   public CertPathValidatorException(String msg, Throwable cause)
 119:   {
 120:     this(msg, cause, null, -1);
 121:   }
 122: 
 123:   /**
 124:    * Create an exception with a cause, message, failed object, and index of
 125:    * failure in that CertPath.
 126:    *
 127:    * @param msg the message
 128:    * @param cause the cause
 129:    * @param certPath the path that was being validated, or null
 130:    * @param index the index of the path, or -1
 131:    * @throws IndexOutOfBoundsException if index is &lt; -1 or
 132:    *         &gt; certPath.getCertificates().size()
 133:    * @throws IllegalArgumentException if certPath is null but index != -1
 134:    */
 135:   public CertPathValidatorException(String msg, Throwable cause,
 136:                                     CertPath certPath, int index)
 137:   {
 138:     super(msg);
 139:     initCause(cause);
 140:     if (index < -1 || (certPath != null
 141:                        && index >= certPath.getCertificates().size()))
 142:       throw new IndexOutOfBoundsException();
 143:     if ((certPath == null) != (index == -1))
 144:       throw new IllegalArgumentException();
 145:     this.certPath = certPath;
 146:     this.index = index;
 147:   }
 148: 
 149:   /**
 150:    * Get the detail message.
 151:    *
 152:    * @return the detail message
 153:    */
 154:   public String getMessage()
 155:   {
 156:     return super.getMessage();
 157:   }
 158: 
 159:   /**
 160:    * Get the certificate path that had the failure, or null.
 161:    *
 162:    * @return the culprit path
 163:    */
 164:   public CertPath getCertPath()
 165:   {
 166:     return certPath;
 167:   }
 168: 
 169:   /**
 170:    * Get the index that failed, or -1.
 171:    *
 172:    * @return the colprit index
 173:    */
 174:   public int getIndex()
 175:   {
 176:     return index;
 177:   }
 178: 
 179:   /**
 180:    * Get the cause, null if unknown.
 181:    *
 182:    * @return the cause
 183:    */
 184:   public Throwable getCause()
 185:   {
 186:     return super.getCause();
 187:   }
 188: 
 189:   /**
 190:    * Convert this to a string, including its cause.
 191:    *
 192:    * @return the string conversion
 193:    */
 194:   public String toString()
 195:   {
 196:     return super.toString();
 197:   }
 198: 
 199:   /**
 200:    * Print the stack trace to <code>System.err</code>.
 201:    */
 202:   public void printStackTrace()
 203:   {
 204:     super.printStackTrace();
 205:   }
 206: 
 207:   /**
 208:    * Print the stack trace to a stream.
 209:    *
 210:    * @param stream the stream
 211:    */
 212:   public void printStackTrace(PrintStream stream)
 213:   {
 214:     super.printStackTrace(stream);
 215:   }
 216: 
 217:   /**
 218:    * Print the stack trace to a stream.
 219:    *
 220:    * @param stream the stream
 221:    */
 222:   public void printStackTrace(PrintWriter stream)
 223:   {
 224:     super.printStackTrace(stream);
 225:   }
 226: }