View Javadoc

1   /*
2    * $Id: CryptoFailureException.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.api.security;
12  
13  import org.mule.api.EncryptionStrategy;
14  import org.mule.api.MuleException;
15  import org.mule.config.i18n.CoreMessages;
16  import org.mule.config.i18n.Message;
17  
18  /**
19   * <code>CryptoFailureException</code> is a generic exception thrown by an
20   * CryptoStrategy if encryption or decryption fails. The constuctors of this
21   * exception accept a EncryptionStrategy that will be included in the exception
22   * message. Implementors of EncryptionStrategy should provide a toString method
23   * that exposes *only* information that maybe useful for debugging not passwords,
24   * secret keys, etc.
25   */
26  public class CryptoFailureException extends MuleException
27  {
28      /**
29       * Serial version
30       */
31      private static final long serialVersionUID = 1336343718508294379L;
32  
33      private transient EncryptionStrategy encryptionStrategy;
34  
35      public CryptoFailureException(Message message, EncryptionStrategy strategy)
36      {
37          super(message);
38          String s = (strategy == null ? "null" : strategy.toString());
39          addInfo("Encryption", s);
40          this.encryptionStrategy = strategy;
41      }
42  
43      public CryptoFailureException(Message message, EncryptionStrategy strategy, Throwable cause)
44      {
45          super(message, cause);
46          String s = (strategy == null ? "null" : strategy.toString());
47          addInfo("Encryption", s);
48          this.encryptionStrategy = strategy;
49      }
50  
51      public CryptoFailureException(EncryptionStrategy strategy, Throwable cause)
52      {
53          super(CoreMessages.cryptoFailure(), cause);
54          String s = (strategy == null ? "null" : strategy.toString());
55          addInfo("Encryption", s);
56          this.encryptionStrategy = strategy;
57  
58      }
59  
60      public EncryptionStrategy getEncryptionStrategy()
61      {
62          return encryptionStrategy;
63      }
64  }