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