Search in sources :

Example 1 with ObjectInputStreamWithClassloader

use of org.teiid.core.util.ObjectInputStreamWithClassloader in project teiid by teiid.

the class BasicCryptor method unsealObject.

public synchronized Object unsealObject(Object object) throws CryptoException {
    if (useSealedObject) {
        if (!(object instanceof SealedObject)) {
            return object;
        }
        SealedObject so = (SealedObject) object;
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try {
            if (cl != classLoader) {
                Thread.currentThread().setContextClassLoader(BasicCryptor.class.getClassLoader());
            }
            return so.getObject(decryptCipher);
        } catch (Exception e) {
            try {
                initDecryptCipher();
            } catch (CryptoException err) {
            // shouldn't happen
            }
            throw new CryptoException(CorePlugin.Event.TEIID10006, CorePlugin.Util.gs(CorePlugin.Event.TEIID10006, e.getClass().getName(), e.getMessage()));
        } finally {
            Thread.currentThread().setContextClassLoader(cl);
        }
    }
    if (!(object instanceof byte[])) {
        return object;
    }
    byte[] bytes = (byte[]) object;
    bytes = decrypt(bytes);
    try {
        ObjectInputStream ois = new ObjectInputStreamWithClassloader(new ByteArrayInputStream(bytes), classLoader);
        return ois.readObject();
    } catch (Exception e) {
        throw new CryptoException(CorePlugin.Event.TEIID10006, CorePlugin.Util.gs(CorePlugin.Event.TEIID10006, e.getClass().getName(), e.getMessage()));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SealedObject(javax.crypto.SealedObject) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) ObjectInputStream(java.io.ObjectInputStream) ObjectInputStreamWithClassloader(org.teiid.core.util.ObjectInputStreamWithClassloader)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 SealedObject (javax.crypto.SealedObject)1 ObjectInputStreamWithClassloader (org.teiid.core.util.ObjectInputStreamWithClassloader)1