diff -Nru jasypt-1.8/ChangeLog.txt jasypt-1.9.2/ChangeLog.txt
--- jasypt-1.8/ChangeLog.txt 2011-07-25 11:16:33.000000000 +0000
+++ jasypt-1.9.2/ChangeLog.txt 2014-02-25 20:11:02.000000000 +0000
@@ -1,4 +1,51 @@
+1.9.2
+=====
+- Replaced Arrays.equals() call in StandardByteDigester with a time-constant function in order
+ to enhance protection against timing attacks in unintended scenarios where parts of jasypt are
+ used for matching message-authentication hashes. Note: password matching and general
+ hash matching scenarios using jasypt were NOT affected by vulnerabilities to timing attacks.
+- Modified how the EncryptableProperties objects deal with serialization, so that now they only
+ make use of the singleton encryptor registry when they are actually serialized (if they are).
+ This allows the removal of the "finalize()" method in this objects, which was causing trouble in
+ some specific Java VM setups.
+- Created new interface org.jasypt.salt.FixedSaltGenerator and two new implementations for it,
+ org.jasypt.salt.StringFixedSaltGenerator and org.jasypt.salt.ByteArrayFixedSaltGenerator,
+ deprecating old equivalents "FixedStringSaltGenerator" and "FixedByteArraySaltGenerator". This
+ new interface allows applying important performance optimizations to encryption operations when
+ using fixed salt.
+- Modified UTF-8 normalization infrastructure in order to make code compile in Java 1.4.
+- Updated testing-scope dependencies.
+
+
+1.9.1
+=====
+- Fixed insufficient entropy in RandomSaltGenerator due to seeding mechanism.
+- Fixed CLI scripts for Windows and CYGWIN environments.
+
+
+1.9.0
+=====
+- Divided old "jasypt" artifact into several modules:
+ * jasypt (core)
+ * jasypt-hibernate3
+ * jasypt-hibernate4
+ * jasypt-spring2
+ * jasypt-spring3
+ * jasypt-acegisecurity
+ * jasypt-springsecurity2
+ * jasypt-springsecurity3
+ * jasypt-wicket13
+ * jasypt-wicket15
+- Fixed error in CLI .bat files resulting in bad processing of CLI commands
+ which involved passwords containing exclamation mark symbols.
+- Fixed bug in PooledPBEStringEncryptor which caused first encryptor in pool not
+ use hexadecimal output type.
+- Added implementation of Hashtable's "get(Object)" method to
+ org.jasypt.properties.EncryptableProperties, so that this method now performs
+ decryption instead of it only being performed at "getProperty(key)".
+
+
1.8
===
- Small bugfixing for large BigInteger number decryption.
diff -Nru jasypt-1.8/.cvsignore jasypt-1.9.2/.cvsignore
--- jasypt-1.8/.cvsignore 2008-01-16 14:57:37.000000000 +0000
+++ jasypt-1.9.2/.cvsignore 1970-01-01 00:00:00.000000000 +0000
@@ -1,5 +0,0 @@
-.settings
-target
-.classpath
-.project
-
diff -Nru jasypt-1.8/debian/changelog jasypt-1.9.2/debian/changelog
--- jasypt-1.8/debian/changelog 2015-08-31 08:40:00.000000000 +0000
+++ jasypt-1.9.2/debian/changelog 2016-05-18 10:30:41.000000000 +0000
@@ -1,3 +1,17 @@
+jasypt (1.9.2-1) unstable; urgency=medium
+
+ * Team upload.
+ * New upstream release
+ - Removed the patches
+ - Removed the unused build dependencies (Spring, Hibernate)
+ * Enabled the unit tests
+ * Build with the DH sequencer instead of CDBS
+ * Standards-Version updated to 3.9.8 (no changes)
+ * Use a secure Vcs-Git URL
+ * Create the upstream tarball from the Subversion repository on SourceForge
+
+ -- Emmanuel Bourg
diff -Nru jasypt-1.8/src/main/java/org/jasypt/digest/config/SimpleStringDigesterConfig.java jasypt-1.9.2/src/main/java/org/jasypt/digest/config/SimpleStringDigesterConfig.java
--- jasypt-1.8/src/main/java/org/jasypt/digest/config/SimpleStringDigesterConfig.java 2011-07-24 16:21:44.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/digest/config/SimpleStringDigesterConfig.java 2014-02-25 00:22:19.000000000 +0000
@@ -20,7 +20,6 @@
package org.jasypt.digest.config;
import org.jasypt.commons.CommonUtils;
-import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
/**
diff -Nru jasypt-1.8/src/main/java/org/jasypt/digest/config/StringDigesterConfig.java jasypt-1.9.2/src/main/java/org/jasypt/digest/config/StringDigesterConfig.java
--- jasypt-1.8/src/main/java/org/jasypt/digest/config/StringDigesterConfig.java 2011-07-24 16:21:44.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/digest/config/StringDigesterConfig.java 2014-02-25 00:22:19.000000000 +0000
@@ -19,7 +19,6 @@
*/
package org.jasypt.digest.config;
-import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
diff -Nru jasypt-1.8/src/main/java/org/jasypt/digest/PooledByteDigester.java jasypt-1.9.2/src/main/java/org/jasypt/digest/PooledByteDigester.java
--- jasypt-1.8/src/main/java/org/jasypt/digest/PooledByteDigester.java 2011-07-24 16:21:44.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/digest/PooledByteDigester.java 2014-02-25 00:22:19.000000000 +0000
@@ -24,8 +24,6 @@
import org.jasypt.commons.CommonUtils;
import org.jasypt.digest.config.DigesterConfig;
import org.jasypt.exceptions.AlreadyInitializedException;
-import org.jasypt.exceptions.EncryptionInitializationException;
-import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.salt.SaltGenerator;
diff -Nru jasypt-1.8/src/main/java/org/jasypt/digest/PooledStringDigester.java jasypt-1.9.2/src/main/java/org/jasypt/digest/PooledStringDigester.java
--- jasypt-1.8/src/main/java/org/jasypt/digest/PooledStringDigester.java 2011-07-24 16:21:44.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/digest/PooledStringDigester.java 2014-02-25 00:22:19.000000000 +0000
@@ -23,10 +23,7 @@
import org.jasypt.commons.CommonUtils;
import org.jasypt.digest.config.DigesterConfig;
-import org.jasypt.digest.config.StringDigesterConfig;
import org.jasypt.exceptions.AlreadyInitializedException;
-import org.jasypt.exceptions.EncryptionInitializationException;
-import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.salt.SaltGenerator;
diff -Nru jasypt-1.8/src/main/java/org/jasypt/digest/StandardByteDigester.java jasypt-1.9.2/src/main/java/org/jasypt/digest/StandardByteDigester.java
--- jasypt-1.8/src/main/java/org/jasypt/digest/StandardByteDigester.java 2010-10-24 23:36:03.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/digest/StandardByteDigester.java 2014-02-20 16:41:18.000000000 +0000
@@ -23,7 +23,6 @@
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
-import java.util.Arrays;
import org.jasypt.commons.CommonUtils;
import org.jasypt.digest.config.DigesterConfig;
@@ -1099,7 +1098,7 @@
final byte[] encryptedMessage = digest(message, salt);
// If, using the same salt, digests match, then messages too.
- return (Arrays.equals(encryptedMessage, digest));
+ return (digestsAreEqual(encryptedMessage, digest));
} catch (Exception e) {
// If digest fails, it is more secure not to return any information
@@ -1110,6 +1109,27 @@
}
+ // Time-constant comparison of byte arrays
+ private static boolean digestsAreEqual(byte[] a, byte[] b) {
+
+ if (a == null || b == null) {
+ return false;
+ }
+
+ final int aLen = a.length;
+ if (b.length != aLen) {
+ return false;
+ }
+
+ int match = 0;
+ for (int i = 0; i < aLen; i++) {
+ match |= a[i] ^ b[i];
+ }
+
+ return (match == 0);
+
+ }
+
}
diff -Nru jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/PooledPBEBigDecimalEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/PooledPBEBigDecimalEncryptor.java
--- jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/PooledPBEBigDecimalEncryptor.java 2011-07-24 16:21:44.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/PooledPBEBigDecimalEncryptor.java 2014-02-25 00:22:19.000000000 +0000
@@ -25,8 +25,6 @@
import org.jasypt.commons.CommonUtils;
import org.jasypt.encryption.pbe.config.PBEConfig;
import org.jasypt.exceptions.AlreadyInitializedException;
-import org.jasypt.exceptions.EncryptionInitializationException;
-import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.salt.SaltGenerator;
diff -Nru jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/PooledPBEBigIntegerEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/PooledPBEBigIntegerEncryptor.java
--- jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/PooledPBEBigIntegerEncryptor.java 2011-07-24 16:21:44.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/PooledPBEBigIntegerEncryptor.java 2014-02-25 00:22:19.000000000 +0000
@@ -25,8 +25,6 @@
import org.jasypt.commons.CommonUtils;
import org.jasypt.encryption.pbe.config.PBEConfig;
import org.jasypt.exceptions.AlreadyInitializedException;
-import org.jasypt.exceptions.EncryptionInitializationException;
-import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.salt.SaltGenerator;
diff -Nru jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/PooledPBEByteEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/PooledPBEByteEncryptor.java
--- jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/PooledPBEByteEncryptor.java 2011-07-24 16:21:44.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/PooledPBEByteEncryptor.java 2014-02-25 00:22:19.000000000 +0000
@@ -24,7 +24,6 @@
import org.jasypt.commons.CommonUtils;
import org.jasypt.encryption.pbe.config.PBEConfig;
import org.jasypt.exceptions.AlreadyInitializedException;
-import org.jasypt.exceptions.EncryptionInitializationException;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.salt.SaltGenerator;
diff -Nru jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/PooledPBEStringEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/PooledPBEStringEncryptor.java
--- jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/PooledPBEStringEncryptor.java 2011-07-24 16:21:44.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/PooledPBEStringEncryptor.java 2014-02-25 00:22:19.000000000 +0000
@@ -24,8 +24,6 @@
import org.jasypt.commons.CommonUtils;
import org.jasypt.encryption.pbe.config.PBEConfig;
import org.jasypt.exceptions.AlreadyInitializedException;
-import org.jasypt.exceptions.EncryptionInitializationException;
-import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.salt.SaltGenerator;
@@ -450,7 +448,7 @@
poolPosition = this.roundRobin;
this.roundRobin = (this.roundRobin + 1) % this.poolSize;
}
-
+
return this.pool[poolPosition].encrypt(message);
}
diff -Nru jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/StandardPBEBigDecimalEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/StandardPBEBigDecimalEncryptor.java
--- jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/StandardPBEBigDecimalEncryptor.java 2011-07-24 15:55:47.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/StandardPBEBigDecimalEncryptor.java 2011-12-08 02:15:37.000000000 +0000
@@ -361,7 +361,9 @@
final StandardPBEBigDecimalEncryptor[] clones = new StandardPBEBigDecimalEncryptor[size];
- for (int i = 0; i < size; i++) {
+ clones[0] = this;
+
+ for (int i = 1; i < size; i++) {
clones[i] = new StandardPBEBigDecimalEncryptor(byteEncryptorClones[i]);
}
diff -Nru jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/StandardPBEBigIntegerEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/StandardPBEBigIntegerEncryptor.java
--- jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/StandardPBEBigIntegerEncryptor.java 2011-07-24 15:55:47.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/StandardPBEBigIntegerEncryptor.java 2011-12-08 02:15:37.000000000 +0000
@@ -360,7 +360,9 @@
final StandardPBEBigIntegerEncryptor[] clones = new StandardPBEBigIntegerEncryptor[size];
- for (int i = 0; i < size; i++) {
+ clones[0] = this;
+
+ for (int i = 1; i < size; i++) {
clones[i] = new StandardPBEBigIntegerEncryptor(byteEncryptorClones[i]);
}
diff -Nru jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/StandardPBEByteEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/StandardPBEByteEncryptor.java
--- jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/StandardPBEByteEncryptor.java 2011-07-25 11:16:33.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/StandardPBEByteEncryptor.java 2014-02-25 01:52:26.000000000 +0000
@@ -35,6 +35,7 @@
import org.jasypt.exceptions.EncryptionInitializationException;
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
import org.jasypt.normalization.Normalizer;
+import org.jasypt.salt.FixedSaltGenerator;
import org.jasypt.salt.RandomSaltGenerator;
import org.jasypt.salt.SaltGenerator;
@@ -202,8 +203,15 @@
private Cipher encryptCipher = null;
private Cipher decryptCipher = null;
-
+ // Flag which indicates whether the salt generator being used is a
+ // FixedSaltGenerator implementation (in which case some optimizations can
+ // be applied).
+ private boolean usingFixedSalt = false;
+ private byte[] fixedSaltInUse = null;
+
+
+
/**
* Creates a new instance of StandardPBEByteEncryptor.
@@ -589,13 +597,13 @@
resolveConfigurationPassword();
- String configAlgorithm = this.config.getAlgorithm();
+ final String configAlgorithm = this.config.getAlgorithm();
if (configAlgorithm != null) {
CommonUtils.validateNotEmpty(configAlgorithm,
"Algorithm cannot be set empty");
}
- Integer configKeyObtentionIterations =
+ final Integer configKeyObtentionIterations =
this.config.getKeyObtentionIterations();
if (configKeyObtentionIterations != null) {
CommonUtils.validateIsTrue(configKeyObtentionIterations.intValue() > 0,
@@ -603,15 +611,15 @@
"greater than zero");
}
- SaltGenerator configSaltGenerator = this.config.getSaltGenerator();
+ final SaltGenerator configSaltGenerator = this.config.getSaltGenerator();
- String configProviderName = this.config.getProviderName();
+ final String configProviderName = this.config.getProviderName();
if (configProviderName != null) {
CommonUtils.validateNotEmpty(configProviderName,
"Provider name cannot be empty");
}
- Provider configProvider = this.config.getProvider();
+ final Provider configProvider = this.config.getProvider();
this.algorithm =
((this.algorithmSet) || (configAlgorithm == null))?
@@ -655,7 +663,7 @@
/*
* Encryption and decryption Ciphers are created the usual way.
*/
- PBEKeySpec pbeKeySpec = new PBEKeySpec(normalizedPassword);
+ final PBEKeySpec pbeKeySpec = new PBEKeySpec(normalizedPassword);
// We don't need the char[] passwords anymore -> clean!
cleanPassword(this.password);
@@ -664,7 +672,7 @@
if (this.provider != null) {
- SecretKeyFactory factory =
+ final SecretKeyFactory factory =
SecretKeyFactory.getInstance(
this.algorithm,
this.provider);
@@ -678,7 +686,7 @@
} else if (this.providerName != null) {
- SecretKeyFactory factory =
+ final SecretKeyFactory factory =
SecretKeyFactory.getInstance(
this.algorithm,
this.providerName);
@@ -692,7 +700,7 @@
} else {
- SecretKeyFactory factory =
+ final SecretKeyFactory factory =
SecretKeyFactory.getInstance(this.algorithm);
this.key = factory.generateSecret(pbeKeySpec);
@@ -711,13 +719,48 @@
// The salt size for the chosen algorithm is set to be equal
// to the algorithm's block size (if it is a block algorithm).
- int algorithmBlockSize = this.encryptCipher.getBlockSize();
+ final int algorithmBlockSize = this.encryptCipher.getBlockSize();
if (algorithmBlockSize > 0) {
this.saltSizeBytes = algorithmBlockSize;
}
+ this.usingFixedSalt = (this.saltGenerator instanceof FixedSaltGenerator);
+
+ if (this.usingFixedSalt) {
+
+ // Create salt
+ this.fixedSaltInUse =
+ this.saltGenerator.generateSalt(this.saltSizeBytes);
+
+ /*
+ * Initialize the Cipher objects themselves. Due to the fact that
+ * we will be using a fixed salt, this can be done just once, which
+ * means a better performance at the encrypt/decrypt methods.
+ */
+
+ final PBEParameterSpec parameterSpec =
+ new PBEParameterSpec(this.fixedSaltInUse, this.keyObtentionIterations);
+
+ try {
+
+ this.encryptCipher.init(
+ Cipher.ENCRYPT_MODE, this.key, parameterSpec);
+ this.decryptCipher.init(
+ Cipher.DECRYPT_MODE, this.key, parameterSpec);
+
+ } catch (final Exception e) {
+ // If encryption fails, it is more secure not to return any
+ // information about the cause in nested exceptions. Simply fail.
+ throw new EncryptionOperationNotPossibleException();
+ }
+
+
+ }
+
+
this.initialized = true;
+
}
}
@@ -831,24 +874,37 @@
}
try {
-
- // Create salt
- final byte[] salt =
- this.saltGenerator.generateSalt(this.saltSizeBytes);
- /*
- * Perform encryption using the Cipher
- */
- final PBEParameterSpec parameterSpec =
- new PBEParameterSpec(salt, this.keyObtentionIterations);
+ final byte[] salt;
+ final byte[] encryptedMessage;
+ if (this.usingFixedSalt) {
- byte[] encryptedMessage = null;
- synchronized (this.encryptCipher) {
- this.encryptCipher.init(
- Cipher.ENCRYPT_MODE, this.key, parameterSpec);
- encryptedMessage = this.encryptCipher.doFinal(message);
+ salt = this.fixedSaltInUse;
+
+ synchronized (this.encryptCipher) {
+ encryptedMessage = this.encryptCipher.doFinal(message);
+ }
+
+ } else {
+
+ // Create salt
+ salt = this.saltGenerator.generateSalt(this.saltSizeBytes);
+
+ /*
+ * Perform encryption using the Cipher
+ */
+ final PBEParameterSpec parameterSpec =
+ new PBEParameterSpec(salt, this.keyObtentionIterations);
+
+ synchronized (this.encryptCipher) {
+ this.encryptCipher.init(
+ Cipher.ENCRYPT_MODE, this.key, parameterSpec);
+ encryptedMessage = this.encryptCipher.doFinal(message);
+ }
+
}
+
// Finally we build an array containing both the unencrypted salt
// and the result of the encryption. This is done only
// if the salt generator we are using specifies to do so.
@@ -862,12 +918,12 @@
return encryptedMessage;
- } catch (InvalidKeyException e) {
+ } catch (final InvalidKeyException e) {
// The problem could be not having the unlimited strength policies
// installed, so better give a usefull error message.
handleInvalidKeyException(e);
throw new EncryptionOperationNotPossibleException();
- } catch (Exception e) {
+ } catch (final Exception e) {
// If encryption fails, it is more secure not to return any
// information about the cause in nested exceptions. Simply fail.
throw new EncryptionOperationNotPossibleException();
@@ -943,39 +999,57 @@
System.arraycopy(encryptedMessage, saltStart, salt, 0, saltSize);
System.arraycopy(encryptedMessage, encMesKernelStart, encryptedMessageKernel, 0, encMesKernelSize);
- } else {
+ } else if (!this.usingFixedSalt){
salt = this.saltGenerator.generateSalt(this.saltSizeBytes);
encryptedMessageKernel = encryptedMessage;
+ } else {
+ // this.usingFixedSalt == true
+
+ salt = this.fixedSaltInUse;
+ encryptedMessageKernel = encryptedMessage;
+
}
-
- /*
- * Perform decryption using the Cipher
- */
- final PBEParameterSpec parameterSpec =
- new PBEParameterSpec(salt, this.keyObtentionIterations);
- byte[] decryptedMessage = null;
-
- synchronized (this.decryptCipher) {
- this.decryptCipher.init(
- Cipher.DECRYPT_MODE, this.key, parameterSpec);
- decryptedMessage =
- this.decryptCipher.doFinal(encryptedMessageKernel);
- }
+ final byte[] decryptedMessage;
+ if (this.usingFixedSalt) {
+
+ /*
+ * Fixed salt is being used, therefore no initialization supposedly needed
+ */
+ synchronized (this.decryptCipher) {
+ decryptedMessage =
+ this.decryptCipher.doFinal(encryptedMessageKernel);
+ }
+
+ } else {
+
+ /*
+ * Perform decryption using the Cipher
+ */
+ final PBEParameterSpec parameterSpec =
+ new PBEParameterSpec(salt, this.keyObtentionIterations);
+
+ synchronized (this.decryptCipher) {
+ this.decryptCipher.init(
+ Cipher.DECRYPT_MODE, this.key, parameterSpec);
+ decryptedMessage =
+ this.decryptCipher.doFinal(encryptedMessageKernel);
+ }
+ }
+
// Return the results
return decryptedMessage;
-
- } catch (InvalidKeyException e) {
+ } catch (final InvalidKeyException e) {
// The problem could be not having the unlimited strength policies
// installed, so better give a usefull error message.
handleInvalidKeyException(e);
throw new EncryptionOperationNotPossibleException();
- } catch (Exception e) {
+ } catch (final Exception e) {
// If decryption fails, it is more secure not to return any
// information about the cause in nested exceptions. Simply fail.
throw new EncryptionOperationNotPossibleException();
@@ -991,7 +1065,7 @@
* message for this is simply "invalid key size", which does not provide
* enough clues for the user to know what is really going on).
*/
- private void handleInvalidKeyException(InvalidKeyException e) {
+ private void handleInvalidKeyException(final InvalidKeyException e) {
if ((e.getMessage() != null) &&
((e.getMessage().toUpperCase().indexOf("KEY SIZE") != -1))) {
diff -Nru jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/StandardPBEStringEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/StandardPBEStringEncryptor.java
--- jasypt-1.8/src/main/java/org/jasypt/encryption/pbe/StandardPBEStringEncryptor.java 2011-07-24 15:55:47.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/encryption/pbe/StandardPBEStringEncryptor.java 2011-12-08 02:15:37.000000000 +0000
@@ -217,7 +217,7 @@
/*
* Creates a new instance of StandardPBEStringEncryptor using
- * the specified byte digester (constructor used for cloning)
+ * the specified byte encryptor (constructor used for cloning)
*/
private StandardPBEStringEncryptor(final StandardPBEByteEncryptor standardPBEByteEncryptor) {
super();
@@ -446,6 +446,7 @@
this.stringOutputType =
CommonUtils.
getStandardStringOutputType(stringOutputType);
+
this.stringOutputTypeSet = true;
}
@@ -468,14 +469,16 @@
final StandardPBEByteEncryptor[] byteEncryptorClones =
this.byteEncryptor.cloneAndInitializeEncryptor(size);
+ initializeSpecifics();
+
final StandardPBEStringEncryptor[] clones = new StandardPBEStringEncryptor[size];
- for (int i = 0; i < size; i++) {
+ clones[0] = this;
+
+ for (int i = 1; i < size; i++) {
clones[i] = new StandardPBEStringEncryptor(byteEncryptorClones[i]);
- if (i > 0) {
- if (CommonUtils.isNotEmpty(this.stringOutputType)) {
- clones[i].setStringOutputType(this.stringOutputType);
- }
+ if (CommonUtils.isNotEmpty(this.stringOutputType)) {
+ clones[i].setStringOutputType(this.stringOutputType);
}
}
@@ -546,30 +549,35 @@
// Double-check to avoid synchronization issues
if (!this.isInitialized()) {
+ initializeSpecifics();
+ this.byteEncryptor.initialize();
+ }
- /*
- * If a StringPBEConfig object has been set, we need to
- * consider the values it returns (if, for each value, the
- * corresponding "setX" method has not been called).
- */
- if (this.stringPBEConfig != null) {
-
- final String configStringOutputType =
- this.stringPBEConfig.getStringOutputType();
-
- this.stringOutputType =
- ((this.stringOutputTypeSet) || (configStringOutputType == null))?
- this.stringOutputType : configStringOutputType;
-
- }
+ }
+
+
+
+
+ private void initializeSpecifics() {
+ /*
+ * If a StringPBEConfig object has been set, we need to
+ * consider the values it returns (if, for each value, the
+ * corresponding "setX" method has not been called).
+ */
+ if (this.stringPBEConfig != null) {
- this.stringOutputTypeBase64 =
- (CommonUtils.STRING_OUTPUT_TYPE_BASE64.
- equalsIgnoreCase(this.stringOutputType));
+ final String configStringOutputType =
+ this.stringPBEConfig.getStringOutputType();
+
+ this.stringOutputType =
+ ((this.stringOutputTypeSet) || (configStringOutputType == null))?
+ this.stringOutputType : configStringOutputType;
- this.byteEncryptor.initialize();
-
}
+
+ this.stringOutputTypeBase64 =
+ (CommonUtils.STRING_OUTPUT_TYPE_BASE64.
+ equalsIgnoreCase(this.stringOutputType));
}
diff -Nru jasypt-1.8/src/main/java/org/jasypt/exceptions/PasswordAlreadyCleanedException.java jasypt-1.9.2/src/main/java/org/jasypt/exceptions/PasswordAlreadyCleanedException.java
--- jasypt-1.8/src/main/java/org/jasypt/exceptions/PasswordAlreadyCleanedException.java 2011-07-24 15:55:47.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/exceptions/PasswordAlreadyCleanedException.java 2011-12-08 10:03:24.000000000 +0000
@@ -39,7 +39,9 @@
super("Password already cleaned: The encryptor that uses this password has " +
"already been initialized and therefore this password has been cleaned so "+
"that it is no more present in memory. An exception has been raised when accessing " +
- "this property in order to avoid inconsistencies.");
+ "this property in order to avoid inconsistencies. A possible reason for this error " +
+ "is that you are using the same PBEConfig object to configure two different " +
+ "PBE encryptor instances.");
}
}
diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/connectionprovider/EncryptedPasswordC3P0ConnectionProvider.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/connectionprovider/EncryptedPasswordC3P0ConnectionProvider.java
--- jasypt-1.8/src/main/java/org/jasypt/hibernate/connectionprovider/EncryptedPasswordC3P0ConnectionProvider.java 2010-10-16 18:38:00.000000000 +0000
+++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/connectionprovider/EncryptedPasswordC3P0ConnectionProvider.java 1970-01-01 00:00:00.000000000 +0000
@@ -1,149 +0,0 @@
-/*
- * =============================================================================
- *
- * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * =============================================================================
- */
-package org.jasypt.hibernate.connectionprovider;
-
-import java.util.Properties;
-
-import org.hibernate.cfg.Environment;
-import org.hibernate.connection.C3P0ConnectionProvider;
-import org.jasypt.encryption.pbe.PBEStringEncryptor;
-import org.jasypt.exceptions.EncryptionInitializationException;
-import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry;
-import org.jasypt.properties.PropertyValueEncryptionUtils;
-
-/**
- *
- *
- * Extension of {@link C3P0ConnectionProvider} that allows the user
- * to write the datasource configuration parameters in an encrypted manner in the
- * hibernate.cfg.xml or hibernate.properties file
- *
- * The encryptable parameters are:
- *
- *
- *
- * The name of the password encryptor (decryptor, in fact) will be set in - * property hibernate.connection.encryptor_registered_name. - * Its value must be the name of a {@link PBEStringEncryptor} object - * previously registered within {@link HibernatePBEEncryptorRegistry}. - *
- *- * An example hibernate.cfg.xml file: - *
- *- *
- * <hibernate-configuration> - * - * <session-factory> - * - * - * <property name="connection.provider_class">org.jasypt.hibernate.connectionprovider.EncryptedPasswordC3P0ConnectionProvider</property> - * <property name="connection.encryptor_registered_name">stringEncryptor</property> - * <property name="connection.driver_class">org.postgresql.Driver</property> - * <property name="connection.url">jdbc:postgresql://localhost/mydatabase</property> - * <property name="connection.username">myuser</property> - * <property name="connection.password">ENC(T6DAe34NasW==)</property> - * <property name="c3p0.min_size">5</property> - * <property name="c3p0.max_size">20</property> - * <property name="c3p0.timeout">1800</property> - * <property name="c3p0.max_statements">50</property> - * ... - * - * </session-factory> - * - * ... - * - * </hibernate-configuration> - *- * - * - * @since 1.4 - * - * @author Daniel Fernández - * - */ -public final class EncryptedPasswordC3P0ConnectionProvider - extends C3P0ConnectionProvider { - - - public EncryptedPasswordC3P0ConnectionProvider() { - super(); - } - - - public void configure(final Properties props) { - - final String encryptorRegisteredName = - props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME); - - final HibernatePBEEncryptorRegistry encryptorRegistry = - HibernatePBEEncryptorRegistry.getInstance(); - final PBEStringEncryptor encryptor = - encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName); - - if (encryptor == null) { - throw new EncryptionInitializationException( - "No string encryptor registered for hibernate " + - "with name \"" + encryptorRegisteredName + "\""); - } - - // Get the original values, which may be encrypted - final String driver = props.getProperty(Environment.DRIVER); - final String url = props.getProperty(Environment.URL); - final String user = props.getProperty(Environment.USER); - final String password = props.getProperty(Environment.PASS); - - // Perform decryption operations as needed and store the new values - if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) { - props.setProperty( - Environment.DRIVER, - PropertyValueEncryptionUtils.decrypt(driver, encryptor)); - } - if (PropertyValueEncryptionUtils.isEncryptedValue(url)) { - props.setProperty( - Environment.URL, - PropertyValueEncryptionUtils.decrypt(url, encryptor)); - } - if (PropertyValueEncryptionUtils.isEncryptedValue(user)) { - props.setProperty( - Environment.USER, - PropertyValueEncryptionUtils.decrypt(user, encryptor)); - } - if (PropertyValueEncryptionUtils.isEncryptedValue(password)) { - props.setProperty( - Environment.PASS, - PropertyValueEncryptionUtils.decrypt(password, encryptor)); - } - - // Let Hibernate do the rest - super.configure(props); - - } - - - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/connectionprovider/EncryptedPasswordDriverManagerConnectionProvider.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/connectionprovider/EncryptedPasswordDriverManagerConnectionProvider.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/connectionprovider/EncryptedPasswordDriverManagerConnectionProvider.java 2010-10-16 18:38:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/connectionprovider/EncryptedPasswordDriverManagerConnectionProvider.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,147 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.connectionprovider; - -import java.util.Properties; - -import org.hibernate.cfg.Environment; -import org.hibernate.connection.DriverManagerConnectionProvider; -import org.jasypt.encryption.pbe.PBEStringEncryptor; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.properties.PropertyValueEncryptionUtils; - -/** - * - *
- * Extension of {@link DriverManagerConnectionProvider} that allows the user - * to write the datasource configuration parameters in an encrypted manner in the - * hibernate.cfg.xml or hibernate.properties file - *
- *- * The encryptable parameters are: - *
- * The name of the password encryptor (decryptor, in fact) will be set in - * property hibernate.connection.encryptor_registered_name. - * Its value must be the name of a {@link PBEStringEncryptor} object - * previously registered within {@link HibernatePBEEncryptorRegistry}. - *
- *- * An example hibernate.cfg.xml file: - *
- *- *
- * <hibernate-configuration> - * - * <session-factory> - * - * <!-- Database connection settings --> - * <property name="connection.provider_class">org.jasypt.hibernate.connectionprovider.EncryptedPasswordDriverManagerConnectionProvider</property> - * <property name="connection.encryptor_registered_name">stringEncryptor</property> - * <property name="connection.driver_class">org.postgresql.Driver</property> - * <property name="connection.url">jdbc:postgresql://localhost/mydatabase</property> - * <property name="connection.username">myuser</property> - * <property name="connection.password">ENC(T6DAe34NasW==)</property> - * <property name="connection.pool_size">5</property> - * - * ... - * - * </session-factory> - * - * ... - * - * </hibernate-configuration> - *- * - * - * @since 1.4 - * - * @author Daniel Fernández - * - */ -public final class EncryptedPasswordDriverManagerConnectionProvider - extends DriverManagerConnectionProvider { - - - public EncryptedPasswordDriverManagerConnectionProvider() { - super(); - } - - - public void configure(final Properties props) { - - final String encryptorRegisteredName = - props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME); - - final HibernatePBEEncryptorRegistry encryptorRegistry = - HibernatePBEEncryptorRegistry.getInstance(); - final PBEStringEncryptor encryptor = - encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName); - - if (encryptor == null) { - throw new EncryptionInitializationException( - "No string encryptor registered for hibernate " + - "with name \"" + encryptorRegisteredName + "\""); - } - - // Get the original values, which may be encrypted - final String driver = props.getProperty(Environment.DRIVER); - final String url = props.getProperty(Environment.URL); - final String user = props.getProperty(Environment.USER); - final String password = props.getProperty(Environment.PASS); - - // Perform decryption operations as needed and store the new values - if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) { - props.setProperty( - Environment.DRIVER, - PropertyValueEncryptionUtils.decrypt(driver, encryptor)); - } - if (PropertyValueEncryptionUtils.isEncryptedValue(url)) { - props.setProperty( - Environment.URL, - PropertyValueEncryptionUtils.decrypt(url, encryptor)); - } - if (PropertyValueEncryptionUtils.isEncryptedValue(user)) { - props.setProperty( - Environment.USER, - PropertyValueEncryptionUtils.decrypt(user, encryptor)); - } - if (PropertyValueEncryptionUtils.isEncryptedValue(password)) { - props.setProperty( - Environment.PASS, - PropertyValueEncryptionUtils.decrypt(password, encryptor)); - } - - // Let Hibernate process - super.configure(props); - - } - - - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/connectionprovider/ParameterNaming.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/connectionprovider/ParameterNaming.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/connectionprovider/ParameterNaming.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/connectionprovider/ParameterNaming.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.connectionprovider; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; - - - -/** - *
- * Constant names of the parameters that can be used by a jasypt's - * Hibernate connection provider. - *
- * - * @since 1.4 - * - * @author Daniel Fernández - * - */ -public final class ParameterNaming { - - - /** - * Property in hibernate.cfg.xml or - * hibernate.properties which contains the registered name - * (in {@link HibernatePBEEncryptorRegistry}) of the encryptor which - * will be used to decrypt the datasource parameters. - */ - public static final String ENCRYPTOR_REGISTERED_NAME = - "hibernate.connection.encryptor_registered_name"; - - - private ParameterNaming() { - super(); - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEBigDecimalEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEBigDecimalEncryptor.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEBigDecimalEncryptor.java 2011-07-25 12:47:47.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEBigDecimalEncryptor.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,350 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.encryptor; - -import java.math.BigDecimal; - -import org.jasypt.encryption.pbe.PBEBigDecimalEncryptor; -import org.jasypt.encryption.pbe.StandardPBEBigDecimalEncryptor; -import org.jasypt.encryption.pbe.config.PBEConfig; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.salt.SaltGenerator; - -/** - *- * Placeholder class for PBEBigDecimalEncryptor objects which are - * eligible for use from Hibernate. - *
- *- * This class acts as a wrapper on a PBEBigDecimalEncryptor, allowing - * to be set a registered name (see {@link #setRegisteredName(String)}) - * and performing the needed registry operations against the - * {@link HibernatePBEEncryptorRegistry}. - *
- *- * It is not mandatory that a PBEBigDecimalEncryptor be explicitly set - * with {@link #setEncryptor(PBEBigDecimalEncryptor)}. If not, a - * StandardPBEBigDecimalEncryptor object will be created internally - * and it will be configurable with the - * {@link #setPassword(String)}/{@link #setPasswordCharArray(char[])}, - * {@link #setAlgorithm(String)}, {@link #setKeyObtentionIterations(int)}, - * {@link #setSaltGenerator(SaltGenerator)} - * and {@link #setConfig(PBEConfig)} methods. - *
- *- * This class is mainly intended for use from Spring Framework or some other - * IoC container (if you are not using a container of this kind, please see - * {@link HibernatePBEEncryptorRegistry}). The steps to be performed are - * the following: - *
- * This in a Spring config file would look like: - *
- *- *
- * ... - * <-- Optional, as the hibernateEncryptor could be directly set an --> - * <-- algorithm and password. --> - * <bean id="bigDecimalEncryptor" - * class="org.jasypt.encryption.pbe.StandardPBEBigDecimalEncryptor"> - * <property name="algorithm"> - * <value>PBEWithMD5AndDES</value> - * </property> - * <property name="password"> - * <value>XXXXX</value> - * </property> - * </bean> - * - * <bean id="hibernateEncryptor" - * class="org.jasypt.hibernate.encryptor.HibernatePBEBigDecimalEncryptor"> - * <property name="registeredName"> - * <value>myHibernateBigDecimalEncryptor</value> - * </property> - * <property name="encryptor"> - * <ref bean="bigDecimalEncryptor" /> - * </property> - * </bean> - * ... - *- * - *
- * And then in the Hibernate mapping file: - *
- *- *
- * <typedef name="encrypted" class="org.jasypt.hibernate.type.EncryptedBigDecimalType"> - * <param name="encryptorRegisteredName">myHibernateBigDecimalEncryptor</param> - * <param name="decimalScale">2</param> - * </typedef> - *- * - *
- * An important thing to note is that, when using HibernatePBEBigDecimalEncryptor - * objects this way to wrap PBEBigDecimalEncryptors, it is not - * necessary to deal with {@link HibernatePBEEncryptorRegistry}, - * because HibernatePBEBigDecimalEncryptor objects get automatically registered - * in the encryptor registry when their {@link #setRegisteredName(String)} - * method is called. - *
- * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class HibernatePBEBigDecimalEncryptor { - - private String registeredName = null; - private PBEBigDecimalEncryptor encryptor = null; - private boolean encryptorSet = false; - - - - /** - * Creates a new instance of HibernatePBEBigDecimalEncryptor It also - * creates a StandardPBEBigDecimalEncryptor for internal use, which - * can be overriden by calling setEncryptor(...). - */ - public HibernatePBEBigDecimalEncryptor() { - super(); - this.encryptor = new StandardPBEBigDecimalEncryptor(); - this.encryptorSet = false; - } - - - /* - * For internal use only, by the Registry, when a PBEBigDecimalEncryptor - * is registered programmatically. - */ - HibernatePBEBigDecimalEncryptor(final String registeredName, - final PBEBigDecimalEncryptor encryptor) { - this.encryptor = encryptor; - this.registeredName = registeredName; - this.encryptorSet = true; - } - - - /** - * Returns the encryptor which this object wraps. - * - * @return the encryptor. - */ - public PBEBigDecimalEncryptor getEncryptor() { - return this.encryptor; - } - - - /** - * Sets the PBEBigDecimalEncryptor to be held (wrapped) by this - * object. This method is optional and can be only called once. - * - * @param encryptor the encryptor. - */ - public void setEncryptor(final PBEBigDecimalEncryptor encryptor) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - this.encryptor = encryptor; - this.encryptorSet = true; - } - - - /** - * Sets the password to be used by the internal encryptor, if a specific - * encryptor has not been set with setEncryptor(...). - * - * @param password the password to be set for the internal encryptor - */ - public void setPassword(final String password) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigDecimalEncryptor standardPBEBigDecimalEncryptor = - (StandardPBEBigDecimalEncryptor) this.encryptor; - standardPBEBigDecimalEncryptor.setPassword(password); - } - - - /** - * Sets the password to be used by the internal encryptor (as a char[]), if a specific - * encryptor has not been set with setEncryptor(...). - * - * @since 1.8 - * @param password the password to be set for the internal encryptor - */ - public void setPasswordCharArray(final char[] password) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigDecimalEncryptor standardPBEBigDecimalEncryptor = - (StandardPBEBigDecimalEncryptor) this.encryptor; - standardPBEBigDecimalEncryptor.setPasswordCharArray(password); - } - - - /** - * Sets the algorithm to be used by the internal encryptor, if a specific - * encryptor has not been set with setEncryptor(...). - * - * @param algorithm the algorithm to be set for the internal encryptor - */ - public void setAlgorithm(final String algorithm) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigDecimalEncryptor standardPBEBigDecimalEncryptor = - (StandardPBEBigDecimalEncryptor) this.encryptor; - standardPBEBigDecimalEncryptor.setAlgorithm(algorithm); - } - - - /** - * Sets the key obtention iterations to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param keyObtentionIterations to be set for the internal encryptor - */ - public void setKeyObtentionIterations(final int keyObtentionIterations) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigDecimalEncryptor standardPBEBigDecimalEncryptor = - (StandardPBEBigDecimalEncryptor) this.encryptor; - standardPBEBigDecimalEncryptor.setKeyObtentionIterations( - keyObtentionIterations); - } - - - /** - * Sets the salt generator to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param saltGenerator the salt generator to be set for the internal - * encryptor. - */ - public void setSaltGenerator(final SaltGenerator saltGenerator) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigDecimalEncryptor standardPBEBigDecimalEncryptor = - (StandardPBEBigDecimalEncryptor) this.encryptor; - standardPBEBigDecimalEncryptor.setSaltGenerator(saltGenerator); - } - - - /** - * Sets the PBEConfig to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param config the PBEConfig to be set for the internal encryptor - */ - public void setConfig(final PBEConfig config) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigDecimalEncryptor standardPBEBigDecimalEncryptor = - (StandardPBEBigDecimalEncryptor) this.encryptor; - standardPBEBigDecimalEncryptor.setConfig(config); - } - - - /** - * Encrypts a message, delegating to wrapped encryptor. - * - * @param message the message to be encrypted. - * @return the encryption result. - */ - public BigDecimal encrypt(final BigDecimal message) { - if (this.encryptor == null) { - throw new EncryptionInitializationException( - "Encryptor has not been set into Hibernate wrapper"); - } - return this.encryptor.encrypt(message); - } - - - /** - * Decypts a message, delegating to wrapped encryptor - * - * @param encryptedMessage the message to be decrypted. - * @return the result of decryption. - */ - public BigDecimal decrypt(final BigDecimal encryptedMessage) { - if (this.encryptor == null) { - throw new EncryptionInitializationException( - "Encryptor has not been set into Hibernate wrapper"); - } - return this.encryptor.decrypt(encryptedMessage); - } - - - - /** - * Sets the registered name of the encryptor and adds it to the registry. - * - * @param registeredName the name with which the encryptor will be - * registered. - */ - public void setRegisteredName(final String registeredName) { - if (this.registeredName != null) { - // It had another name before, we have to clean - HibernatePBEEncryptorRegistry.getInstance(). - unregisterHibernatePBEBigDecimalEncryptor(this.registeredName); - } - this.registeredName = registeredName; - HibernatePBEEncryptorRegistry.getInstance(). - registerHibernatePBEBigDecimalEncryptor(this); - } - - /** - * Returns the name with which the wrapped encryptor is registered at - * the registry. - * - * @return the registered name. - */ - public String getRegisteredName() { - return this.registeredName; - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEBigIntegerEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEBigIntegerEncryptor.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEBigIntegerEncryptor.java 2011-07-25 12:47:47.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEBigIntegerEncryptor.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,349 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.encryptor; - -import java.math.BigInteger; - -import org.jasypt.encryption.pbe.PBEBigIntegerEncryptor; -import org.jasypt.encryption.pbe.StandardPBEBigIntegerEncryptor; -import org.jasypt.encryption.pbe.config.PBEConfig; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.salt.SaltGenerator; - -/** - *- * Placeholder class for PBEBigIntegerEncryptor objects which are - * eligible for use from Hibernate. - *
- *- * This class acts as a wrapper on a PBEBigIntegerEncryptor, allowing - * to be set a registered name (see {@link #setRegisteredName(String)}) - * and performing the needed registry operations against the - * {@link HibernatePBEEncryptorRegistry}. - *
- *- * It is not mandatory that a PBEBigIntegerEncryptor be explicitly set - * with {@link #setEncryptor(PBEBigIntegerEncryptor)}. If not, a - * StandardPBEBigIntegerEncryptor object will be created internally - * and it will be configurable with the - * {@link #setPassword(String)}/{@link #setPasswordCharArray(char[])}, - * {@link #setAlgorithm(String)}, {@link #setKeyObtentionIterations(int)}, - * {@link #setSaltGenerator(SaltGenerator)} - * and {@link #setConfig(PBEConfig)} methods. - *
- *- * This class is mainly intended for use from Spring Framework or some other - * IoC container (if you are not using a container of this kind, please see - * {@link HibernatePBEEncryptorRegistry}). The steps to be performed are - * the following: - *
- * This in a Spring config file would look like: - *
- *- *
- * ... - * <-- Optional, as the hibernateEncryptor could be directly set an --> - * <-- algorithm and password. --> - * <bean id="bigIntegerEncryptor" - * class="org.jasypt.encryption.pbe.StandardPBEBigIntegerEncryptor"> - * <property name="algorithm"> - * <value>PBEWithMD5AndDES</value> - * </property> - * <property name="password"> - * <value>XXXXX</value> - * </property> - * </bean> - * - * <bean id="hibernateEncryptor" - * class="org.jasypt.hibernate.encryptor.HibernatePBEBigIntegerEncryptor"> - * <property name="registeredName"> - * <value>myHibernateBigIntegerEncryptor</value> - * </property> - * <property name="encryptor"> - * <ref bean="bigIntegerEncryptor" /> - * </property> - * </bean> - * ... - *- * - *
- * And then in the Hibernate mapping file: - *
- *- *
- * <typedef name="encrypted" class="org.jasypt.hibernate.type.EncryptedBigIntegerType"> - * <param name="encryptorRegisteredName">myHibernateBigIntegerEncryptor</param> - * </typedef> - *- * - *
- * An important thing to note is that, when using HibernatePBEBigIntegerEncryptor - * objects this way to wrap PBEBigIntegerEncryptors, it is not - * necessary to deal with {@link HibernatePBEEncryptorRegistry}, - * because HibernatePBEBigIntegerEncryptor objects get automatically registered - * in the encryptor registry when their {@link #setRegisteredName(String)} - * method is called. - *
- * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class HibernatePBEBigIntegerEncryptor { - - private String registeredName = null; - private PBEBigIntegerEncryptor encryptor = null; - private boolean encryptorSet = false; - - - - /** - * Creates a new instance of HibernatePBEBigIntegerEncryptor It also - * creates a StandardPBEBigIntegerEncryptor for internal use, which - * can be overriden by calling setEncryptor(...). - */ - public HibernatePBEBigIntegerEncryptor() { - super(); - this.encryptor = new StandardPBEBigIntegerEncryptor(); - this.encryptorSet = false; - } - - - /* - * For internal use only, by the Registry, when a PBEBigIntegerEncryptor - * is registered programmatically. - */ - HibernatePBEBigIntegerEncryptor(final String registeredName, - final PBEBigIntegerEncryptor encryptor) { - this.encryptor = encryptor; - this.registeredName = registeredName; - this.encryptorSet = true; - } - - - /** - * Returns the encryptor which this object wraps. - * - * @return the encryptor. - */ - public PBEBigIntegerEncryptor getEncryptor() { - return this.encryptor; - } - - - /** - * Sets the PBEBigIntegerEncryptor to be held (wrapped) by this - * object. This method is optional and can be only called once. - * - * @param encryptor the encryptor. - */ - public void setEncryptor(final PBEBigIntegerEncryptor encryptor) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - this.encryptor = encryptor; - this.encryptorSet = true; - } - - - /** - * Sets the password to be used by the internal encryptor, if a specific - * encryptor has not been set with setEncryptor(...). - * - * @param password the password to be set for the internal encryptor - */ - public void setPassword(final String password) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigIntegerEncryptor standardPBEBigIntegerEncryptor = - (StandardPBEBigIntegerEncryptor) this.encryptor; - standardPBEBigIntegerEncryptor.setPassword(password); - } - - - /** - * Sets the password to be used by the internal encryptor (as a char[]), if a specific - * encryptor has not been set with setEncryptor(...). - * - * @since 1.8 - * @param password the password to be set for the internal encryptor - */ - public void setPasswordCharArray(final char[] password) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigIntegerEncryptor standardPBEBigIntegerEncryptor = - (StandardPBEBigIntegerEncryptor) this.encryptor; - standardPBEBigIntegerEncryptor.setPasswordCharArray(password); - } - - - /** - * Sets the algorithm to be used by the internal encryptor, if a specific - * encryptor has not been set with setEncryptor(...). - * - * @param algorithm the algorithm to be set for the internal encryptor - */ - public void setAlgorithm(final String algorithm) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigIntegerEncryptor standardPBEBigIntegerEncryptor = - (StandardPBEBigIntegerEncryptor) this.encryptor; - standardPBEBigIntegerEncryptor.setAlgorithm(algorithm); - } - - - /** - * Sets the key obtention iterations to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param keyObtentionIterations to be set for the internal encryptor - */ - public void setKeyObtentionIterations(final int keyObtentionIterations) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigIntegerEncryptor standardPBEBigIntegerEncryptor = - (StandardPBEBigIntegerEncryptor) this.encryptor; - standardPBEBigIntegerEncryptor.setKeyObtentionIterations( - keyObtentionIterations); - } - - - /** - * Sets the salt generator to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param saltGenerator the salt generator to be set for the internal - * encryptor. - */ - public void setSaltGenerator(final SaltGenerator saltGenerator) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigIntegerEncryptor standardPBEBigIntegerEncryptor = - (StandardPBEBigIntegerEncryptor) this.encryptor; - standardPBEBigIntegerEncryptor.setSaltGenerator(saltGenerator); - } - - - /** - * Sets the PBEConfig to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param config the PBEConfig to be set for the internal encryptor - */ - public void setConfig(final PBEConfig config) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEBigIntegerEncryptor standardPBEBigIntegerEncryptor = - (StandardPBEBigIntegerEncryptor) this.encryptor; - standardPBEBigIntegerEncryptor.setConfig(config); - } - - - /** - * Encrypts a message, delegating to wrapped encryptor. - * - * @param message the message to be encrypted. - * @return the encryption result. - */ - public BigInteger encrypt(final BigInteger message) { - if (this.encryptor == null) { - throw new EncryptionInitializationException( - "Encryptor has not been set into Hibernate wrapper"); - } - return this.encryptor.encrypt(message); - } - - - /** - * Decypts a message, delegating to wrapped encryptor - * - * @param encryptedMessage the message to be decrypted. - * @return the result of decryption. - */ - public BigInteger decrypt(final BigInteger encryptedMessage) { - if (this.encryptor == null) { - throw new EncryptionInitializationException( - "Encryptor has not been set into Hibernate wrapper"); - } - return this.encryptor.decrypt(encryptedMessage); - } - - - - /** - * Sets the registered name of the encryptor and adds it to the registry. - * - * @param registeredName the name with which the encryptor will be - * registered. - */ - public void setRegisteredName(final String registeredName) { - if (this.registeredName != null) { - // It had another name before, we have to clean - HibernatePBEEncryptorRegistry.getInstance(). - unregisterHibernatePBEBigIntegerEncryptor(this.registeredName); - } - this.registeredName = registeredName; - HibernatePBEEncryptorRegistry.getInstance(). - registerHibernatePBEBigIntegerEncryptor(this); - } - - /** - * Returns the name with which the wrapped encryptor is registered at - * the registry. - * - * @return the registered name. - */ - public String getRegisteredName() { - return this.registeredName; - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEByteEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEByteEncryptor.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEByteEncryptor.java 2011-07-25 12:47:47.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEByteEncryptor.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,347 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.encryptor; - -import org.jasypt.encryption.pbe.PBEByteEncryptor; -import org.jasypt.encryption.pbe.StandardPBEByteEncryptor; -import org.jasypt.encryption.pbe.config.PBEConfig; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.salt.SaltGenerator; - -/** - *- * Placeholder class for PBEByteEncryptor objects which are - * eligible for use from Hibernate. - *
- *- * This class acts as a wrapper on a PBEByteEncryptor, allowing - * to be set a registered name (see {@link #setRegisteredName(String)}) - * and performing the needed registry operations against the - * {@link HibernatePBEEncryptorRegistry}. - *
- *- * It is not mandatory that a PBEByteEncryptor be explicitly set - * with {@link #setEncryptor(PBEByteEncryptor)}. If not, a - * StandardPBEByteEncryptor object will be created internally - * and it will be configurable with the - * {@link #setPassword(String)}/{@link #setPasswordCharArray(char[])}, - * {@link #setAlgorithm(String)}, {@link #setKeyObtentionIterations(int)}, - * {@link #setSaltGenerator(SaltGenerator)} - * and {@link #setConfig(PBEConfig)} methods. - *
- *- * This class is mainly intended for use from Spring Framework or some other - * IoC container (if you are not using a container of this kind, please see - * {@link HibernatePBEEncryptorRegistry}). The steps to be performed are - * the following: - *
- * This in a Spring config file would look like: - *
- *- *
- * ... - * <-- Optional, as the hibernateEncryptor could be directly set an --> - * <-- algorithm and password. --> - * <bean id="byteEncryptor" - * class="org.jasypt.encryption.pbe.StandardPBEByteEncryptor"> - * <property name="algorithm"> - * <value>PBEWithMD5AndDES</value> - * </property> - * <property name="password"> - * <value>XXXXX</value> - * </property> - * </bean> - * - * <bean id="hibernateEncryptor" - * class="org.jasypt.hibernate.encryptor.HibernatePBEByteEncryptor"> - * <property name="registeredName"> - * <value>myHibernateByteEncryptor</value> - * </property> - * <property name="encryptor"> - * <ref bean="byteEncryptor" /> - * </property> - * </bean> - * ... - *- * - *
- * And then in the Hibernate mapping file: - *
- *- *
- * <typedef name="encrypted" class="org.jasypt.hibernate.type.EncryptedBinaryType"> - * <param name="encryptorRegisteredName">myHibernateByteEncryptor</param> - * </typedef> - *- * - *
- * An important thing to note is that, when using HibernatePBEByteEncryptor - * objects this way to wrap PBEByteEncryptors, it is not - * necessary to deal with {@link HibernatePBEEncryptorRegistry}, - * because HibernatePBEByteEncryptor objects get automatically registered - * in the encryptor registry when their {@link #setRegisteredName(String)} - * method is called. - *
- * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class HibernatePBEByteEncryptor { - - private String registeredName = null; - private PBEByteEncryptor encryptor = null; - private boolean encryptorSet = false; - - - - /** - * Creates a new instance of HibernatePBEByteEncryptor It also - * creates a StandardPBEByteEncryptor for internal use, which - * can be overriden by calling setEncryptor(...). - */ - public HibernatePBEByteEncryptor() { - super(); - this.encryptor = new StandardPBEByteEncryptor(); - this.encryptorSet = false; - } - - - /* - * For internal use only, by the Registry, when a PBEByteEncryptor - * is registered programmatically. - */ - HibernatePBEByteEncryptor(final String registeredName, - final PBEByteEncryptor encryptor) { - this.encryptor = encryptor; - this.registeredName = registeredName; - this.encryptorSet = true; - } - - - /** - * Returns the encryptor which this object wraps. - * - * @return the encryptor. - */ - public PBEByteEncryptor getEncryptor() { - return this.encryptor; - } - - - /** - * Sets the PBEByteEncryptor to be held (wrapped) by this - * object. This method is optional and can be only called once. - * - * @param encryptor the encryptor. - */ - public void setEncryptor(final PBEByteEncryptor encryptor) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - this.encryptor = encryptor; - this.encryptorSet = true; - } - - - /** - * Sets the password to be used by the internal encryptor, if a specific - * encryptor has not been set with setEncryptor(...). - * - * @param password the password to be set for the internal encryptor - */ - public void setPassword(final String password) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEByteEncryptor standardPBEByteEncryptor = - (StandardPBEByteEncryptor) this.encryptor; - standardPBEByteEncryptor.setPassword(password); - } - - - /** - * Sets the password to be used by the internal encryptor (as a char[]), if a specific - * encryptor has not been set with setEncryptor(...). - * - * @since 1.8 - * @param password the password to be set for the internal encryptor - */ - public void setPasswordCharArray(final char[] password) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEByteEncryptor standardPBEByteEncryptor = - (StandardPBEByteEncryptor) this.encryptor; - standardPBEByteEncryptor.setPasswordCharArray(password); - } - - - /** - * Sets the algorithm to be used by the internal encryptor, if a specific - * encryptor has not been set with setEncryptor(...). - * - * @param algorithm the algorithm to be set for the internal encryptor - */ - public void setAlgorithm(final String algorithm) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEByteEncryptor standardPBEByteEncryptor = - (StandardPBEByteEncryptor) this.encryptor; - standardPBEByteEncryptor.setAlgorithm(algorithm); - } - - - /** - * Sets the key obtention iterations to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param keyObtentionIterations to be set for the internal encryptor - */ - public void setKeyObtentionIterations(final int keyObtentionIterations) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEByteEncryptor standardPBEByteEncryptor = - (StandardPBEByteEncryptor) this.encryptor; - standardPBEByteEncryptor.setKeyObtentionIterations( - keyObtentionIterations); - } - - - /** - * Sets the salt generator to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param saltGenerator the salt generator to be set for the internal - * encryptor. - */ - public void setSaltGenerator(final SaltGenerator saltGenerator) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEByteEncryptor standardPBEByteEncryptor = - (StandardPBEByteEncryptor) this.encryptor; - standardPBEByteEncryptor.setSaltGenerator(saltGenerator); - } - - - /** - * Sets the PBEConfig to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param config the PBEConfig to be set for the internal encryptor - */ - public void setConfig(final PBEConfig config) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEByteEncryptor standardPBEByteEncryptor = - (StandardPBEByteEncryptor) this.encryptor; - standardPBEByteEncryptor.setConfig(config); - } - - - /** - * Encrypts a message, delegating to wrapped encryptor. - * - * @param message the message to be encrypted. - * @return the encryption result. - */ - public byte[] encrypt(final byte[] message) { - if (this.encryptor == null) { - throw new EncryptionInitializationException( - "Encryptor has not been set into Hibernate wrapper"); - } - return this.encryptor.encrypt(message); - } - - - /** - * Decypts a message, delegating to wrapped encryptor - * - * @param encryptedMessage the message to be decrypted. - * @return the result of decryption. - */ - public byte[] decrypt(final byte[] encryptedMessage) { - if (this.encryptor == null) { - throw new EncryptionInitializationException( - "Encryptor has not been set into Hibernate wrapper"); - } - return this.encryptor.decrypt(encryptedMessage); - } - - - - /** - * Sets the registered name of the encryptor and adds it to the registry. - * - * @param registeredName the name with which the encryptor will be - * registered. - */ - public void setRegisteredName(final String registeredName) { - if (this.registeredName != null) { - // It had another name before, we have to clean - HibernatePBEEncryptorRegistry.getInstance(). - unregisterHibernatePBEByteEncryptor(this.registeredName); - } - this.registeredName = registeredName; - HibernatePBEEncryptorRegistry.getInstance(). - registerHibernatePBEByteEncryptor(this); - } - - /** - * Returns the name with which the wrapped encryptor is registered at - * the registry. - * - * @return the registered name. - */ - public String getRegisteredName() { - return this.registeredName; - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEEncryptorRegistry.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEEncryptorRegistry.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEEncryptorRegistry.java 2010-10-16 18:38:01.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEEncryptorRegistry.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,341 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.encryptor; - -import java.util.HashMap; - -import org.jasypt.encryption.pbe.PBEBigDecimalEncryptor; -import org.jasypt.encryption.pbe.PBEBigIntegerEncryptor; -import org.jasypt.encryption.pbe.PBEByteEncryptor; -import org.jasypt.encryption.pbe.PBEStringEncryptor; - -/** - *- * Registry for all the PBE*Encryptor which are eligible for - * use from Hibernate. - *
- *- * This class is intended to be directly used in applications where - * an IoC container (like Spring Framework) is not present. If it is, - * it is better to use the HibernatePBE*Encryptor classes - * directly, instead. - *
- *- * This registry is a singleton which maintains a registry - * of PBE*Encryptor objects which can be used from Hibernate, - * by using its registeredName to reference them from mappings. - *
- *- * The steps would be: - *
- * This is, first register the encryptor (example with a String encryptor): - *
- *- *
- * StandardPBEStringEncryptor myEncryptor = new StandardPBEStringEncryptor(); - * ... - * HibernatePBEEncryptorRegistry registry = - * HibernatePBEEncryptorRegistry.getInstance(); - * registry.registerPBEStringEncryptor("myHibernateEncryptor", myEncryptor); - *- * - *
- * And then, reference it from a Hibernate mapping file: - *
- *- *
- * <typedef name="encryptedString" class="org.jasypt.hibernate.type.EncryptedStringType"> - * <param name="encryptorRegisteredName">myHibernateEncryptor</param> - * </typedef> - *- * - * - * - * @since 1.2 (class existed as - * org.jasypt.hibernate.HibernatePBEEncryptorRegistry since 1.0) - * - * @author Daniel Fernández - * - */ -public final class HibernatePBEEncryptorRegistry { - - - // The singleton instance - private static final HibernatePBEEncryptorRegistry instance = - new HibernatePBEEncryptorRegistry(); - - - // Registry maps - private final HashMap stringEncryptors = new HashMap(); - private final HashMap bigIntegerEncryptors = new HashMap(); - private final HashMap bigDecimalEncryptors = new HashMap(); - private final HashMap byteEncryptors = new HashMap(); - - - /** - * Returns the singleton instance of the registry. - * - * @return the registry. - */ - public static HibernatePBEEncryptorRegistry getInstance() { - return instance; - } - - // The registry cannot be externally instantiated. - private HibernatePBEEncryptorRegistry() { - super(); - } - - - /** - * Registers a PBEStringEncryptor object with the specified - * name. - * - * @param registeredName the registered name. - * @param encryptor the encryptor to be registered. - */ - public synchronized void registerPBEStringEncryptor( - final String registeredName, final PBEStringEncryptor encryptor) { - final HibernatePBEStringEncryptor hibernateEncryptor = - new HibernatePBEStringEncryptor(registeredName, encryptor); - this.stringEncryptors.put(registeredName, hibernateEncryptor); - } - - - - // Not public: this is used from - // HibernatePBEStringEncryptor.setRegisteredName. - synchronized void registerHibernatePBEStringEncryptor( - final HibernatePBEStringEncryptor hibernateEncryptor) { - this.stringEncryptors.put( - hibernateEncryptor.getRegisteredName(), - hibernateEncryptor); - } - - - // Not public: this is used from - // HibernatePBEStringEncryptor.setRegisteredName. - synchronized void unregisterHibernatePBEStringEncryptor(final String name) { - this.stringEncryptors.remove(name); - } - - - /** - * Returns the PBEStringEncryptor registered with the specified - * name (if exists). - * - * @param registeredName the name with which the desired encryptor was - * registered. - * @return the encryptor, or null if no encryptor has been registered with - * that name. - */ - public synchronized PBEStringEncryptor getPBEStringEncryptor( - final String registeredName) { - final HibernatePBEStringEncryptor hibernateEncryptor = - (HibernatePBEStringEncryptor) this.stringEncryptors.get(registeredName); - if (hibernateEncryptor == null) { - return null; - } - return hibernateEncryptor.getEncryptor(); - } - - - - - /** - * Registers a PBEBigIntegerEncryptor object with the specified - * name. - * - * @since 1.6 - * - * @param registeredName the registered name. - * @param encryptor the encryptor to be registered. - */ - public synchronized void registerPBEBigIntegerEncryptor( - final String registeredName, final PBEBigIntegerEncryptor encryptor) { - final HibernatePBEBigIntegerEncryptor hibernateEncryptor = - new HibernatePBEBigIntegerEncryptor(registeredName, encryptor); - this.bigIntegerEncryptors.put(registeredName, hibernateEncryptor); - } - - - - // Not public: this is used from - // HibernatePBEBigIntegerEncryptor.setRegisteredName. - synchronized void registerHibernatePBEBigIntegerEncryptor( - final HibernatePBEBigIntegerEncryptor hibernateEncryptor) { - this.bigIntegerEncryptors.put( - hibernateEncryptor.getRegisteredName(), - hibernateEncryptor); - } - - - // Not public: this is used from - // HibernatePBEBigIntegerEncryptor.setRegisteredName. - synchronized void unregisterHibernatePBEBigIntegerEncryptor(final String name) { - this.bigIntegerEncryptors.remove(name); - } - - - /** - * Returns the PBEBigIntegerEncryptor registered with the specified - * name (if exists). - * - * @param registeredName the name with which the desired encryptor was - * registered. - * @return the encryptor, or null if no encryptor has been registered with - * that name. - */ - public synchronized PBEBigIntegerEncryptor getPBEBigIntegerEncryptor( - final String registeredName) { - final HibernatePBEBigIntegerEncryptor hibernateEncryptor = - (HibernatePBEBigIntegerEncryptor) this.bigIntegerEncryptors.get(registeredName); - if (hibernateEncryptor == null) { - return null; - } - return hibernateEncryptor.getEncryptor(); - } - - - - /** - * Registers a PBEBigDecimalEncryptor object with the specified - * name. - * - * @since 1.6 - * - * @param registeredName the registered name. - * @param encryptor the encryptor to be registered. - */ - public synchronized void registerPBEBigDecimalEncryptor( - final String registeredName, final PBEBigDecimalEncryptor encryptor) { - final HibernatePBEBigDecimalEncryptor hibernateEncryptor = - new HibernatePBEBigDecimalEncryptor(registeredName, encryptor); - this.bigDecimalEncryptors.put(registeredName, hibernateEncryptor); - } - - - - // Not public: this is used from - // HibernatePBEBigDecimalEncryptor.setRegisteredName. - synchronized void registerHibernatePBEBigDecimalEncryptor( - final HibernatePBEBigDecimalEncryptor hibernateEncryptor) { - this.bigDecimalEncryptors.put( - hibernateEncryptor.getRegisteredName(), - hibernateEncryptor); - } - - - // Not public: this is used from - // HibernatePBEBigDecimalEncryptor.setRegisteredName. - synchronized void unregisterHibernatePBEBigDecimalEncryptor(final String name) { - this.bigDecimalEncryptors.remove(name); - } - - - /** - * Returns the PBEBigDecimalEncryptor registered with the specified - * name (if exists). - * - * @param registeredName the name with which the desired encryptor was - * registered. - * @return the encryptor, or null if no encryptor has been registered with - * that name. - */ - public synchronized PBEBigDecimalEncryptor getPBEBigDecimalEncryptor( - final String registeredName) { - final HibernatePBEBigDecimalEncryptor hibernateEncryptor = - (HibernatePBEBigDecimalEncryptor) this.bigDecimalEncryptors.get(registeredName); - if (hibernateEncryptor == null) { - return null; - } - return hibernateEncryptor.getEncryptor(); - } - - - - - - /** - * Registers a PBEByteEncryptor object with the specified - * name. - * - * @since 1.6 - * - * @param registeredName the registered name. - * @param encryptor the encryptor to be registered. - */ - public synchronized void registerPBEByteEncryptor( - final String registeredName, final PBEByteEncryptor encryptor) { - final HibernatePBEByteEncryptor hibernateEncryptor = - new HibernatePBEByteEncryptor(registeredName, encryptor); - this.byteEncryptors.put(registeredName, hibernateEncryptor); - } - - - - - - // Not public: this is used from - // HibernatePBEByteEncryptor.setRegisteredName. - synchronized void registerHibernatePBEByteEncryptor( - final HibernatePBEByteEncryptor hibernateEncryptor) { - this.byteEncryptors.put( - hibernateEncryptor.getRegisteredName(), - hibernateEncryptor); - } - - - // Not public: this is used from - // HibernatePBEByteEncryptor.setRegisteredName. - synchronized void unregisterHibernatePBEByteEncryptor(final String name) { - this.byteEncryptors.remove(name); - } - - - /** - * Returns the PBEByteEncryptor registered with the specified - * name (if exists). - * - * @param registeredName the name with which the desired encryptor was - * registered. - * @return the encryptor, or null if no encryptor has been registered with - * that name. - */ - public synchronized PBEByteEncryptor getPBEByteEncryptor( - final String registeredName) { - final HibernatePBEByteEncryptor hibernateEncryptor = - (HibernatePBEByteEncryptor) this.byteEncryptors.get(registeredName); - if (hibernateEncryptor == null) { - return null; - } - return hibernateEncryptor.getEncryptor(); - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEStringEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEStringEncryptor.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEStringEncryptor.java 2011-07-25 12:47:47.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/encryptor/HibernatePBEStringEncryptor.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,412 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.encryptor; - -import java.security.Provider; - -import org.jasypt.encryption.pbe.PBEStringEncryptor; -import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; -import org.jasypt.encryption.pbe.config.PBEConfig; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.salt.SaltGenerator; - -/** - *
- * Placeholder class for PBEStringEncryptor objects which are - * eligible for use from Hibernate. - *
- *- * This class acts as a wrapper on a PBEStringEncryptor, allowing - * to be set a registered name (see {@link #setRegisteredName(String)}) - * and performing the needed registry operations against the - * {@link HibernatePBEEncryptorRegistry}. - *
- *- * It is not mandatory that a PBEStringEncryptor be explicitly set - * with {@link #setEncryptor(PBEStringEncryptor)}. If not, a - * StandardPBEStringEncryptor object will be created internally - * and it will be configurable with the - * {@link #setPassword(String)}/{@link #setPasswordCharArray(char[])}, - * {@link #setAlgorithm(String)}, {@link #setKeyObtentionIterations(int)}, - * {@link #setSaltGenerator(SaltGenerator)}, {@link #setProviderName(String)}, - * {@link #setProvider(Provider)}, {@link #setStringOutputType(String)} - * and {@link #setConfig(PBEConfig)} methods. - *
- *- * This class is mainly intended for use from Spring Framework or some other - * IoC container (if you are not using a container of this kind, please see - * {@link HibernatePBEEncryptorRegistry}). The steps to be performed are - * the following: - *
- * This in a Spring config file would look like: - *
- *- *
- * ... - * <-- Optional, as the hibernateEncryptor could be directly set an --> - * <-- algorithm and password. --> - * <bean id="stringEncryptor" - * class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor"> - * <property name="algorithm"> - * <value>PBEWithMD5AndDES</value> - * </property> - * <property name="password"> - * <value>XXXXX</value> - * </property> - * </bean> - * - * <bean id="hibernateEncryptor" - * class="org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor"> - * <property name="registeredName"> - * <value>myHibernateStringEncryptor</value> - * </property> - * <property name="encryptor"> - * <ref bean="stringEncryptor" /> - * </property> - * </bean> - * ... - *- * - *
- * And then in the Hibernate mapping file: - *
- *- *
- * <typedef name="encrypted" class="org.jasypt.hibernate.type.EncryptedStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - *- * - *
- * An important thing to note is that, when using HibernatePBEStringEncryptor - * objects this way to wrap PBEStringEncryptors, it is not - * necessary to deal with {@link HibernatePBEEncryptorRegistry}, - * because HibernatePBEStringEncryptor objects get automatically registered - * in the encryptor registry when their {@link #setRegisteredName(String)} - * method is called. - *
- * - * @since 1.2 (substitutes org.jasypt.hibernate.HibernatePBEEncryptor which - * existed since 1.0) - * - * @author Daniel Fernández - * - */ -public final class HibernatePBEStringEncryptor { - - private String registeredName = null; - private PBEStringEncryptor encryptor = null; - private boolean encryptorSet = false; - - - - /** - * Creates a new instance of HibernatePBEStringEncryptor. It also - * creates a StandardPBEStringEncryptor for internal use, which - * can be overriden by calling setEncryptor(...). - */ - public HibernatePBEStringEncryptor() { - super(); - this.encryptor = new StandardPBEStringEncryptor(); - this.encryptorSet = false; - } - - - /* - * For internal use only, by the Registry, when a PBEStringEncryptor - * is registered programmatically. - */ - HibernatePBEStringEncryptor(final String registeredName, - final PBEStringEncryptor encryptor) { - this.encryptor = encryptor; - this.registeredName = registeredName; - this.encryptorSet = true; - } - - - /** - * Returns the encryptor which this object wraps. - * - * @return the encryptor. - */ - public synchronized PBEStringEncryptor getEncryptor() { - return this.encryptor; - } - - - /** - * Sets the PBEStringEncryptor to be held (wrapped) by this - * object. This method is optional and can be only called once. - * - * @param encryptor the encryptor. - */ - public synchronized void setEncryptor(final PBEStringEncryptor encryptor) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - this.encryptor = encryptor; - this.encryptorSet = true; - } - - - /** - * Sets the password to be used by the internal encryptor, if a specific - * encryptor has not been set with setEncryptor(...). - * - * @param password the password to be set for the internal encryptor - */ - public void setPassword(final String password) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setPassword(password); - } - - - /** - * Sets the password to be used by the internal encryptor (as a char[]), if a specific - * encryptor has not been set with setEncryptor(...). - * - * @since 1.8 - * @param password the password to be set for the internal encryptor - */ - public void setPasswordCharArray(final char[] password) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setPasswordCharArray(password); - } - - - /** - * Sets the algorithm to be used by the internal encryptor, if a specific - * encryptor has not been set with setEncryptor(...). - * - * @param algorithm the algorithm to be set for the internal encryptor - */ - public void setAlgorithm(final String algorithm) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setAlgorithm(algorithm); - } - - - /** - * Sets the key obtention iterations to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param keyObtentionIterations to be set for the internal encryptor - */ - public void setKeyObtentionIterations(final int keyObtentionIterations) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setKeyObtentionIterations( - keyObtentionIterations); - } - - - /** - * Sets the salt generator to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param saltGenerator the salt generator to be set for the internal - * encryptor. - */ - public void setSaltGenerator(final SaltGenerator saltGenerator) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setSaltGenerator(saltGenerator); - } - - - /** - * Sets the name of the JCE provider to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @since 1.3 - * - * @param providerName the name of the JCE provider (already registered) - */ - public void setProviderName(final String providerName) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setProviderName(providerName); - } - - - /** - * Sets the JCE provider to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @since 1.3 - * - * @param provider the JCE provider to be used - */ - public void setProvider(final Provider provider) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setProvider(provider); - } - - - /** - * Sets the type of String output ("base64" (default), "hexadecimal") to - * be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @since 1.3 - * - * @param stringOutputType the type of String output - */ - public void setStringOutputType(final String stringOutputType) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setStringOutputType(stringOutputType); - } - - - /** - * Sets the PBEConfig to be used by the internal encryptor, - * if a specific encryptor has not been set with setEncryptor(...). - * - * @param config the PBEConfig to be set for the internal encryptor - */ - public void setConfig(final PBEConfig config) { - if (this.encryptorSet) { - throw new EncryptionInitializationException( - "An encryptor has been already set: no " + - "further configuration possible on hibernate wrapper"); - } - final StandardPBEStringEncryptor standardPBEStringEncryptor = - (StandardPBEStringEncryptor) this.encryptor; - standardPBEStringEncryptor.setConfig(config); - } - - - /** - * Encrypts a message, delegating to wrapped encryptor. - * - * @param message the message to be encrypted. - * @return the encryption result. - */ - public String encrypt(final String message) { - if (this.encryptor == null) { - throw new EncryptionInitializationException( - "Encryptor has not been set into Hibernate wrapper"); - } - return this.encryptor.encrypt(message); - } - - - /** - * Decypts a message, delegating to wrapped encryptor - * - * @param encryptedMessage the message to be decrypted. - * @return the result of decryption. - */ - public String decrypt(final String encryptedMessage) { - if (this.encryptor == null) { - throw new EncryptionInitializationException( - "Encryptor has not been set into Hibernate wrapper"); - } - return this.encryptor.decrypt(encryptedMessage); - } - - - - /** - * Sets the registered name of the encryptor and adds it to the registry. - * - * @param registeredName the name with which the encryptor will be - * registered. - */ - public void setRegisteredName(final String registeredName) { - if (this.registeredName != null) { - // It had another name before, we have to clean - HibernatePBEEncryptorRegistry.getInstance(). - unregisterHibernatePBEStringEncryptor(this.registeredName); - } - this.registeredName = registeredName; - HibernatePBEEncryptorRegistry.getInstance(). - registerHibernatePBEStringEncryptor(this); - } - - /** - * Returns the name with which the wrapped encryptor is registered at - * the registry. - * - * @return the registered name. - */ - public String getRegisteredName() { - return this.registeredName; - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/AbstractEncryptedAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/AbstractEncryptedAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/AbstractEncryptedAsStringType.java 2010-10-23 12:24:29.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/AbstractEncryptedAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,289 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Properties; - -import org.hibernate.HibernateException; -import org.hibernate.usertype.ParameterizedType; -import org.hibernate.usertype.UserType; -import org.hibernate.util.EqualsHelper; -import org.jasypt.encryption.pbe.PBEStringEncryptor; -import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; - -/** - * - * Base class for Hibernate 3 UserTypes to store - * values as encrypted strings. - * - * @since 1.2 - * @author Daniel Fernández - * @author Iván García Sáinz-Aja - * - */ -public abstract class AbstractEncryptedAsStringType - implements UserType, ParameterizedType { - - static final int sqlType = Types.VARCHAR; - static final int[] sqlTypes = new int[]{ sqlType }; - - private boolean initialized = false; - private boolean useEncryptorName = false; - - private String encryptorName = null; - private String algorithm = null; - private String providerName = null; - private String password = null; - private Integer keyObtentionIterations = null; - private String stringOutputType = null; - - protected PBEStringEncryptor encryptor = null; - - /** - * Converts given String to its Object form. - * @param string the string value - * @return the object form of the passed String - */ - protected abstract Object convertToObject(final String string); - - /** - * Converts given Object to its String form. - * @param object the object value - * @return the string form of the passes Object - */ - protected String convertToString(final Object object) { - return object == null? null : object.toString(); - } - - public final int[] sqlTypes() { - return (int[]) sqlTypes.clone(); - } - - - public abstract Class returnedClass(); - - - public final boolean equals(final Object x, final Object y) - throws HibernateException { - return EqualsHelper.equals(x, y); - } - - - public final Object deepCopy(final Object value) - throws HibernateException { - return value; - } - - - public final Object assemble(final Serializable cached, final Object owner) - throws HibernateException { - if (cached == null) { - return null; - } - return deepCopy(cached); - } - - - public final Serializable disassemble(final Object value) - throws HibernateException { - if (value == null) { - return null; - } - return (Serializable) deepCopy(value); - } - - - public final boolean isMutable() { - return false; - } - - - public final int hashCode(final Object x) - throws HibernateException { - return x.hashCode(); - } - - - public final Object replace(final Object original, final Object target, final Object owner) - throws HibernateException { - return original; - } - - - public final Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) - throws HibernateException, SQLException { - checkInitialization(); - final String message = rs.getString(names[0]); - return rs.wasNull() ? null : convertToObject(this.encryptor.decrypt(message)); - } - - - public final void nullSafeSet(final PreparedStatement st, final Object value, final int index) - throws HibernateException, SQLException { - checkInitialization(); - if (value == null) { - st.setNull(index, sqlType); - } else { - st.setString(index, this.encryptor.encrypt(convertToString(value))); - } - } - - - public synchronized void setParameterValues(final Properties parameters) { - - final String paramEncryptorName = - parameters.getProperty(ParameterNaming.ENCRYPTOR_NAME); - final String paramAlgorithm = - parameters.getProperty(ParameterNaming.ALGORITHM); - final String paramProviderName = - parameters.getProperty(ParameterNaming.PROVIDER_NAME); - final String paramPassword = - parameters.getProperty(ParameterNaming.PASSWORD); - final String paramKeyObtentionIterations = - parameters.getProperty(ParameterNaming.KEY_OBTENTION_ITERATIONS); - final String paramStringOutputType = - parameters.getProperty(ParameterNaming.STRING_OUTPUT_TYPE); - - this.useEncryptorName = false; - if (paramEncryptorName != null) { - - if ((paramAlgorithm != null) || - (paramPassword != null) || - (paramKeyObtentionIterations != null)) { - - throw new EncryptionInitializationException( - "If \"" + ParameterNaming.ENCRYPTOR_NAME + - "\" is specified, none of \"" + - ParameterNaming.ALGORITHM + "\", \"" + - ParameterNaming.PASSWORD + "\" or \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + "\" " + - "can be specified"); - - } - this.encryptorName = paramEncryptorName; - this.useEncryptorName = true; - - } else if ((paramPassword != null)) { - - this.password = paramPassword; - - if (paramAlgorithm != null) { - this.algorithm = paramAlgorithm; - } - - if (paramProviderName != null) { - this.providerName = paramProviderName; - } - - if (paramKeyObtentionIterations != null) { - - try { - this.keyObtentionIterations = - new Integer( - Integer.parseInt(paramKeyObtentionIterations)); - } catch (NumberFormatException e) { - throw new EncryptionInitializationException( - "Value specified for \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + - "\" is not a valid integer"); - } - - } - - if (paramStringOutputType != null) { - this.stringOutputType = paramStringOutputType; - } - - } else { - - throw new EncryptionInitializationException( - "If \"" + ParameterNaming.ENCRYPTOR_NAME + - "\" is not specified, then \"" + - ParameterNaming.PASSWORD + "\" (and optionally \"" + - ParameterNaming.ALGORITHM + "\" and \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + "\") " + - "must be specified"); - - } - } - - - - protected synchronized final void checkInitialization() { - - if (!this.initialized) { - - if (this.useEncryptorName) { - - final HibernatePBEEncryptorRegistry registry = - HibernatePBEEncryptorRegistry.getInstance(); - final PBEStringEncryptor pbeEncryptor = - registry.getPBEStringEncryptor(this.encryptorName); - if (pbeEncryptor == null) { - throw new EncryptionInitializationException( - "No string encryptor registered for hibernate " + - "with name \"" + this.encryptorName + "\""); - } - this.encryptor = pbeEncryptor; - - } else { - - final StandardPBEStringEncryptor newEncryptor = - new StandardPBEStringEncryptor(); - - newEncryptor.setPassword(this.password); - - if (this.algorithm != null) { - newEncryptor.setAlgorithm(this.algorithm); - } - - if (this.providerName != null) { - newEncryptor.setProviderName(this.providerName); - } - - if (this.keyObtentionIterations != null) { - newEncryptor.setKeyObtentionIterations( - this.keyObtentionIterations.intValue()); - } - - if (this.stringOutputType != null) { - newEncryptor.setStringOutputType(this.stringOutputType); - } - - newEncryptor.initialize(); - - this.encryptor = newEncryptor; - - } - - this.initialized = true; - } - - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBigDecimalAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBigDecimalAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBigDecimalAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBigDecimalAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,115 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import java.math.BigDecimal; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of BigDecimal values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBigDecimalAsString" class="org.jasypt.hibernate.type.EncryptedBigDecimalAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedBigDecimalAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBigDecimalAsString" class="org.jasypt.hibernate.type.EncryptedBigDecimalAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedBigDecimalAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedBigDecimalAsStringType extends AbstractEncryptedAsStringType{ - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return new BigDecimal(string); - } - - public Class returnedClass() { - return BigDecimal.class; - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBigDecimalType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBigDecimalType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBigDecimalType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBigDecimalType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,376 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Properties; - -import org.hibernate.HibernateException; -import org.hibernate.usertype.ParameterizedType; -import org.hibernate.usertype.UserType; -import org.hibernate.util.EqualsHelper; -import org.jasypt.encryption.pbe.PBEBigDecimalEncryptor; -import org.jasypt.encryption.pbe.StandardPBEBigDecimalEncryptor; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.hibernate.encryptor.HibernatePBEBigDecimalEncryptor; -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; - -/** - *- * A Hibernate 3 UserType implementation which allows transparent - * encryption of BigDecimal values during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBigDecimal" class="org.jasypt.hibernate.type.EncryptedBigDecimalType"> - * <param name="encryptorRegisteredName">myHibernateBigDecimalEncryptor</param> - * <param name="decimalScale">2</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedBigDecimal" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEBigDecimalEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateBigDecimalEncryptor (see - * {@link HibernatePBEBigDecimalEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBigDecimal" class="org.jasypt.hibernate.type.EncryptedBigDecimalType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * <param name="decimalScale">2</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="address" column="ADDRESS" type="encryptedBigDecimal" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- *
- * About the decimalScale parameter - *- * The decimalScale parameter is aimed at setting the scale with which - * BigDecimal numbers will be set to and retrieved from the database. It is - * an important parameter because many DBMSs return BigDecimal numbers with - * a scale equal to the amount of decimal positions declared for the field - * (e.g. if we store "18.23" (scale=2) in a DECIMAL(15,5) field, we can get a - * "18.23000" (scale=5) back when we retrieve the number). This can affect - * correct decryption of encrypted numbers, but specifying a - * decimalScale parameter will solve this issue. - *
- *- * So, if we set decimalScale to 3, and we store "18.23", this - * Hibernate type will send "18.230" to the encryptor, which is the value that - * we will get back from the database at retrieval time (a scale of "3" - * will be set again on the value obtained from DB). If it is necessary, a - * DOWN rounding operation is executed on the number. - *
- *- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedBigDecimalType implements UserType, ParameterizedType { - - private static final int sqlType = Types.NUMERIC; - private static final int[] sqlTypes = new int[]{ sqlType }; - - private boolean initialized = false; - private boolean useEncryptorName = false; - - private String encryptorName = null; - private String algorithm = null; - private String password = null; - private Integer keyObtentionIterations = null; - private Integer decimalScale = null; - - private PBEBigDecimalEncryptor encryptor = null; - - - public int[] sqlTypes() { - return (int[]) sqlTypes.clone(); - } - - - public Class returnedClass() { - return BigDecimal.class; - } - - - public boolean equals(final Object x, final Object y) - throws HibernateException { - return EqualsHelper.equals(x, y); - } - - - public Object deepCopy(final Object value) - throws HibernateException { - return value; - } - - - public Object assemble(final Serializable cached, final Object owner) - throws HibernateException { - if (cached == null) { - return null; - } - return deepCopy(cached); - } - - - public Serializable disassemble(final Object value) - throws HibernateException { - if (value == null) { - return null; - } - return (Serializable) deepCopy(value); - } - - - public boolean isMutable() { - return false; - } - - - public int hashCode(final Object x) - throws HibernateException { - return x.hashCode(); - } - - - public Object replace(final Object original, final Object target, final Object owner) - throws HibernateException { - return original; - } - - - public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) - throws HibernateException, SQLException { - checkInitialization(); - final BigDecimal storedEncryptedMessage = rs.getBigDecimal(names[0]); - if (rs.wasNull()) { - return null; - } - final BigDecimal scaledEncryptedMessage = - storedEncryptedMessage.setScale( - this.decimalScale.intValue(), BigDecimal.ROUND_UNNECESSARY); - return this.encryptor.decrypt(scaledEncryptedMessage); - } - - - public void nullSafeSet(final PreparedStatement st, final Object value, final int index) - throws HibernateException, SQLException { - checkInitialization(); - if (value == null) { - st.setNull(index, sqlType); - } else { - final BigDecimal scaledValue = - ((BigDecimal) value).setScale( - this.decimalScale.intValue(), BigDecimal.ROUND_DOWN); - final BigDecimal encryptedMessage = - this.encryptor.encrypt(scaledValue); - st.setBigDecimal(index, encryptedMessage); - } - } - - - public synchronized void setParameterValues(final Properties parameters) { - - final String paramEncryptorName = - parameters.getProperty(ParameterNaming.ENCRYPTOR_NAME); - final String paramAlgorithm = - parameters.getProperty(ParameterNaming.ALGORITHM); - final String paramPassword = - parameters.getProperty(ParameterNaming.PASSWORD); - final String paramKeyObtentionIterations = - parameters.getProperty(ParameterNaming.KEY_OBTENTION_ITERATIONS); - final String paramDecimalScale = - parameters.getProperty(ParameterNaming.DECIMAL_SCALE); - - this.useEncryptorName = false; - if (paramEncryptorName != null) { - - if ((paramAlgorithm != null) || - (paramPassword != null) || - (paramKeyObtentionIterations != null)) { - - throw new EncryptionInitializationException( - "If \"" + ParameterNaming.ENCRYPTOR_NAME + - "\" is specified, none of \"" + - ParameterNaming.ALGORITHM + "\", \"" + - ParameterNaming.PASSWORD + "\" or \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + "\" " + - "can be specified"); - - } - this.encryptorName = paramEncryptorName; - this.useEncryptorName = true; - - } else if ((paramPassword != null)) { - - this.password = paramPassword; - - if (paramAlgorithm != null) { - this.algorithm = paramAlgorithm; - } - - if (paramKeyObtentionIterations != null) { - - try { - this.keyObtentionIterations = - new Integer( - Integer.parseInt(paramKeyObtentionIterations)); - } catch (NumberFormatException e) { - throw new EncryptionInitializationException( - "Value specified for \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + - "\" is not a valid integer"); - } - - } - - } else { - - throw new EncryptionInitializationException( - "If \"" + ParameterNaming.ENCRYPTOR_NAME + - "\" is not specified, then \"" + - ParameterNaming.PASSWORD + "\" (and optionally \"" + - ParameterNaming.ALGORITHM + "\" and \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + "\") " + - "must be specified"); - - } - - if (paramDecimalScale != null) { - - try { - this.decimalScale = - new Integer(Integer.parseInt(paramDecimalScale)); - } catch (NumberFormatException e) { - throw new EncryptionInitializationException( - "Value specified for \"" + - ParameterNaming.DECIMAL_SCALE + - "\" is not a valid integer"); - } - - } else { - - throw new EncryptionInitializationException( - ParameterNaming.DECIMAL_SCALE + - " must be specified"); - - } - - } - - - - private synchronized void checkInitialization() { - - if (!this.initialized) { - - if (this.useEncryptorName) { - - final HibernatePBEEncryptorRegistry registry = - HibernatePBEEncryptorRegistry.getInstance(); - final PBEBigDecimalEncryptor pbeEncryptor = - registry.getPBEBigDecimalEncryptor(this.encryptorName); - if (pbeEncryptor == null) { - throw new EncryptionInitializationException( - "No big decimal encryptor registered for hibernate " + - "with name \"" + this.encryptorName + "\""); - } - this.encryptor = pbeEncryptor; - - } else { - - final StandardPBEBigDecimalEncryptor newEncryptor = - new StandardPBEBigDecimalEncryptor(); - - newEncryptor.setPassword(this.password); - - if (this.algorithm != null) { - newEncryptor.setAlgorithm(this.algorithm); - } - - if (this.keyObtentionIterations != null) { - newEncryptor.setKeyObtentionIterations( - this.keyObtentionIterations.intValue()); - } - - newEncryptor.initialize(); - - this.encryptor = newEncryptor; - - } - - this.initialized = true; - } - - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBigIntegerAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBigIntegerAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBigIntegerAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBigIntegerAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,115 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import java.math.BigInteger; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of BigInteger values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBigIntegerAsString" class="org.jasypt.hibernate.type.EncryptedBigIntegerAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedBigIntegerAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBigIntegerAsString" class="org.jasypt.hibernate.type.EncryptedBigIntegerAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedBigIntegerAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedBigIntegerAsStringType extends AbstractEncryptedAsStringType{ - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return new BigInteger(string); - } - - public Class returnedClass() { - return BigInteger.class; - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBigIntegerType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBigIntegerType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBigIntegerType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBigIntegerType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,327 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Properties; - -import org.hibernate.HibernateException; -import org.hibernate.usertype.ParameterizedType; -import org.hibernate.usertype.UserType; -import org.hibernate.util.EqualsHelper; -import org.jasypt.encryption.pbe.PBEBigIntegerEncryptor; -import org.jasypt.encryption.pbe.StandardPBEBigIntegerEncryptor; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.hibernate.encryptor.HibernatePBEBigIntegerEncryptor; -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; - -/** - *- * A Hibernate 3 UserType implementation which allows transparent - * encryption of BigInteger values during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBigInteger" class="org.jasypt.hibernate.type.EncryptedBigIntegerType"> - * <param name="encryptorRegisteredName">myHibernateBigIntegerEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedBigInteger" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEBigIntegerEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateBigIntegerEncryptor (see - * {@link HibernatePBEBigIntegerEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBigInteger" class="org.jasypt.hibernate.type.EncryptedBigIntegerType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="address" column="ADDRESS" type="encryptedBigInteger" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedBigIntegerType implements UserType, ParameterizedType { - - private static int sqlType = Types.NUMERIC; - private static int[] sqlTypes = new int[]{ sqlType }; - - private boolean initialized = false; - private boolean useEncryptorName = false; - - private String encryptorName = null; - private String algorithm = null; - private String password = null; - private Integer keyObtentionIterations = null; - - private PBEBigIntegerEncryptor encryptor = null; - - - public int[] sqlTypes() { - return (int[]) sqlTypes.clone(); - } - - - public Class returnedClass() { - return BigInteger.class; - } - - - public boolean equals(final Object x, final Object y) - throws HibernateException { - return EqualsHelper.equals(x, y); - } - - - public Object deepCopy(final Object value) - throws HibernateException { - return value; - } - - - public Object assemble(final Serializable cached, final Object owner) - throws HibernateException { - if (cached == null) { - return null; - } - return deepCopy(cached); - } - - - public Serializable disassemble(final Object value) - throws HibernateException { - if (value == null) { - return null; - } - return (Serializable) deepCopy(value); - } - - - public boolean isMutable() { - return false; - } - - - public int hashCode(final Object x) - throws HibernateException { - return x.hashCode(); - } - - - public Object replace(final Object original, final Object target, final Object owner) - throws HibernateException { - return original; - } - - - public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) - throws HibernateException, SQLException { - checkInitialization(); - final BigDecimal decimalMessage = rs.getBigDecimal(names[0]); - if (rs.wasNull()) { - return null; - } - final BigInteger message = - decimalMessage.setScale(0, BigDecimal.ROUND_UNNECESSARY). - unscaledValue(); - return this.encryptor.decrypt(message); - } - - - public void nullSafeSet(final PreparedStatement st, final Object value, final int index) - throws HibernateException, SQLException { - checkInitialization(); - if (value == null) { - st.setNull(index, sqlType); - } else { - final BigInteger encryptedMessage = - this.encryptor.encrypt((BigInteger) value); - st.setBigDecimal(index, new BigDecimal(encryptedMessage)); - } - } - - - public synchronized void setParameterValues(final Properties parameters) { - - final String paramEncryptorName = - parameters.getProperty(ParameterNaming.ENCRYPTOR_NAME); - final String paramAlgorithm = - parameters.getProperty(ParameterNaming.ALGORITHM); - final String paramPassword = - parameters.getProperty(ParameterNaming.PASSWORD); - final String paramKeyObtentionIterations = - parameters.getProperty(ParameterNaming.KEY_OBTENTION_ITERATIONS); - - this.useEncryptorName = false; - if (paramEncryptorName != null) { - - if ((paramAlgorithm != null) || - (paramPassword != null) || - (paramKeyObtentionIterations != null)) { - - throw new EncryptionInitializationException( - "If \"" + ParameterNaming.ENCRYPTOR_NAME + - "\" is specified, none of \"" + - ParameterNaming.ALGORITHM + "\", \"" + - ParameterNaming.PASSWORD + "\" or \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + "\" " + - "can be specified"); - - } - this.encryptorName = paramEncryptorName; - this.useEncryptorName = true; - - } else if ((paramPassword != null)) { - - this.password = paramPassword; - - if (paramAlgorithm != null) { - this.algorithm = paramAlgorithm; - } - - if (paramKeyObtentionIterations != null) { - - try { - this.keyObtentionIterations = - new Integer( - Integer.parseInt(paramKeyObtentionIterations)); - } catch (NumberFormatException e) { - throw new EncryptionInitializationException( - "Value specified for \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + - "\" is not a valid integer"); - } - - } - - } else { - - throw new EncryptionInitializationException( - "If \"" + ParameterNaming.ENCRYPTOR_NAME + - "\" is not specified, then \"" + - ParameterNaming.PASSWORD + "\" (and optionally \"" + - ParameterNaming.ALGORITHM + "\" and \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + "\") " + - "must be specified"); - - } - } - - - - private synchronized void checkInitialization() { - - if (!this.initialized) { - - if (this.useEncryptorName) { - - final HibernatePBEEncryptorRegistry registry = - HibernatePBEEncryptorRegistry.getInstance(); - final PBEBigIntegerEncryptor pbeEncryptor = - registry.getPBEBigIntegerEncryptor(this.encryptorName); - if (pbeEncryptor == null) { - throw new EncryptionInitializationException( - "No big integer encryptor registered for hibernate " + - "with name \"" + this.encryptorName + "\""); - } - this.encryptor = pbeEncryptor; - - } else { - - final StandardPBEBigIntegerEncryptor newEncryptor = - new StandardPBEBigIntegerEncryptor(); - - newEncryptor.setPassword(this.password); - - if (this.algorithm != null) { - newEncryptor.setAlgorithm(this.algorithm); - } - - if (this.keyObtentionIterations != null) { - newEncryptor.setKeyObtentionIterations( - this.keyObtentionIterations.intValue()); - } - - newEncryptor.initialize(); - - this.encryptor = newEncryptor; - - } - - this.initialized = true; - } - - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBinaryType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBinaryType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBinaryType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBinaryType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,400 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Properties; - -import org.hibernate.HibernateException; -import org.hibernate.cfg.Environment; -import org.hibernate.usertype.ParameterizedType; -import org.hibernate.usertype.UserType; -import org.jasypt.encryption.pbe.PBEByteEncryptor; -import org.jasypt.encryption.pbe.StandardPBEByteEncryptor; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.hibernate.encryptor.HibernatePBEByteEncryptor; -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; - -/** - *- * A Hibernate 3 UserType implementation which allows transparent - * encryption of byte[] values during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBinary" class="org.jasypt.hibernate.type.EncryptedBinaryType"> - * <param name="encryptorRegisteredName">myHibernateByteEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="resume" column="RESUME" type="encryptedBinary" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEByteEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateByteEncryptor (see - * {@link HibernatePBEByteEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBinary" class="org.jasypt.hibernate.type.EncryptedBinaryType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="resume" column="RESUME" type="encryptedBinary" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedBinaryType implements UserType, ParameterizedType { - - private static final int BLOCK_SIZE = 2048; - - private static final int sqlType = Types.VARBINARY; - private static final int[] sqlTypes = new int[]{ sqlType }; - - private boolean initialized = false; - private boolean useEncryptorName = false; - - private String encryptorName = null; - private String algorithm = null; - private String password = null; - private Integer keyObtentionIterations = null; - - private PBEByteEncryptor encryptor = null; - - - public int[] sqlTypes() { - return (int[]) sqlTypes.clone(); - } - - - public Class returnedClass() { - return byte[].class; - } - - - public boolean equals(final Object x, final Object y) - throws HibernateException { - - return (x == y) || - (x != null && y != null && java.util.Arrays.equals((byte[]) x, (byte[]) y)); - - } - - - public Object deepCopy(final Object value) - throws HibernateException { - - if (value == null) { - return null; - } - final byte[] valueBytes = (byte[]) value; - final byte[] copyBytes = new byte[valueBytes.length]; - System.arraycopy(valueBytes, 0, copyBytes, 0, valueBytes.length); - return copyBytes; - - } - - - public Object assemble(final Serializable cached, final Object owner) - throws HibernateException { - if (cached == null) { - return null; - } - return deepCopy(cached); - } - - - public Serializable disassemble(final Object value) - throws HibernateException { - if (value == null) { - return null; - } - return (Serializable) deepCopy(value); - } - - - public boolean isMutable() { - return true; - } - - - public int hashCode(final Object x) - throws HibernateException { - - final byte[] valueBytes = (byte[]) x; - int result = 1; - for (int i = 0; i < valueBytes.length; i++ ) { - result = (result * 17) + valueBytes[i]; - } - return result; - - } - - - public Object replace(final Object original, final Object target, final Object owner) - throws HibernateException { - return (original == null)? null : deepCopy(original); - } - - - public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) - throws HibernateException, SQLException { - - checkInitialization(); - - byte[] encryptedValue = null; - if (Environment.useStreamsForBinary()) { - - final InputStream inputStream = rs.getBinaryStream(names[0]); - if (rs.wasNull()) { - return null; - } - - final ByteArrayOutputStream outputStream = - new ByteArrayOutputStream(BLOCK_SIZE); - final byte[] inputBuff = new byte[BLOCK_SIZE]; - try { - int readBytes = 0; - while (readBytes != -1) { - readBytes = inputStream.read(inputBuff); - if (readBytes != -1) { - outputStream.write(inputBuff, 0, readBytes); - } - } - } catch (IOException e) { - throw new HibernateException( - "IOException occurred reading a binary value", e); - } finally { - try { - inputStream.close(); - } catch (IOException e) { - // exception ignored - } - try { - outputStream.close(); - } catch (IOException e) { - // exception ignored - } - } - - encryptedValue = outputStream.toByteArray(); - - } else { - - encryptedValue = rs.getBytes(names[0]); - if (rs.wasNull()) { - return null; - } - - } - - return this.encryptor.decrypt(encryptedValue); - - } - - - public void nullSafeSet(final PreparedStatement st, final Object value, final int index) - throws HibernateException, SQLException { - - checkInitialization(); - - if (value == null) { - st.setNull(index, sqlType); - } else { - final byte[] encryptedValue = this.encryptor.encrypt((byte[]) value); - if (Environment.useStreamsForBinary()) { - st.setBinaryStream( - index, - new ByteArrayInputStream(encryptedValue), - encryptedValue.length); - } else { - st.setBytes(index, encryptedValue); - } - } - - } - - - public synchronized void setParameterValues(final Properties parameters) { - - final String paramEncryptorName = - parameters.getProperty(ParameterNaming.ENCRYPTOR_NAME); - final String paramAlgorithm = - parameters.getProperty(ParameterNaming.ALGORITHM); - final String paramPassword = - parameters.getProperty(ParameterNaming.PASSWORD); - final String paramKeyObtentionIterations = - parameters.getProperty(ParameterNaming.KEY_OBTENTION_ITERATIONS); - - this.useEncryptorName = false; - if (paramEncryptorName != null) { - - if ((paramAlgorithm != null) || - (paramPassword != null) || - (paramKeyObtentionIterations != null)) { - - throw new EncryptionInitializationException( - "If \"" + ParameterNaming.ENCRYPTOR_NAME + - "\" is specified, none of \"" + - ParameterNaming.ALGORITHM + "\", \"" + - ParameterNaming.PASSWORD + "\" or \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + "\" " + - "can be specified"); - - } - this.encryptorName = paramEncryptorName; - this.useEncryptorName = true; - - } else if ((paramPassword != null)) { - - this.password = paramPassword; - - if (paramAlgorithm != null) { - this.algorithm = paramAlgorithm; - } - - if (paramKeyObtentionIterations != null) { - - try { - this.keyObtentionIterations = - new Integer( - Integer.parseInt(paramKeyObtentionIterations)); - } catch (NumberFormatException e) { - throw new EncryptionInitializationException( - "Value specified for \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + - "\" is not a valid integer"); - } - - } - - } else { - - throw new EncryptionInitializationException( - "If \"" + ParameterNaming.ENCRYPTOR_NAME + - "\" is not specified, then \"" + - ParameterNaming.PASSWORD + "\" (and optionally \"" + - ParameterNaming.ALGORITHM + "\" and \"" + - ParameterNaming.KEY_OBTENTION_ITERATIONS + "\") " + - "must be specified"); - - } - } - - - - private synchronized void checkInitialization() { - - if (!this.initialized) { - - if (this.useEncryptorName) { - - final HibernatePBEEncryptorRegistry registry = - HibernatePBEEncryptorRegistry.getInstance(); - final PBEByteEncryptor pbeEncryptor = - registry.getPBEByteEncryptor(this.encryptorName); - if (pbeEncryptor == null) { - throw new EncryptionInitializationException( - "No big integer encryptor registered for hibernate " + - "with name \"" + this.encryptorName + "\""); - } - this.encryptor = pbeEncryptor; - - } else { - - final StandardPBEByteEncryptor newEncryptor = - new StandardPBEByteEncryptor(); - - newEncryptor.setPassword(this.password); - - if (this.algorithm != null) { - newEncryptor.setAlgorithm(this.algorithm); - } - - if (this.keyObtentionIterations != null) { - newEncryptor.setKeyObtentionIterations( - this.keyObtentionIterations.intValue()); - } - - newEncryptor.initialize(); - - this.encryptor = newEncryptor; - - } - - this.initialized = true; - } - - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBooleanAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBooleanAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedBooleanAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedBooleanAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,115 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - - - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Boolean values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBooleanAsString" class="org.jasypt.hibernate.type.EncryptedBooleanAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="active" column="ACTIVE" type="encryptedBooleanAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedBooleanAsString" class="org.jasypt.hibernate.type.EncryptedBooleanAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="active" column="ACTIVE" type="encryptedBooleanAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedBooleanAsStringType extends AbstractEncryptedAsStringType { - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return Boolean.valueOf(string); - } - - public Class returnedClass() { - return Boolean.class; - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedByteAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedByteAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedByteAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedByteAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,115 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - - - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Byte values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedByteAsString" class="org.jasypt.hibernate.type.EncryptedByteAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedByteAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedByteAsString" class="org.jasypt.hibernate.type.EncryptedByteAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedByteAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedByteAsStringType extends AbstractEncryptedAsStringType{ - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return new Byte(string); - } - - public Class returnedClass() { - return Byte.class; - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedCalendarAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedCalendarAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedCalendarAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedCalendarAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,165 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import java.util.Calendar; -import java.util.Properties; -import java.util.TimeZone; - -import org.jasypt.commons.CommonUtils; -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Calendar values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedCalendarAsString" class="org.jasypt.hibernate.type.EncryptedCalendarAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * <param name="storeTimeZone">true</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="birth" column="BIRTH" type="encryptedCalendarAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * The boolean storeTimeZone parameter allows the Calendar to be - * re-created with the same TimeZone that it was created. This is an - * optional parameter, and its default value is FALSE. - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedCalendarAsString" class="org.jasypt.hibernate.type.EncryptedCalendarAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * <param name="storeTimeZone">true</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="birth" column="BIRTH" type="encryptedCalendarAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedCalendarAsStringType extends AbstractEncryptedAsStringType{ - - private Boolean storeTimeZone = Boolean.FALSE; - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - final String[] stringTokens = CommonUtils.split(string); - TimeZone tz = null; - final long timeMillis = Long.valueOf(stringTokens[0]).longValue(); - if (this.storeTimeZone.booleanValue()) { - tz = TimeZone.getTimeZone(stringTokens[1]); - } else { - tz = TimeZone.getDefault(); - } - final Calendar cal = Calendar.getInstance(); - cal.setTimeZone(tz); - cal.setTimeInMillis(timeMillis); - return cal; - } - - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToString(java.lang.Object) - */ - protected String convertToString(final Object object) { - final StringBuffer strBuff = new StringBuffer(); - final long timeMillis = ((Calendar) object).getTimeInMillis(); - strBuff.append((new Long(timeMillis)).toString()); - if (this.storeTimeZone.booleanValue()) { - strBuff.append(" "); - strBuff.append(((Calendar) object).getTimeZone().getID()); - } - return strBuff.toString(); - } - - - public synchronized void setParameterValues(final Properties parameters) { - - super.setParameterValues(parameters); - - final String paramStoreTimeZone = parameters.getProperty(ParameterNaming.STORE_TIME_ZONE); - if ((paramStoreTimeZone != null) && (!paramStoreTimeZone.trim().equals(""))) { - this.storeTimeZone = CommonUtils.getStandardBooleanValue(paramStoreTimeZone); - } - - } - - - public Class returnedClass() { - return Calendar.class; - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedDateAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedDateAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedDateAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedDateAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,126 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import java.util.Date; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Date values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedDateAsString" class="org.jasypt.hibernate.type.EncryptedDateAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="birth" column="BIRTH" type="encryptedDateAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedDateAsString" class="org.jasypt.hibernate.type.EncryptedDateAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="birth" column="BIRTH" type="encryptedDateAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedDateAsStringType extends AbstractEncryptedAsStringType{ - - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - final long timeMillis = Long.valueOf(string).longValue(); - return new Date(timeMillis); - } - - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToString(java.lang.Object) - */ - protected String convertToString(final Object object) { - final long timeMillis = ((Date) object).getTime(); - return String.valueOf(timeMillis); - } - - - public Class returnedClass() { - return Date.class; - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedDoubleAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedDoubleAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedDoubleAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedDoubleAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,114 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - - - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Double values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedDoubleAsString" class="org.jasypt.hibernate.type.EncryptedDoubleAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedDoubleAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedDoubleAsString" class="org.jasypt.hibernate.type.EncryptedDoubleAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedDoubleAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedDoubleAsStringType extends AbstractEncryptedAsStringType{ - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return new Double(string); - } - - public Class returnedClass() { - return Double.class; - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedFloatAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedFloatAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedFloatAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedFloatAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,115 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - - - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Float values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedFloatAsString" class="org.jasypt.hibernate.type.EncryptedFloatAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedFloatAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedFloatAsString" class="org.jasypt.hibernate.type.EncryptedFloatAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedFloatAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedFloatAsStringType extends AbstractEncryptedAsStringType{ - - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return new Float(string); - } - - public Class returnedClass() { - return Float.class; - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedIntegerAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedIntegerAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedIntegerAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedIntegerAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,116 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - - - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Integer values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedIntegerAsString" class="org.jasypt.hibernate.type.EncryptedIntegerAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedIntegerAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedIntegerAsString" class="org.jasypt.hibernate.type.EncryptedIntegerAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedIntegerAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedIntegerAsStringType extends AbstractEncryptedAsStringType{ - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return new Integer(string); - } - - public Class returnedClass() { - return Integer.class; - } - - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedLongAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedLongAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedLongAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedLongAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,116 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - - - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Long values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedLongAsString" class="org.jasypt.hibernate.type.EncryptedLongAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedLongAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedLongAsString" class="org.jasypt.hibernate.type.EncryptedLongAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedLongAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedLongAsStringType extends AbstractEncryptedAsStringType{ - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return new Long(string); - } - - public Class returnedClass() { - return Long.class; - } - - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedShortAsStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedShortAsStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedShortAsStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedShortAsStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,117 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - - - -/** - *- * A Hibernate 3 UserType implementation which allows - * encryption of Short values into String (VARCHAR) database fields - * during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedShortAsString" class="org.jasypt.hibernate.type.EncryptedShortAsStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedShortAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedShortAsString" class="org.jasypt.hibernate.type.EncryptedShortAsStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="salary" column="SALARY" type="encryptedShortAsString" /> - * ... - * <class> - * ... - * <hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 - * - * @author Daniel Fernández - * - */ -public final class EncryptedShortAsStringType extends AbstractEncryptedAsStringType { - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String string) { - return new Short(string); - } - - public Class returnedClass() { - return Short.class; - } - - - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedStringType.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedStringType.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/EncryptedStringType.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/EncryptedStringType.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,115 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry; -import org.jasypt.hibernate.encryptor.HibernatePBEStringEncryptor; - - - -/** - *- * A Hibernate 3 UserType implementation which allows transparent - * encryption of String values during persistence of entities. - *
- *- * This class is intended only for declarative use from a Hibernate mapping - * file. Do not use it directly from your .java files (although - * of course you can use it when mapping entities using annotations). - *
- *- * To use this Hibernate type in one of your Hibernate mappings, you can - * add it like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedString" class="org.jasypt.hibernate.type.EncryptedStringType"> - * <param name="encryptorRegisteredName">myHibernateStringEncryptor</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="address" column="ADDRESS" type="encryptedString" /> - * ... - * </class> - * ... - * </hibernate-mapping> - *- * - *
- * ...where a HibernatePBEStringEncryptor object - * should have been previously registered to be used - * from Hibernate with name myHibernateStringEncryptor (see - * {@link HibernatePBEStringEncryptor} and {@link HibernatePBEEncryptorRegistry}). - *
- *- * Or, if you prefer to avoid registration of encryptors, you can configure - * your encryptor directly in the mapping file (although not recommended), - * like this: - *
- *- *
- * <hibernate-mapping package="myapp"> - * ... - * <typedef name="encryptedString" class="org.jasypt.hibernate.type.EncryptedStringType"> - * <param name="algorithm">PBEWithMD5AndTripleDES</param> - * <param name="password">XXXXX</param> - * <param name="keyObtentionIterations">1000</param> - * </typedef> - * ... - * <class name="UserData" table="USER_DATA"> - * ... - * <property name="address" column="ADDRESS" type="encryptedString" /> - * ... - * </class> - * ... - * </hibernate-mapping> - *- * - *
- * To learn more about usage of user-defined types, please refer to the - * Hibernate Reference - * Documentation. - *
- * - * - * @since 1.2 (substitutes org.jasypt.hibernate.EncryptedTextType - * which existed since 1.0) - * - * @author Daniel Fernández - * - */ -public final class EncryptedStringType extends AbstractEncryptedAsStringType{ - - /** - * @see org.jasypt.hibernate.type.AbstractEncryptedAsStringType#convertToObject(java.lang.String) - */ - protected Object convertToObject(final String stringValue) { - return stringValue; - } - - public Class returnedClass() { - return String.class; - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/hibernate/type/ParameterNaming.java jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/ParameterNaming.java --- jasypt-1.8/src/main/java/org/jasypt/hibernate/type/ParameterNaming.java 2010-10-16 18:38:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/hibernate/type/ParameterNaming.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,129 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.hibernate.type; - -/** - *- * Constant names of the parameters that can be used by a jasypt type's - * typedef declaration in a Hibernate mapping. - *
- * - * @since 1.4 (was org.jasypt.hibernate.ParameterNaming since 1.0) - * - * @author Daniel Fernández - * - */ -public final class ParameterNaming { - - /** - *- * The registered name of an encryptor previously registered at the - * {@link org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry}. - *
- *- * Value = encryptorRegisteredName - *
- */ - public static final String ENCRYPTOR_NAME = "encryptorRegisteredName"; - - /** - *- * The encryption algorithm. - *
- *- * Value = algorithm - *
- */ - public static final String ALGORITHM = "algorithm"; - - /** - *- * The name of the JCE security provider we want to get the algorithm from - * (if it is no the default one. - *
- *- * Value = providerName - *
- */ - public static final String PROVIDER_NAME = "providerName"; - - /** - *- * The encryption password. - *
- *- * Value = password - *
- */ - public static final String PASSWORD = "password"; - - /** - *- * The number of hashing iterations to be applied for obtaining the - * encryption key. - *
- *- * Value = keyObtentionIterations - *
- */ - public static final String KEY_OBTENTION_ITERATIONS = - "keyObtentionIterations"; - - /** - *- * The type of String output ("base64" (default), "hexadecimal") to be - * generated. - *
- *- * Value = stringOutputType - *
- */ - public static final String STRING_OUTPUT_TYPE = "stringOutputType"; - - /** - *- * The scale (numbers after the decimal point) to be used when storing - * decimal numbers. - *
- *- * Value = decimalScale - *
- */ - public static final String DECIMAL_SCALE = - "decimalScale"; - - /** - *- * Whether the calendar time zone should be stored with the date or not. - *
- *- * Value = storeTimeZone - *
- */ - public static final String STORE_TIME_ZONE = - "storeTimeZone"; - - - - private ParameterNaming() { - super(); - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/intf/service/JasyptStatelessService.java jasypt-1.9.2/src/main/java/org/jasypt/intf/service/JasyptStatelessService.java --- jasypt-1.8/src/main/java/org/jasypt/intf/service/JasyptStatelessService.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/intf/service/JasyptStatelessService.java 2014-02-25 00:22:19.000000000 +0000 @@ -24,7 +24,6 @@ import org.jasypt.digest.config.EnvironmentStringDigesterConfig; import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig; -import org.jasypt.exceptions.EncryptionOperationNotPossibleException; diff -Nru jasypt-1.8/src/main/java/org/jasypt/normalization/Normalizer.java jasypt-1.9.2/src/main/java/org/jasypt/normalization/Normalizer.java --- jasypt-1.8/src/main/java/org/jasypt/normalization/Normalizer.java 2011-07-24 15:55:47.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/normalization/Normalizer.java 2014-02-25 14:19:40.000000000 +0000 @@ -19,6 +19,9 @@ */ package org.jasypt.normalization; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + import org.jasypt.exceptions.EncryptionInitializationException; @@ -42,8 +45,12 @@ private static final String ICU_NORMALIZER_CLASS_NAME = "com.ibm.icu.text.Normalizer"; private static final String JDK_NORMALIZER_CLASS_NAME = "java.text.Normalizer"; + private static final String JDK_NORMALIZER_FORM_CLASS_NAME = "java.text.Normalizer$Form"; + + private static Boolean useIcuNormalizer = null; - private static Boolean useIcuNormalizer = null; + private static Method javaTextNormalizerMethod = null; + private static Object javaTextNormalizerFormNFCConstant = null; /** @@ -85,19 +92,36 @@ // Still not initialized, will try to load the icu4j Normalizer. If // icu4j is in the classpath, it will be used even if java version is >= 6. try { - Thread.currentThread().getContextClassLoader().loadClass(ICU_NORMALIZER_CLASS_NAME); - useIcuNormalizer = Boolean.TRUE; - } catch (ClassNotFoundException e) { + + initializeIcu4j(); + + } catch (final ClassNotFoundException e) { + try { - Thread.currentThread().getContextClassLoader().loadClass(JDK_NORMALIZER_CLASS_NAME); - } catch (ClassNotFoundException e2) { + + initializeJavaTextNormalizer(); + + } catch (final ClassNotFoundException e2) { throw new EncryptionInitializationException( "Cannot find a valid UNICODE normalizer: neither " + JDK_NORMALIZER_CLASS_NAME + " nor " + ICU_NORMALIZER_CLASS_NAME + " have been found at the classpath. If you are using " + "a version of the JDK older than JavaSE 6, you should include the icu4j library in " + "your classpath."); + } catch (final NoSuchMethodException e2) { + throw new EncryptionInitializationException( + "Cannot find a valid UNICODE normalizer: " + JDK_NORMALIZER_CLASS_NAME + " has " + + "been found at the classpath, but has an incompatible signature for its 'normalize' " + + "method."); + } catch (final NoSuchFieldException e2) { + throw new EncryptionInitializationException( + "Cannot find a valid UNICODE normalizer: " + JDK_NORMALIZER_FORM_CLASS_NAME + " has " + + "been found at the classpath, but seems to have no 'NFC' value."); + } catch (final IllegalAccessException e2) { + throw new EncryptionInitializationException( + "Cannot find a valid UNICODE normalizer: " + JDK_NORMALIZER_FORM_CLASS_NAME + " has " + + "been found at the classpath, but seems to have no 'NFC' value."); } - useIcuNormalizer = Boolean.FALSE; + } } @@ -109,21 +133,64 @@ } + + static void initializeIcu4j() throws ClassNotFoundException { + Thread.currentThread().getContextClassLoader().loadClass(ICU_NORMALIZER_CLASS_NAME); + useIcuNormalizer = Boolean.TRUE; + } + + + static void initializeJavaTextNormalizer() + throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException { - private static char[] normalizeWithJavaNormalizer(final char[] message) { + final Class javaTextNormalizerClass = + Thread.currentThread().getContextClassLoader().loadClass(JDK_NORMALIZER_CLASS_NAME); + final Class javaTextNormalizerFormClass = + Thread.currentThread().getContextClassLoader().loadClass(JDK_NORMALIZER_FORM_CLASS_NAME); + javaTextNormalizerMethod = + javaTextNormalizerClass.getMethod( + "normalize", new Class[]{ CharSequence.class, javaTextNormalizerFormClass }); + final Field javaTextNormalizerFormNFCConstantField = javaTextNormalizerFormClass.getField("NFC"); + javaTextNormalizerFormNFCConstant = javaTextNormalizerFormNFCConstantField.get(null); + + useIcuNormalizer = Boolean.FALSE; + + } + + + + + static char[] normalizeWithJavaNormalizer(final char[] message) { + + if (javaTextNormalizerMethod == null || javaTextNormalizerFormNFCConstant == null) { + throw new EncryptionInitializationException( + "Cannot use: " + JDK_NORMALIZER_FORM_CLASS_NAME + ", as JDK-based normalization has " + + "not been initialized! (check previous execution errors)"); + } + // Using java JDK's Normalizer, we cannot avoid creating Strings // (it is the only possible interface to the Normalizer class). + // + // Note java.text.Normalizer is accessed via reflection in order to allow this + // class to be JDK 1.4-compilable (though ICU4j will be needed at runtime + // if Java 1.4 is used). final String messageStr = new String(message); - final String result = - java.text.Normalizer.normalize(messageStr, java.text.Normalizer.Form.NFC); + final String result; + try { + result = (String) javaTextNormalizerMethod.invoke( + null, new Object[] { messageStr, javaTextNormalizerFormNFCConstant }); + } catch (final Exception e) { + throw new EncryptionInitializationException( + "Could not perform a valid UNICODE normalization", e); + } return result.toCharArray(); } - private static char[] normalizeWithIcu4j(final char[] message) { + static char[] normalizeWithIcu4j(final char[] message) { // initialize the result to twice the size of the message // this should be more than enough in most cases char[] normalizationResult = new char[message.length * 2]; diff -Nru jasypt-1.8/src/main/java/org/jasypt/properties/EncryptableProperties.java jasypt-1.9.2/src/main/java/org/jasypt/properties/EncryptableProperties.java --- jasypt-1.8/src/main/java/org/jasypt/properties/EncryptableProperties.java 2010-10-16 18:38:04.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/properties/EncryptableProperties.java 2014-02-24 22:49:38.000000000 +0000 @@ -20,6 +20,7 @@ package org.jasypt.properties; import java.io.IOException; +import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Properties; @@ -78,12 +79,19 @@ * Used as an identifier for the encryptor registry */ private final Integer ident = new Integer(CommonUtils.nextRandomInt()); + + /* + * The string encryptor to be used for properties. Either this or the + * 'textEncryptor' property have to be non-null. + */ + private transient StringEncryptor stringEncryptor = null; /* - * Used as a marker to know if the object has ever been serialized + * The text encryptor to be used for properties. Either this or the + * 'stringEncryptor' property have to be non-null. */ - private boolean beenSerialized = false; - + private transient TextEncryptor textEncryptor = null; + /** *@@ -127,9 +135,8 @@ public EncryptableProperties(final Properties defaults, final StringEncryptor stringEncryptor) { super(defaults); CommonUtils.validateNotNull(stringEncryptor, "Encryptor cannot be null"); - final EncryptablePropertiesEncryptorRegistry registry = - EncryptablePropertiesEncryptorRegistry.getInstance(); - registry.setStringEncryptor(this, stringEncryptor); + this.stringEncryptor = stringEncryptor; + this.textEncryptor = null; } @@ -147,9 +154,8 @@ public EncryptableProperties(final Properties defaults, final TextEncryptor textEncryptor) { super(defaults); CommonUtils.validateNotNull(textEncryptor, "Encryptor cannot be null"); - final EncryptablePropertiesEncryptorRegistry registry = - EncryptablePropertiesEncryptorRegistry.getInstance(); - registry.setTextEncryptor(this, textEncryptor); + this.stringEncryptor = null; + this.textEncryptor = textEncryptor; } @@ -184,6 +190,24 @@ public String getProperty(final String key, final String defaultValue) { return decode(super.getProperty(key, defaultValue)); } + + + /** + *
+ * Obtains the property value for the specified key (see + * {@link Hashtable#get(Object)}), decrypting it if needed. + *
+ * + * @param key the property key + * @return the (decrypted) value + * @since 1.9.0 + */ + public synchronized Object get(final Object key) { + final Object value = super.get(key); + final String valueStr = + (value instanceof String) ? (String)value : null; + return decode(valueStr); + } /* @@ -202,16 +226,12 @@ if (!PropertyValueEncryptionUtils.isEncryptedValue(encodedValue)) { return encodedValue; } - final EncryptablePropertiesEncryptorRegistry registry = - EncryptablePropertiesEncryptorRegistry.getInstance(); - final StringEncryptor stringEncryptor = registry.getStringEncryptor(this); - if (stringEncryptor != null) { - return PropertyValueEncryptionUtils.decrypt(encodedValue, stringEncryptor); + if (this.stringEncryptor != null) { + return PropertyValueEncryptionUtils.decrypt(encodedValue, this.stringEncryptor); } - final TextEncryptor textEncryptor = registry.getTextEncryptor(this); - if (textEncryptor != null) { - return PropertyValueEncryptionUtils.decrypt(encodedValue, textEncryptor); + if (this.textEncryptor != null) { + return PropertyValueEncryptionUtils.decrypt(encodedValue, this.textEncryptor); } /* @@ -229,22 +249,46 @@ "serialized themselves)"); } + + private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { + + in.defaultReadObject(); + + final EncryptablePropertiesEncryptorRegistry registry = + EncryptablePropertiesEncryptorRegistry.getInstance(); + + final StringEncryptor registeredStringEncryptor = registry.getStringEncryptor(this); + if (registeredStringEncryptor != null) { + this.stringEncryptor = registeredStringEncryptor; + return; + } + + final TextEncryptor registeredTextEncryptor = registry.getTextEncryptor(this); + if (registeredTextEncryptor != null) { + this.textEncryptor = registeredTextEncryptor; + } + + } + + private void writeObject(final ObjectOutputStream outputStream) throws IOException { - this.beenSerialized = true; + + final EncryptablePropertiesEncryptorRegistry registry = + EncryptablePropertiesEncryptorRegistry.getInstance(); + if (this.textEncryptor != null) { + registry.setTextEncryptor(this, this.textEncryptor); + } else if (this.stringEncryptor != null) { + registry.setStringEncryptor(this, this.stringEncryptor); + } + outputStream.defaultWriteObject(); + } - - protected void finalize() throws Throwable { - if (!this.beenSerialized) { - final EncryptablePropertiesEncryptorRegistry registry = - EncryptablePropertiesEncryptorRegistry.getInstance(); - registry.removeEntries(this); - } - } + } diff -Nru jasypt-1.8/src/main/java/org/jasypt/salt/ByteArrayFixedSaltGenerator.java jasypt-1.9.2/src/main/java/org/jasypt/salt/ByteArrayFixedSaltGenerator.java --- jasypt-1.8/src/main/java/org/jasypt/salt/ByteArrayFixedSaltGenerator.java 1970-01-01 00:00:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/salt/ByteArrayFixedSaltGenerator.java 2014-02-25 01:52:26.000000000 +0000 @@ -0,0 +1,88 @@ +/* + * ============================================================================= + * + * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============================================================================= + */ +package org.jasypt.salt; + +import org.jasypt.commons.CommonUtils; +import org.jasypt.exceptions.EncryptionInitializationException; + +/** + *+ * Byte-array based implementation of {@link FixedSaltGenerator}, that will + * always return the same salt. + *
+ *+ * If the requested salt has a size in bytes smaller than the specified salt, + * the first n bytes are returned. If it is larger, an exception is thrown. + *
+ *+ * This class is thread-safe. + *
+ * + * @since 1.9.2 + * + * @author Daniel Fernández + * + */ +public class ByteArrayFixedSaltGenerator implements FixedSaltGenerator { + + private final byte[] salt; + + /** + * Creates a new instance of FixedByteArraySaltGenerator + * + * @param salt the specified salt. + */ + public ByteArrayFixedSaltGenerator(final byte[] salt) { + super(); + CommonUtils.validateNotNull(salt, "Salt cannot be set null"); + this.salt = (byte[]) salt.clone(); + } + + + /** + * Return salt with the specified byte length. + * + * @param lengthBytes length in bytes. + * @return the generated salt. + */ + public byte[] generateSalt(final int lengthBytes) { + if (this.salt.length < lengthBytes) { + throw new EncryptionInitializationException( + "Requested salt larger than set"); + } + final byte[] generatedSalt = new byte[lengthBytes]; + System.arraycopy(this.salt, 0, generatedSalt, 0, lengthBytes); + return generatedSalt; + } + + + /** + * As this salt generator provides a fixed salt, its inclusion + * unencrypted in encryption results + * is not necessary, and in fact not desirable (so that it remains hidden). + * + * @return false + */ + public boolean includePlainSaltInEncryptionResults() { + return false; + } + + +} diff -Nru jasypt-1.8/src/main/java/org/jasypt/salt/FixedByteArraySaltGenerator.java jasypt-1.9.2/src/main/java/org/jasypt/salt/FixedByteArraySaltGenerator.java --- jasypt-1.8/src/main/java/org/jasypt/salt/FixedByteArraySaltGenerator.java 2010-10-16 18:38:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/salt/FixedByteArraySaltGenerator.java 2014-02-25 01:52:26.000000000 +0000 @@ -39,6 +39,11 @@ * * @author Daniel Fernández * + * @deprecated Deprecated in 1.9.2 in favour of {@link ByteArrayFixedSaltGenerator}, which + * implements the new {@link FixedSaltGenerator} interface and therefore is able to benefit + * from the performance improvements associated with it. This class will be removed + * in 1.10.0 (or 2.0.0). + * */ public class FixedByteArraySaltGenerator implements SaltGenerator { diff -Nru jasypt-1.8/src/main/java/org/jasypt/salt/FixedSaltGenerator.java jasypt-1.9.2/src/main/java/org/jasypt/salt/FixedSaltGenerator.java --- jasypt-1.8/src/main/java/org/jasypt/salt/FixedSaltGenerator.java 1970-01-01 00:00:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/salt/FixedSaltGenerator.java 2014-02-25 01:52:26.000000000 +0000 @@ -0,0 +1,42 @@ +/* + * ============================================================================= + * + * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============================================================================= + */ +package org.jasypt.salt; + + +/** + *+ * Marker interface for all implementations of {@link SaltGenerator} that + * will always return the same salt (for the same amount of bytes asked). + *
+ *+ * Use of this interface in salt generators enables encryptors to perform + * some performance optimizations whenever they are used. + *
+ * + * @since 1.9.2 + * + * @author Daniel Fernández + * + */ +public interface FixedSaltGenerator extends SaltGenerator { + + // Marker interface - no methods added + +} diff -Nru jasypt-1.8/src/main/java/org/jasypt/salt/FixedStringSaltGenerator.java jasypt-1.9.2/src/main/java/org/jasypt/salt/FixedStringSaltGenerator.java --- jasypt-1.8/src/main/java/org/jasypt/salt/FixedStringSaltGenerator.java 2010-10-16 18:38:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/salt/FixedStringSaltGenerator.java 2014-02-25 01:52:26.000000000 +0000 @@ -42,6 +42,11 @@ * * @author Daniel Fernández * + * @deprecated Deprecated in 1.9.2 in favour of {@link StringFixedSaltGenerator}, which + * implements the new {@link FixedSaltGenerator} interface and therefore is able to benefit + * from the performance improvements associated with it. This class will be removed + * in 1.10.0 (or 2.0.0). + * */ public class FixedStringSaltGenerator implements SaltGenerator { diff -Nru jasypt-1.8/src/main/java/org/jasypt/salt/RandomSaltGenerator.java jasypt-1.9.2/src/main/java/org/jasypt/salt/RandomSaltGenerator.java --- jasypt-1.8/src/main/java/org/jasypt/salt/RandomSaltGenerator.java 2010-10-16 18:38:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/salt/RandomSaltGenerator.java 2013-08-21 21:31:58.000000000 +0000 @@ -74,7 +74,6 @@ super(); try { this.random = SecureRandom.getInstance(secureRandomAlgorithm); - this.random.setSeed(System.currentTimeMillis()); } catch (NoSuchAlgorithmException e) { throw new EncryptionInitializationException(e); } diff -Nru jasypt-1.8/src/main/java/org/jasypt/salt/StringFixedSaltGenerator.java jasypt-1.9.2/src/main/java/org/jasypt/salt/StringFixedSaltGenerator.java --- jasypt-1.8/src/main/java/org/jasypt/salt/StringFixedSaltGenerator.java 1970-01-01 00:00:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/salt/StringFixedSaltGenerator.java 2014-02-25 01:52:26.000000000 +0000 @@ -0,0 +1,116 @@ +/* + * ============================================================================= + * + * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============================================================================= + */ +package org.jasypt.salt; + +import java.io.UnsupportedEncodingException; + +import org.jasypt.commons.CommonUtils; +import org.jasypt.exceptions.EncryptionInitializationException; + +/** + *+ * String based implementation of {@link FixedSaltGenerator}, that will + * always return the same salt. This salt is returned as bytes using the + * specified charset for conversion (UTF-8 by default). + *
+ *+ * If the requested salt has a size in bytes smaller than the specified salt, + * the first n bytes are returned. If it is larger, an exception is thrown. + *
+ *+ * This class is thread-safe. + *
+ * + * @since 1.9.2 + * + * @author Daniel Fernández + * + */ +public class StringFixedSaltGenerator implements FixedSaltGenerator { + + private static final String DEFAULT_CHARSET = "UTF-8"; + + private final String salt; + private final String charset; + private final byte[] saltBytes; + + + + /** + * Creates a new instance of FixedStringSaltGenerator using + * the default charset. + * + * @param salt the specified salt. + */ + public StringFixedSaltGenerator(final String salt) { + this(salt, null); + } + + + /** + * Creates a new instance of FixedStringSaltGenerator + * + * @param salt the specified salt. + * @param charset the specified charset + */ + public StringFixedSaltGenerator(final String salt, final String charset) { + super(); + CommonUtils.validateNotNull(salt, "Salt cannot be set null"); + this.salt = salt; + this.charset = (charset != null? charset : DEFAULT_CHARSET); + try { + this.saltBytes = this.salt.getBytes(this.charset); + } catch (UnsupportedEncodingException e) { + throw new EncryptionInitializationException( + "Invalid charset specified: " + this.charset); + } + } + + + /** + * Return salt with the specified byte length. + * + * @param lengthBytes length in bytes. + * @return the generated salt. + */ + public byte[] generateSalt(final int lengthBytes) { + if (this.saltBytes.length < lengthBytes) { + throw new EncryptionInitializationException( + "Requested salt larger than set"); + } + final byte[] generatedSalt = new byte[lengthBytes]; + System.arraycopy(this.saltBytes, 0, generatedSalt, 0, lengthBytes); + return generatedSalt; + } + + + /** + * As this salt generator provides a fixed salt, its inclusion + * unencrypted in encryption results + * is not necessary, and in fact not desirable (so that it remains hidden). + * + * @return false + */ + public boolean includePlainSaltInEncryptionResults() { + return false; + } + + +} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/properties/EncryptablePreferencesPlaceholderConfigurer.java jasypt-1.9.2/src/main/java/org/jasypt/spring/properties/EncryptablePreferencesPlaceholderConfigurer.java --- jasypt-1.8/src/main/java/org/jasypt/spring/properties/EncryptablePreferencesPlaceholderConfigurer.java 2010-10-21 23:28:02.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/properties/EncryptablePreferencesPlaceholderConfigurer.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,110 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.properties; - -import org.jasypt.commons.CommonUtils; -import org.jasypt.encryption.StringEncryptor; -import org.jasypt.properties.PropertyValueEncryptionUtils; -import org.jasypt.util.text.TextEncryptor; -import org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer; - -/** - *- * Subclass of - * org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer - * which can make use of a {@link org.jasypt.encryption.StringEncryptor} or - * {@link org.jasypt.util.text.TextEncryptor} object to decrypt preferences values - * if they are encrypted in the loaded resource locations. - *
- *- * A value is considered "encrypted" when it appears surrounded by - * ENC(...), like: - *
- *- *
- * Creates an EncryptablePreferencesPlaceholderConfigurer instance - * which will use the passed {@link StringEncryptor} object to decrypt - * encrypted values. - *
- * - * @param stringEncryptor - * the {@link StringEncryptor} to be used do decrypt values. It - * can not be null. - */ - public EncryptablePreferencesPlaceholderConfigurer( - final StringEncryptor stringEncryptor) { - super(); - CommonUtils.validateNotNull(stringEncryptor, "Encryptor cannot be null"); - this.stringEncryptor = stringEncryptor; - this.textEncryptor = null; - } - - /** - *- * Creates an EncryptablePreferencesPlaceholderConfigurer instance which will use the - * passed {@link TextEncryptor} object to decrypt encrypted values. - *
- * - * @param textEncryptor - * the {@link TextEncryptor} to be used do decrypt values. It can - * not be null. - */ - public EncryptablePreferencesPlaceholderConfigurer(final TextEncryptor textEncryptor) { - super(); - CommonUtils.validateNotNull(textEncryptor, "Encryptor cannot be null"); - this.stringEncryptor = null; - this.textEncryptor = textEncryptor; - } - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.config.PropertyResourceConfigurer#convertPropertyValue(java.lang.String) - */ - protected String convertPropertyValue(final String originalValue) { - if (!PropertyValueEncryptionUtils.isEncryptedValue(originalValue)) { - return originalValue; - } - if (this.stringEncryptor != null) { - return PropertyValueEncryptionUtils.decrypt(originalValue, - this.stringEncryptor); - - } - return PropertyValueEncryptionUtils.decrypt(originalValue, this.textEncryptor); - } -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/properties/EncryptablePropertyOverrideConfigurer.java jasypt-1.9.2/src/main/java/org/jasypt/spring/properties/EncryptablePropertyOverrideConfigurer.java --- jasypt-1.8/src/main/java/org/jasypt/spring/properties/EncryptablePropertyOverrideConfigurer.java 2010-10-21 23:28:02.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/properties/EncryptablePropertyOverrideConfigurer.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,113 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.properties; - -import org.jasypt.commons.CommonUtils; -import org.jasypt.encryption.StringEncryptor; -import org.jasypt.properties.PropertyValueEncryptionUtils; -import org.jasypt.util.text.TextEncryptor; -import org.springframework.beans.factory.config.PropertyOverrideConfigurer; - -/** - *- * Subclass of - * org.springframework.beans.factory.config.PropertyOverrideConfigurer - * which can make use of a {@link org.jasypt.encryption.StringEncryptor} or - * {@link org.jasypt.util.text.TextEncryptor} object to decrypt property values - * if they are encrypted in the loaded resource locations. - *
- *- * A value is considered "encrypted" when it appears surrounded by - * ENC(...), like: - *
- *- *
- * Encrypted and unencrypted objects can be combined in the same resources file. - *
- * - * @since 1.4 - * - * @author Marcos Muíño García - * - */ -public final class EncryptablePropertyOverrideConfigurer - extends PropertyOverrideConfigurer { - /* - * Only one of these instances will be initialized, the other one will be - * null. - */ - private final StringEncryptor stringEncryptor; - private final TextEncryptor textEncryptor; - - /** - *- * Creates an EncryptablePropertyOverrideConfigurer instance - * which will use the passed {@link StringEncryptor} object to decrypt - * encrypted values. - *
- * - * @param stringEncryptor - * the {@link StringEncryptor} to be used do decrypt values. It - * can not be null. - */ - public EncryptablePropertyOverrideConfigurer( - final StringEncryptor stringEncryptor) { - super(); - CommonUtils.validateNotNull(stringEncryptor, "Encryptor cannot be null"); - this.stringEncryptor = stringEncryptor; - this.textEncryptor = null; - } - - /** - *- * Creates an EncryptablePropertyOverrideConfigurer instance which will use the - * passed {@link TextEncryptor} object to decrypt encrypted values. - *
- * - * @param textEncryptor - * the {@link TextEncryptor} to be used do decrypt values. It can - * not be null. - */ - public EncryptablePropertyOverrideConfigurer(final TextEncryptor textEncryptor) { - super(); - CommonUtils.validateNotNull(textEncryptor, "Encryptor cannot be null"); - this.stringEncryptor = null; - this.textEncryptor = textEncryptor; - } - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.config.PropertyResourceConfigurer#convertPropertyValue(java.lang.String) - */ - protected String convertPropertyValue(final String originalValue) { - if (!PropertyValueEncryptionUtils.isEncryptedValue(originalValue)) { - return originalValue; - } - if (this.stringEncryptor != null) { - return PropertyValueEncryptionUtils.decrypt(originalValue, - this.stringEncryptor); - - } - return PropertyValueEncryptionUtils.decrypt(originalValue, this.textEncryptor); - } -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/properties/EncryptablePropertyPlaceholderConfigurer.java jasypt-1.9.2/src/main/java/org/jasypt/spring/properties/EncryptablePropertyPlaceholderConfigurer.java --- jasypt-1.8/src/main/java/org/jasypt/spring/properties/EncryptablePropertyPlaceholderConfigurer.java 2011-07-24 20:59:48.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/properties/EncryptablePropertyPlaceholderConfigurer.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,125 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.properties; - -import org.jasypt.commons.CommonUtils; -import org.jasypt.encryption.StringEncryptor; -import org.jasypt.properties.PropertyValueEncryptionUtils; -import org.jasypt.util.text.TextEncryptor; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; - -/** - *- * Subclass of - * org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - * which can make use of a {@link org.jasypt.encryption.StringEncryptor} or - * {@link org.jasypt.util.text.TextEncryptor} object to decrypt property values - * if they are encrypted in the loaded resource locations. - *
- *- * A value is considered "encrypted" when it appears surrounded by - * ENC(...), like: - *
- *- *
- * Encrypted and unencrypted objects can be combined in the same resources file. - *
- * - * @since 1.4 - * - * @author Marcos Muíño García - * @author Carlos Fernández - * - */ -public final class EncryptablePropertyPlaceholderConfigurer - extends PropertyPlaceholderConfigurer { - /* - * Only one of these instances will be initialized, the other one will be - * null. - */ - private final StringEncryptor stringEncryptor; - private final TextEncryptor textEncryptor; - - /** - *- * Creates an EncryptablePropertyPlaceholderConfigurer instance - * which will use the passed {@link StringEncryptor} object to decrypt - * encrypted values. - *
- * - * @param stringEncryptor - * the {@link StringEncryptor} to be used do decrypt values. It - * can not be null. - */ - public EncryptablePropertyPlaceholderConfigurer( - final StringEncryptor stringEncryptor) { - super(); - CommonUtils.validateNotNull(stringEncryptor, "Encryptor cannot be null"); - this.stringEncryptor = stringEncryptor; - this.textEncryptor = null; - } - - /** - *- * Creates an EncryptablePropertyPlaceholderConfigurer instance which will use the - * passed {@link TextEncryptor} object to decrypt encrypted values. - *
- * - * @param textEncryptor - * the {@link TextEncryptor} to be used do decrypt values. It can - * not be null. - */ - public EncryptablePropertyPlaceholderConfigurer(final TextEncryptor textEncryptor) { - super(); - CommonUtils.validateNotNull(textEncryptor, "Encryptor cannot be null"); - this.stringEncryptor = null; - this.textEncryptor = textEncryptor; - } - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.config.PropertyResourceConfigurer#convertPropertyValue(java.lang.String) - */ - protected String convertPropertyValue(final String originalValue) { - if (!PropertyValueEncryptionUtils.isEncryptedValue(originalValue)) { - return originalValue; - } - if (this.stringEncryptor != null) { - return PropertyValueEncryptionUtils.decrypt(originalValue, - this.stringEncryptor); - - } - return PropertyValueEncryptionUtils.decrypt(originalValue, this.textEncryptor); - } - - /* - * (non-Javadoc) - * - * @since 1.8 - * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#resolveSystemProperty(java.lang.String) - */ - protected String resolveSystemProperty(final String key) { - return convertPropertyValue(super.resolveSystemProperty(key)); - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/properties/EncryptableServletContextPropertyPlaceholderConfigurer.java jasypt-1.9.2/src/main/java/org/jasypt/spring/properties/EncryptableServletContextPropertyPlaceholderConfigurer.java --- jasypt-1.8/src/main/java/org/jasypt/spring/properties/EncryptableServletContextPropertyPlaceholderConfigurer.java 2011-03-31 00:25:34.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/properties/EncryptableServletContextPropertyPlaceholderConfigurer.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,127 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.properties; - -import java.util.Properties; - -import org.jasypt.commons.CommonUtils; -import org.jasypt.encryption.StringEncryptor; -import org.jasypt.properties.PropertyValueEncryptionUtils; -import org.jasypt.util.text.TextEncryptor; -import org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer; - -/** - *- * Subclass of - * org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer - * which can make use of a {@link org.jasypt.encryption.StringEncryptor} or - * {@link org.jasypt.util.text.TextEncryptor} object to decrypt servlet context parameter values - * if they are encrypted in the loaded resource locations. - *
- *- * A value is considered "encrypted" when it appears surrounded by - * ENC(...), like: - *
- *- *
- * Creates an EncryptableServletContextPropertyPlaceholderConfigurer instance - * which will use the passed {@link StringEncryptor} object to decrypt - * encrypted values. - *
- * - * @param stringEncryptor - * the {@link StringEncryptor} to be used do decrypt values. It - * can not be null. - */ - public EncryptableServletContextPropertyPlaceholderConfigurer( - final StringEncryptor stringEncryptor) { - super(); - CommonUtils.validateNotNull(stringEncryptor, "Encryptor cannot be null"); - this.stringEncryptor = stringEncryptor; - this.textEncryptor = null; - } - - /** - *- * Creates an EncryptableServletContextPropertyPlaceholderConfigurer instance which will use the - * passed {@link TextEncryptor} object to decrypt encrypted values. - *
- * - * @param textEncryptor - * the {@link TextEncryptor} to be used do decrypt values. It can - * not be null. - */ - public EncryptableServletContextPropertyPlaceholderConfigurer(final TextEncryptor textEncryptor) { - super(); - CommonUtils.validateNotNull(textEncryptor, "Encryptor cannot be null"); - this.stringEncryptor = null; - this.textEncryptor = textEncryptor; - } - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.config.PropertyResourceConfigurer#convertPropertyValue(java.lang.String) - */ - protected String convertPropertyValue(final String originalValue) { - if (!PropertyValueEncryptionUtils.isEncryptedValue(originalValue)) { - return originalValue; - } - if (this.stringEncryptor != null) { - return PropertyValueEncryptionUtils.decrypt(originalValue, - this.stringEncryptor); - - } - return PropertyValueEncryptionUtils.decrypt(originalValue, this.textEncryptor); - } - - - - /* - * Spring's ServletContextPropertyPlaceholderConfigurer never creates a complete - * map of properties, and so never really applies the "convertPropertyValue" method - * to them. Instead it gets properties on the fly and returns them without conversion - * (as of Spring 3.0.5). - * - * This fix makes sure that variables are decrypted before being returned. - */ - protected String resolvePlaceholder(final String placeholder, final Properties props) { - return convertPropertyValue(super.resolvePlaceholder(placeholder, props)); - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/security/PasswordEncoder.java jasypt-1.9.2/src/main/java/org/jasypt/spring/security/PasswordEncoder.java --- jasypt-1.8/src/main/java/org/jasypt/spring/security/PasswordEncoder.java 2010-10-16 18:38:03.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/security/PasswordEncoder.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,236 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.security; - -import org.jasypt.digest.StringDigester; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.util.password.BasicPasswordEncryptor; -import org.jasypt.util.password.PasswordEncryptor; - -/** - *- * This class implements the Spring Security (ACEGI) - * org.acegisecurity.providers.encoding.PasswordEncoder - * interface, allowing Spring Security-enabled applications to use JASYPT - * for password encryption. - *
- *- * Objects of this class will internally hold either an object of type - * org.jasypt.util.password.PasswordEncryptor or an object of type - * org.jasypt.digest.StringDigester (only one of them), - * which should be set by respectively calling - * {@link #setPasswordEncryptor(PasswordEncryptor)} or - * {@link #setStringDigester(StringDigester)} - * after creation. If neither a PasswordEncryptor nor - * a StringDigester are set, a new - * org.jasypt.util.password.BasicPasswordEncryptor object is - * created and internally used. - *
- *- * Important: This implementation ignores any salt provided through - * the interface methods, as the internal Jasypt - * PasswordEncryptor or StringDigester objects normally use a - * random one. This means that salt can be safely passed as - * null. - *
- *- * Usage with a PasswordEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the PasswordEncryptor in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptPasswordEncryptor" class="org.jasypt.util.password.StrongPasswordEncryptor" /> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the PasswordEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security.PasswordEncoder"> - * <property name="passwordEncryptor"> - * <ref bean="jasyptPasswordEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * Usage with a StringDigester - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the StringDigester in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptStringDigester" class="org.jasypt.digest.StandardStringDigester" > - * <property name="algorithm" value="SHA-1" /> - * <property name="iterations" value="100000" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the StringDigester instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security.PasswordEncoder"> - * <property name="stringDigester"> - * <ref bean="jasyptStringDigester" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * This class is thread-safe - *
- * - * @since 1.4 (existed since 1.2 as - * org.jasypt.springsecurity.PasswordEncoder) - * - * @author Daniel Fernández - * - */ -public final class PasswordEncoder - implements org.acegisecurity.providers.encoding.PasswordEncoder { - - // The password encryptor or string digester to be internally used - private PasswordEncryptor passwordEncryptor = null; - private StringDigester stringDigester = null; - private Boolean useEncryptor = null; - - - /** - * Creates a new instance of PasswordEncoder - */ - public PasswordEncoder() { - super(); - } - - - /** - * Sets a password encryptor to be used. Only one of - * setPasswordEncryptor or setStringDigester should be - * called. If both are, the last call will define which method will be - * used. - * - * @param passwordEncryptor the password encryptor instance to be used. - */ - public void setPasswordEncryptor(final PasswordEncryptor passwordEncryptor) { - this.passwordEncryptor = passwordEncryptor; - this.useEncryptor = Boolean.TRUE; - } - - /** - * Sets a string digester to be used. Only one of - * setPasswordEncryptor or setStringDigester should be - * called. If both are, the last call will define which method will be - * used. - * - * @param stringDigester the string digester instance to be used. - */ - public void setStringDigester(final StringDigester stringDigester) { - this.stringDigester = stringDigester; - this.useEncryptor = Boolean.FALSE; - } - - - /** - * Encodes a password. This implementation completely ignores salt, - * as jasypt's PasswordEncryptor and StringDigester - * normally use a random one. Thus, it can be safely passed as null. - * - * @param rawPass The password to be encoded. - * @param salt The salt, which will be ignored. It can be null. - */ - public String encodePassword(final String rawPass, final Object salt) { - checkInitialization(); - if (this.useEncryptor.booleanValue()) { - return this.passwordEncryptor.encryptPassword(rawPass); - } - return this.stringDigester.digest(rawPass); - } - - - /** - * Checks a password's validity. This implementation completely ignores - * salt, as jasypt's PasswordEncryptor and StringDigester - * normally use a random one. Thus, it can be safely passed as null. - * - * @param encPass The encrypted password (digest) against which to check. - * @param rawPass The password to be checked. - * @param salt The salt, which will be ignored. It can be null. - */ - public boolean isPasswordValid(final String encPass, final String rawPass, final Object salt) { - checkInitialization(); - if (this.useEncryptor.booleanValue()) { - return this.passwordEncryptor.checkPassword(rawPass, encPass); - } - return this.stringDigester.matches(rawPass, encPass); - } - - - /* - * Checks that the PasswordEncoder has been correctly initialized - * (either a password encryptor or a string digester has been set). - */ - private synchronized void checkInitialization() { - if (this.useEncryptor == null) { - this.passwordEncryptor = new BasicPasswordEncryptor(); - this.useEncryptor = Boolean.TRUE; - } else { - if (this.useEncryptor.booleanValue()) { - if (this.passwordEncryptor == null) { - throw new EncryptionInitializationException( - "Password encoder not initialized: password " + - "encryptor is null"); - } - } else { - if (this.stringDigester == null) { - throw new EncryptionInitializationException( - "Password encoder not initialized: string " + - "digester is null"); - } - } - } - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/security/PBEPasswordEncoder.java jasypt-1.9.2/src/main/java/org/jasypt/spring/security/PBEPasswordEncoder.java --- jasypt-1.8/src/main/java/org/jasypt/spring/security/PBEPasswordEncoder.java 2010-10-16 18:38:03.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/security/PBEPasswordEncoder.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,253 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.security; - -import org.jasypt.encryption.pbe.PBEStringEncryptor; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.util.text.BasicTextEncryptor; -import org.jasypt.util.text.TextEncryptor; - -/** - *- * This class implements the Spring Security (ACEGI) - * org.acegisecurity.providers.encoding.PasswordEncoder - * interface, allowing Spring Security-enabled applications to use JASYPT - * for password encryption. - *
- *- * Important: This class allows bi-directional password-based encryption - * of user passwords - * in ACEGI using Jasypt. But please note that passwords should not be - * encrypted in a bi-directional way, but instead as uni-directional - * digests (hashes). Encrypting passwords in a way they can be decrypted - * can be a severe security issue, and should only be considered in legacy - * or complex inter-application integration scenarios. - *
- *- * Objects of this class will internally hold either an object of type - * org.jasypt.util.text.TextEncryptor or an object of type - * org.jasypt.encryption.pbe.PBEStringEncryptor (only one of them), - * which should be set by respectively calling - * {@link #setTextEncryptor(TextEncryptor)} or - * {@link #setPbeStringEncryptor(PBEStringEncryptor)} - * after creation. If neither a TextEncryptor nor - * a PBEStringEncryptor are set, a new - * org.jasypt.util.text.BasicTextEncryptor object is - * created and internally used. - *
- *- * Important: This implementation ignores any salt provided through - * the interface methods, as the internal Jasypt - * TextEncryptor or PBEStringEncryptor objects normally use a - * random one. This means that salt can be safely passed as - * null. - *
- *- * Usage with a TextEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the TextEncryptor in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptTextEncryptor" class="org.jasypt.util.text.StrongTextEncryptor" > - * <property name="password" value="myPassword" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the TextEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security.PBEPasswordEncoder"> - * <property name="textEncryptor"> - * <ref bean="jasyptTextEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * Usage with a PBEStringEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the PBEStringEncryptor in several places,--> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptPBEStringEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor" > - * <property name="algorithm" value="PBEWithMD5AndTripleDES" /> - * <property name="password" value="myPassword" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the PBEStringEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security.PBEPasswordEncoder"> - * <property name="pbeStringEncryptor"> - * <ref bean="jasyptPBEStringEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * This class is thread-safe - *
- * - * @since 1.4 (existed since 1.2 as - * org.jasypt.springsecurity.PasswordEncoder) - * - * @author Daniel Fernández - * - */ -public final class PBEPasswordEncoder - implements org.acegisecurity.providers.encoding.PasswordEncoder { - - // The text encryptor or PBE string encryptor to be internally used - private TextEncryptor textEncryptor = null; - private PBEStringEncryptor pbeStringEncryptor = null; - private Boolean useTextEncryptor = null; - - - /** - * Creates a new instance of PBEPasswordEncoder - */ - public PBEPasswordEncoder() { - super(); - } - - - /** - * Sets a text encryptor to be used. Only one of - * setTextEncryptor or setPBEStringEncryptor should be - * called. If both are, the last call will define which method will be - * used. - * - * @param textEncryptor the text encryptor instance to be used. - */ - public void setTextEncryptor(final TextEncryptor textEncryptor) { - this.textEncryptor = textEncryptor; - this.useTextEncryptor = Boolean.TRUE; - } - - /** - * Sets a string digester to be used. Only one of - * setTextEncryptor or setPBEStringEncryptor should be - * called. If both are, the last call will define which method will be - * used. - * - * @param pbeStringEncryptor the PBE string encryptor instance to be used. - */ - public void setPbeStringEncryptor(final PBEStringEncryptor pbeStringEncryptor) { - this.pbeStringEncryptor = pbeStringEncryptor; - this.useTextEncryptor = Boolean.FALSE; - } - - - /** - * Encodes a password. This implementation completely ignores salt, - * as jasypt's TextEncryptor and PBEStringEncryptor - * normally use a random one. Thus, it can be safely passed as null. - * - * @param rawPass The password to be encoded. - * @param salt The salt, which will be ignored. It can be null. - */ - public String encodePassword(final String rawPass, final Object salt) { - checkInitialization(); - if (this.useTextEncryptor.booleanValue()) { - return this.textEncryptor.encrypt(rawPass); - } - return this.pbeStringEncryptor.encrypt(rawPass); - } - - - /** - * Checks a password's validity. This implementation completely ignores - * salt, as jasypt's TextEncryptor and PBEStringEncryptor - * normally use a random one. Thus, it can be safely passed as null. - * - * @param encPass The encrypted password against which to check. - * @param rawPass The password to be checked. - * @param salt The salt, which will be ignored. It can be null. - */ - public boolean isPasswordValid(final String encPass, final String rawPass, final Object salt) { - checkInitialization(); - String decPassword = null; - if (this.useTextEncryptor.booleanValue()) { - decPassword = this.textEncryptor.decrypt(encPass); - } else { - decPassword = this.pbeStringEncryptor.decrypt(encPass); - } - if ((decPassword == null) || (rawPass == null)) { - return (decPassword == rawPass); - } - return decPassword.equals(rawPass); - } - - - /* - * Checks that the PasswordEncoder has been correctly initialized - * (either a text encryptor or a PBE string encryptor has been set). - */ - private synchronized void checkInitialization() { - if (this.useTextEncryptor == null) { - this.textEncryptor = new BasicTextEncryptor(); - this.useTextEncryptor = Boolean.TRUE; - } else { - if (this.useTextEncryptor.booleanValue()) { - if (this.textEncryptor == null) { - throw new EncryptionInitializationException( - "PBE Password encoder not initialized: text " + - "encryptor is null"); - } - } else { - if (this.pbeStringEncryptor == null) { - throw new EncryptionInitializationException( - "PBE Password encoder not initialized: PBE " + - "string encryptor is null"); - } - } - } - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/security2/PasswordEncoder.java jasypt-1.9.2/src/main/java/org/jasypt/spring/security2/PasswordEncoder.java --- jasypt-1.8/src/main/java/org/jasypt/spring/security2/PasswordEncoder.java 2010-10-16 18:38:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/security2/PasswordEncoder.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,235 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.security2; - -import org.jasypt.digest.StringDigester; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.util.password.BasicPasswordEncryptor; -import org.jasypt.util.password.PasswordEncryptor; - -/** - *- * This class implements the Spring Security 2.x - * org.springframework.security.providers.encoding.PasswordEncoder - * interface, allowing Spring Security-enabled applications to use JASYPT - * for password encryption. - *
- *- * Objects of this class will internally hold either an object of type - * org.jasypt.util.password.PasswordEncryptor or an object of type - * org.jasypt.digest.StringDigester (only one of them), - * which should be set by respectively calling - * {@link #setPasswordEncryptor(PasswordEncryptor)} or - * {@link #setStringDigester(StringDigester)} - * after creation. If neither a PasswordEncryptor nor - * a StringDigester are set, a new - * org.jasypt.util.password.BasicPasswordEncryptor object is - * created and internally used. - *
- *- * Important: This implementation ignores any salt provided through - * the interface methods, as the internal Jasypt - * PasswordEncryptor or StringDigester objects normally use a - * random one. This means that salt can be safely passed as - * null. - *
- *- * Usage with a PasswordEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the PasswordEncryptor in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptPasswordEncryptor" class="org.jasypt.util.password.StrongPasswordEncryptor" /> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the PasswordEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security2.PasswordEncoder"> - * <property name="passwordEncryptor"> - * <ref bean="jasyptPasswordEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * Usage with a StringDigester - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the StringDigester in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptStringDigester" class="org.jasypt.digest.StandardStringDigester" > - * <property name="algorithm" value="SHA-1" /> - * <property name="iterations" value="100000" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the StringDigester instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security2.PasswordEncoder"> - * <property name="stringDigester"> - * <ref bean="jasyptStringDigester" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * This class is thread-safe - *
- * - * @since 1.5 - * - * @author Daniel Fernández - * - */ -public final class PasswordEncoder - implements org.springframework.security.providers.encoding.PasswordEncoder { - - // The password encryptor or string digester to be internally used - private PasswordEncryptor passwordEncryptor = null; - private StringDigester stringDigester = null; - private Boolean useEncryptor = null; - - - /** - * Creates a new instance of PasswordEncoder - */ - public PasswordEncoder() { - super(); - } - - - /** - * Sets a password encryptor to be used. Only one of - * setPasswordEncryptor or setStringDigester should be - * called. If both are, the last call will define which method will be - * used. - * - * @param passwordEncryptor the password encryptor instance to be used. - */ - public void setPasswordEncryptor(final PasswordEncryptor passwordEncryptor) { - this.passwordEncryptor = passwordEncryptor; - this.useEncryptor = Boolean.TRUE; - } - - /** - * Sets a string digester to be used. Only one of - * setPasswordEncryptor or setStringDigester should be - * called. If both are, the last call will define which method will be - * used. - * - * @param stringDigester the string digester instance to be used. - */ - public void setStringDigester(final StringDigester stringDigester) { - this.stringDigester = stringDigester; - this.useEncryptor = Boolean.FALSE; - } - - - /** - * Encodes a password. This implementation completely ignores salt, - * as jasypt's PasswordEncryptor and StringDigester - * normally use a random one. Thus, it can be safely passed as null. - * - * @param rawPass The password to be encoded. - * @param salt The salt, which will be ignored. It can be null. - */ - public String encodePassword(final String rawPass, final Object salt) { - checkInitialization(); - if (this.useEncryptor.booleanValue()) { - return this.passwordEncryptor.encryptPassword(rawPass); - } - return this.stringDigester.digest(rawPass); - } - - - /** - * Checks a password's validity. This implementation completely ignores - * salt, as jasypt's PasswordEncryptor and StringDigester - * normally use a random one. Thus, it can be safely passed as null. - * - * @param encPass The encrypted password (digest) against which to check. - * @param rawPass The password to be checked. - * @param salt The salt, which will be ignored. It can be null. - */ - public boolean isPasswordValid(final String encPass, final String rawPass, final Object salt) { - checkInitialization(); - if (this.useEncryptor.booleanValue()) { - return this.passwordEncryptor.checkPassword(rawPass, encPass); - } - return this.stringDigester.matches(rawPass, encPass); - } - - - /* - * Checks that the PasswordEncoder has been correctly initialized - * (either a password encryptor or a string digester has been set). - */ - private synchronized void checkInitialization() { - if (this.useEncryptor == null) { - this.passwordEncryptor = new BasicPasswordEncryptor(); - this.useEncryptor = Boolean.TRUE; - } else { - if (this.useEncryptor.booleanValue()) { - if (this.passwordEncryptor == null) { - throw new EncryptionInitializationException( - "Password encoder not initialized: password " + - "encryptor is null"); - } - } else { - if (this.stringDigester == null) { - throw new EncryptionInitializationException( - "Password encoder not initialized: string " + - "digester is null"); - } - } - } - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/security2/PBEPasswordEncoder.java jasypt-1.9.2/src/main/java/org/jasypt/spring/security2/PBEPasswordEncoder.java --- jasypt-1.8/src/main/java/org/jasypt/spring/security2/PBEPasswordEncoder.java 2010-10-16 18:38:00.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/security2/PBEPasswordEncoder.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,252 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.security2; - -import org.jasypt.encryption.pbe.PBEStringEncryptor; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.util.text.BasicTextEncryptor; -import org.jasypt.util.text.TextEncryptor; - -/** - *- * This class implements the Spring Security 2.x - * org.springframework.security.providers.encoding.PasswordEncoder - * interface, allowing Spring Security-enabled applications to use JASYPT - * for password encryption. - *
- *- * Important: This class allows bi-directional password-based encryption - * of user passwords - * in Spring Security using Jasypt. But please note that passwords should not be - * encrypted in a bi-directional way, but instead as uni-directional - * digests (hashes). Encrypting passwords in a way they can be decrypted - * can be a severe security issue, and should only be considered in legacy - * or complex inter-application integration scenarios. - *
- *- * Objects of this class will internally hold either an object of type - * org.jasypt.util.text.TextEncryptor or an object of type - * org.jasypt.encryption.pbe.PBEStringEncryptor (only one of them), - * which should be set by respectively calling - * {@link #setTextEncryptor(TextEncryptor)} or - * {@link #setPbeStringEncryptor(PBEStringEncryptor)} - * after creation. If neither a TextEncryptor nor - * a PBEStringEncryptor are set, a new - * org.jasypt.util.text.BasicTextEncryptor object is - * created and internally used. - *
- *- * Important: This implementation ignores any salt provided through - * the interface methods, as the internal Jasypt - * TextEncryptor or PBEStringEncryptor objects normally use a - * random one. This means that salt can be safely passed as - * null. - *
- *- * Usage with a TextEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the TextEncryptor in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptTextEncryptor" class="org.jasypt.util.text.StrongTextEncryptor" > - * <property name="password" value="myPassword" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the TextEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security2.PBEPasswordEncoder"> - * <property name="textEncryptor"> - * <ref bean="jasyptTextEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * Usage with a PBEStringEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the PBEStringEncryptor in several places,--> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptPBEStringEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor" > - * <property name="algorithm" value="PBEWithMD5AndTripleDES" /> - * <property name="password" value="myPassword" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the PBEStringEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security2.PBEPasswordEncoder"> - * <property name="pbeStringEncryptor"> - * <ref bean="jasyptPBEStringEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * This class is thread-safe - *
- * - * @since 1.5 - * - * @author Daniel Fernández - * - */ -public final class PBEPasswordEncoder - implements org.springframework.security.providers.encoding.PasswordEncoder { - - // The text encryptor or PBE string encryptor to be internally used - private TextEncryptor textEncryptor = null; - private PBEStringEncryptor pbeStringEncryptor = null; - private Boolean useTextEncryptor = null; - - - /** - * Creates a new instance of PBEPasswordEncoder - */ - public PBEPasswordEncoder() { - super(); - } - - - /** - * Sets a text encryptor to be used. Only one of - * setTextEncryptor or setPBEStringEncryptor should be - * called. If both are, the last call will define which method will be - * used. - * - * @param textEncryptor the text encryptor instance to be used. - */ - public void setTextEncryptor(final TextEncryptor textEncryptor) { - this.textEncryptor = textEncryptor; - this.useTextEncryptor = Boolean.TRUE; - } - - /** - * Sets a string digester to be used. Only one of - * setTextEncryptor or setPBEStringEncryptor should be - * called. If both are, the last call will define which method will be - * used. - * - * @param pbeStringEncryptor the PBE string encryptor instance to be used. - */ - public void setPbeStringEncryptor(final PBEStringEncryptor pbeStringEncryptor) { - this.pbeStringEncryptor = pbeStringEncryptor; - this.useTextEncryptor = Boolean.FALSE; - } - - - /** - * Encodes a password. This implementation completely ignores salt, - * as jasypt's TextEncryptor and PBEStringEncryptor - * normally use a random one. Thus, it can be safely passed as null. - * - * @param rawPass The password to be encoded. - * @param salt The salt, which will be ignored. It can be null. - */ - public String encodePassword(final String rawPass, final Object salt) { - checkInitialization(); - if (this.useTextEncryptor.booleanValue()) { - return this.textEncryptor.encrypt(rawPass); - } - return this.pbeStringEncryptor.encrypt(rawPass); - } - - - /** - * Checks a password's validity. This implementation completely ignores - * salt, as jasypt's TextEncryptor and PBEStringEncryptor - * normally use a random one. Thus, it can be safely passed as null. - * - * @param encPass The encrypted password against which to check. - * @param rawPass The password to be checked. - * @param salt The salt, which will be ignored. It can be null. - */ - public boolean isPasswordValid(final String encPass, final String rawPass, final Object salt) { - checkInitialization(); - String decPassword = null; - if (this.useTextEncryptor.booleanValue()) { - decPassword = this.textEncryptor.decrypt(encPass); - } else { - decPassword = this.pbeStringEncryptor.decrypt(encPass); - } - if ((decPassword == null) || (rawPass == null)) { - return (decPassword == rawPass); - } - return decPassword.equals(rawPass); - } - - - /* - * Checks that the PasswordEncoder has been correctly initialized - * (either a text encryptor or a PBE string encryptor has been set). - */ - private synchronized void checkInitialization() { - if (this.useTextEncryptor == null) { - this.textEncryptor = new BasicTextEncryptor(); - this.useTextEncryptor = Boolean.TRUE; - } else { - if (this.useTextEncryptor.booleanValue()) { - if (this.textEncryptor == null) { - throw new EncryptionInitializationException( - "PBE Password encoder not initialized: text " + - "encryptor is null"); - } - } else { - if (this.pbeStringEncryptor == null) { - throw new EncryptionInitializationException( - "PBE Password encoder not initialized: PBE " + - "string encryptor is null"); - } - } - } - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/security3/PasswordEncoder.java jasypt-1.9.2/src/main/java/org/jasypt/spring/security3/PasswordEncoder.java --- jasypt-1.8/src/main/java/org/jasypt/spring/security3/PasswordEncoder.java 2010-10-16 18:38:04.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/security3/PasswordEncoder.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,235 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.security3; - -import org.jasypt.digest.StringDigester; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.util.password.BasicPasswordEncryptor; -import org.jasypt.util.password.PasswordEncryptor; - -/** - *- * This class implements the Spring Security 3.x - * org.springframework.security.authentication.encoding.PasswordEncoder - * interface, allowing Spring Security-enabled applications to use JASYPT - * for password encryption. - *
- *- * Objects of this class will internally hold either an object of type - * org.jasypt.util.password.PasswordEncryptor or an object of type - * org.jasypt.digest.StringDigester (only one of them), - * which should be set by respectively calling - * {@link #setPasswordEncryptor(PasswordEncryptor)} or - * {@link #setStringDigester(StringDigester)} - * after creation. If neither a PasswordEncryptor nor - * a StringDigester are set, a new - * org.jasypt.util.password.BasicPasswordEncryptor object is - * created and internally used. - *
- *- * Important: This implementation ignores any salt provided through - * the interface methods, as the internal Jasypt - * PasswordEncryptor or StringDigester objects normally use a - * random one. This means that salt can be safely passed as - * null. - *
- *- * Usage with a PasswordEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the PasswordEncryptor in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptPasswordEncryptor" class="org.jasypt.util.password.StrongPasswordEncryptor" /> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the PasswordEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security2.PasswordEncoder"> - * <property name="passwordEncryptor"> - * <ref bean="jasyptPasswordEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * Usage with a StringDigester - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the StringDigester in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptStringDigester" class="org.jasypt.digest.StandardStringDigester" > - * <property name="algorithm" value="SHA-1" /> - * <property name="iterations" value="100000" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the StringDigester instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security2.PasswordEncoder"> - * <property name="stringDigester"> - * <ref bean="jasyptStringDigester" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * This class is thread-safe - *
- * - * @since 1.6 - * - * @author Daniel Fernández - * - */ -public final class PasswordEncoder - implements org.springframework.security.authentication.encoding.PasswordEncoder { - - // The password encryptor or string digester to be internally used - private PasswordEncryptor passwordEncryptor = null; - private StringDigester stringDigester = null; - private Boolean useEncryptor = null; - - - /** - * Creates a new instance of PasswordEncoder - */ - public PasswordEncoder() { - super(); - } - - - /** - * Sets a password encryptor to be used. Only one of - * setPasswordEncryptor or setStringDigester should be - * called. If both are, the last call will define which method will be - * used. - * - * @param passwordEncryptor the password encryptor instance to be used. - */ - public void setPasswordEncryptor(final PasswordEncryptor passwordEncryptor) { - this.passwordEncryptor = passwordEncryptor; - this.useEncryptor = Boolean.TRUE; - } - - /** - * Sets a string digester to be used. Only one of - * setPasswordEncryptor or setStringDigester should be - * called. If both are, the last call will define which method will be - * used. - * - * @param stringDigester the string digester instance to be used. - */ - public void setStringDigester(final StringDigester stringDigester) { - this.stringDigester = stringDigester; - this.useEncryptor = Boolean.FALSE; - } - - - /** - * Encodes a password. This implementation completely ignores salt, - * as jasypt's PasswordEncryptor and StringDigester - * normally use a random one. Thus, it can be safely passed as null. - * - * @param rawPass The password to be encoded. - * @param salt The salt, which will be ignored. It can be null. - */ - public String encodePassword(final String rawPass, final Object salt) { - checkInitialization(); - if (this.useEncryptor.booleanValue()) { - return this.passwordEncryptor.encryptPassword(rawPass); - } - return this.stringDigester.digest(rawPass); - } - - - /** - * Checks a password's validity. This implementation completely ignores - * salt, as jasypt's PasswordEncryptor and StringDigester - * normally use a random one. Thus, it can be safely passed as null. - * - * @param encPass The encrypted password (digest) against which to check. - * @param rawPass The password to be checked. - * @param salt The salt, which will be ignored. It can be null. - */ - public boolean isPasswordValid(final String encPass, final String rawPass, final Object salt) { - checkInitialization(); - if (this.useEncryptor.booleanValue()) { - return this.passwordEncryptor.checkPassword(rawPass, encPass); - } - return this.stringDigester.matches(rawPass, encPass); - } - - - /* - * Checks that the PasswordEncoder has been correctly initialized - * (either a password encryptor or a string digester has been set). - */ - private synchronized void checkInitialization() { - if (this.useEncryptor == null) { - this.passwordEncryptor = new BasicPasswordEncryptor(); - this.useEncryptor = Boolean.TRUE; - } else { - if (this.useEncryptor.booleanValue()) { - if (this.passwordEncryptor == null) { - throw new EncryptionInitializationException( - "Password encoder not initialized: password " + - "encryptor is null"); - } - } else { - if (this.stringDigester == null) { - throw new EncryptionInitializationException( - "Password encoder not initialized: string " + - "digester is null"); - } - } - } - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/security3/PBEPasswordEncoder.java jasypt-1.9.2/src/main/java/org/jasypt/spring/security3/PBEPasswordEncoder.java --- jasypt-1.8/src/main/java/org/jasypt/spring/security3/PBEPasswordEncoder.java 2010-10-16 18:38:04.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/security3/PBEPasswordEncoder.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,252 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.security3; - -import org.jasypt.encryption.pbe.PBEStringEncryptor; -import org.jasypt.exceptions.EncryptionInitializationException; -import org.jasypt.util.text.BasicTextEncryptor; -import org.jasypt.util.text.TextEncryptor; - -/** - *- * This class implements the Spring Security 3.x - * org.springframework.security.providers.encoding.PasswordEncoder - * interface, allowing Spring Security-enabled applications to use JASYPT - * for password encryption. - *
- *- * Important: This class allows bi-directional password-based encryption - * of user passwords - * in Spring Security using Jasypt. But please note that passwords should not be - * encrypted in a bi-directional way, but instead as uni-directional - * digests (hashes). Encrypting passwords in a way they can be decrypted - * can be a severe security issue, and should only be considered in legacy - * or complex inter-application integration scenarios. - *
- *- * Objects of this class will internally hold either an object of type - * org.jasypt.util.text.TextEncryptor or an object of type - * org.jasypt.encryption.pbe.PBEStringEncryptor (only one of them), - * which should be set by respectively calling - * {@link #setTextEncryptor(TextEncryptor)} or - * {@link #setPbeStringEncryptor(PBEStringEncryptor)} - * after creation. If neither a TextEncryptor nor - * a PBEStringEncryptor are set, a new - * org.jasypt.util.text.BasicTextEncryptor object is - * created and internally used. - *
- *- * Important: This implementation ignores any salt provided through - * the interface methods, as the internal Jasypt - * TextEncryptor or PBEStringEncryptor objects normally use a - * random one. This means that salt can be safely passed as - * null. - *
- *- * Usage with a TextEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the TextEncryptor in several places, --> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptTextEncryptor" class="org.jasypt.util.text.StrongTextEncryptor" > - * <property name="password" value="myPassword" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the TextEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security2.PBEPasswordEncoder"> - * <property name="textEncryptor"> - * <ref bean="jasyptTextEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * Usage with a PBEStringEncryptor - *
- *- * This class can be used like this from your Spring XML resource files: - *
- *- * ... - * <!-- Your application may use the PBEStringEncryptor in several places,--> - * <!-- like for example at new user sign-up. --> - * <bean id="jasyptPBEStringEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor" > - * <property name="algorithm" value="PBEWithMD5AndTripleDES" /> - * <property name="password" value="myPassword" /> - * </bean> - * ... - * ... - * <!-- This Spring Security-friendly PasswordEncoder implementation will --> - * <!-- wrap the PBEStringEncryptor instance so that it can be used from --> - * <!-- the security framework. --> - * <bean id="passwordEncoder" class="org.jasypt.spring.security2.PBEPasswordEncoder"> - * <property name="pbeStringEncryptor"> - * <ref bean="jasyptPBEStringEncryptor" /> - * </property> - * </bean> - * ... - * ... - * <!-- Your DaoAuthenticationProvider will then use it like with any --> - * <!-- other implementation of the PasswordEncoder interface. --> - * <bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider"> - * <property name="userDetailsService" ref="userDetailsService"/> - * <property name="passwordEncoder"> - * <ref bean="passwordEncoder" /> - * </property> - * </bean> - * ... - *- *
- * This class is thread-safe - *
- * - * @since 1.6 - * - * @author Daniel Fernández - * - */ -public final class PBEPasswordEncoder - implements org.springframework.security.authentication.encoding.PasswordEncoder { - - // The text encryptor or PBE string encryptor to be internally used - private TextEncryptor textEncryptor = null; - private PBEStringEncryptor pbeStringEncryptor = null; - private Boolean useTextEncryptor = null; - - - /** - * Creates a new instance of PBEPasswordEncoder - */ - public PBEPasswordEncoder() { - super(); - } - - - /** - * Sets a text encryptor to be used. Only one of - * setTextEncryptor or setPBEStringEncryptor should be - * called. If both are, the last call will define which method will be - * used. - * - * @param textEncryptor the text encryptor instance to be used. - */ - public void setTextEncryptor(final TextEncryptor textEncryptor) { - this.textEncryptor = textEncryptor; - this.useTextEncryptor = Boolean.TRUE; - } - - /** - * Sets a string digester to be used. Only one of - * setTextEncryptor or setPBEStringEncryptor should be - * called. If both are, the last call will define which method will be - * used. - * - * @param pbeStringEncryptor the PBE string encryptor instance to be used. - */ - public void setPbeStringEncryptor(final PBEStringEncryptor pbeStringEncryptor) { - this.pbeStringEncryptor = pbeStringEncryptor; - this.useTextEncryptor = Boolean.FALSE; - } - - - /** - * Encodes a password. This implementation completely ignores salt, - * as jasypt's TextEncryptor and PBEStringEncryptor - * normally use a random one. Thus, it can be safely passed as null. - * - * @param rawPass The password to be encoded. - * @param salt The salt, which will be ignored. It can be null. - */ - public String encodePassword(final String rawPass, final Object salt) { - checkInitialization(); - if (this.useTextEncryptor.booleanValue()) { - return this.textEncryptor.encrypt(rawPass); - } - return this.pbeStringEncryptor.encrypt(rawPass); - } - - - /** - * Checks a password's validity. This implementation completely ignores - * salt, as jasypt's TextEncryptor and PBEStringEncryptor - * normally use a random one. Thus, it can be safely passed as null. - * - * @param encPass The encrypted password against which to check. - * @param rawPass The password to be checked. - * @param salt The salt, which will be ignored. It can be null. - */ - public boolean isPasswordValid(final String encPass, final String rawPass, final Object salt) { - checkInitialization(); - String decPassword = null; - if (this.useTextEncryptor.booleanValue()) { - decPassword = this.textEncryptor.decrypt(encPass); - } else { - decPassword = this.pbeStringEncryptor.decrypt(encPass); - } - if ((decPassword == null) || (rawPass == null)) { - return (decPassword == rawPass); - } - return decPassword.equals(rawPass); - } - - - /* - * Checks that the PasswordEncoder has been correctly initialized - * (either a text encryptor or a PBE string encryptor has been set). - */ - private synchronized void checkInitialization() { - if (this.useTextEncryptor == null) { - this.textEncryptor = new BasicTextEncryptor(); - this.useTextEncryptor = Boolean.TRUE; - } else { - if (this.useTextEncryptor.booleanValue()) { - if (this.textEncryptor == null) { - throw new EncryptionInitializationException( - "PBE Password encoder not initialized: text " + - "encryptor is null"); - } - } else { - if (this.pbeStringEncryptor == null) { - throw new EncryptionInitializationException( - "PBE Password encoder not initialized: PBE " + - "string encryptor is null"); - } - } - } - } - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/spring/security3/TokenBasedRememberMeServices.java jasypt-1.9.2/src/main/java/org/jasypt/spring/security3/TokenBasedRememberMeServices.java --- jasypt-1.8/src/main/java/org/jasypt/spring/security3/TokenBasedRememberMeServices.java 2010-10-24 18:58:37.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/spring/security3/TokenBasedRememberMeServices.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,161 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.spring.security3; - -import java.util.Date; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.jasypt.commons.CommonUtils; -import org.jasypt.digest.StringDigester; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices; -import org.springframework.security.web.authentication.rememberme.InvalidCookieException; - - -/** - *- * Implementation of org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices - * which provides a "remember-me" cookie arranged in the same way as - * org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices, but using a - * Jasypt {@link StringDigester} passed as a parameter for performing the digest of the signature in the cookie - * (username + ":" + expiry time + ":" + password + ":" + key). - *
- *- * This class is thread-safe - *
- * - * @since 1.7 - * - * @author Daniel Fernández - * - */ -public final class TokenBasedRememberMeServices extends AbstractRememberMeServices { - - - private StringDigester digester = null; - - - - public void setDigester(final StringDigester digester) { - this.digester = digester; - } - - - - - private String getSignatureData(final long tokenExpiryTime, final String username, final String password) { - return username + ":" + tokenExpiryTime + ":" + password + ":" + getKey(); - } - - - - protected UserDetails processAutoLoginCookie(final String[] cookieTokens, - final HttpServletRequest request, final HttpServletResponse response) { - - if (this.digester == null) { - throw new IllegalStateException("Service incorrectly initialized: a " + - "digester has not been set. A value must be specified for the \"digester\"" + - " property in service of class " + this.getClass().getName()); - } - - if (cookieTokens.length != 3) { - throw new InvalidCookieException("Wrong number of tokens in cookie"); - } - - final String usernameToken = cookieTokens[0]; - final String expiryToken = cookieTokens[1]; - final String digestedSignature = cookieTokens[2]; - - long expiryTimestamp = -1; - try { - expiryTimestamp = new Long(expiryToken).longValue(); - } catch (NumberFormatException nfe) { - throw new InvalidCookieException("Invalid cookie expiry token"); - } - - if (expiryTimestamp < System.currentTimeMillis()) { - // Cookie has expired - throw new InvalidCookieException("Cookie has expired (expired on '" + new Date(expiryTimestamp) + "'; current time is '" + new Date() + "')"); - } - - // Retrieve user details - final UserDetails userDetails = - getUserDetailsService().loadUserByUsername(usernameToken); - final String username = userDetails.getUsername(); - final String password = userDetails.getPassword(); - - // Check signature data - if (!this.digester.matches(getSignatureData(expiryTimestamp, username, password), digestedSignature)) { - throw new InvalidCookieException("Cookie signature is not valid"); - } - - return userDetails; - - } - - - - public void onLoginSuccess(final HttpServletRequest request, final HttpServletResponse response, - final Authentication successfulAuthentication) { - - if (this.digester == null) { - throw new IllegalStateException("Service incorrectly initialized: a " + - "digester has not been set. A value must be specified for the \"digester\"" + - " property in service of class " + this.getClass().getName()); - } - - String username = null; - String password = null; - - if (successfulAuthentication.getPrincipal() instanceof UserDetails) { - final UserDetails userDetails = (UserDetails) successfulAuthentication.getPrincipal(); - username = userDetails.getUsername(); - password = userDetails.getPassword(); - } else { - username = successfulAuthentication.getPrincipal().toString(); - password = (successfulAuthentication.getCredentials() == null? null : successfulAuthentication.getCredentials().toString()); - } - - if (CommonUtils.isEmpty(username) || CommonUtils.isEmpty(password)) { - // both user name and password have to be non-empty. No cookie to be added - return; - } - - final int tokenValiditySeconds = getTokenValiditySeconds(); - final long expiryTime = - System.currentTimeMillis() + 1000L* (tokenValiditySeconds < 0 ? TWO_WEEKS_S : tokenValiditySeconds); - - final String signature = this.digester.digest(getSignatureData(expiryTime, username, password)); - - setCookie(new String[] {username, Long.toString(expiryTime), signature}, tokenValiditySeconds, request, response); - - if (this.logger.isDebugEnabled()) { - this.logger.debug("Added remember-me cookie for user '" + username + "', expiry: '" + new Date(expiryTime) + "'"); - } - - } - - - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/util/digest/Digester.java jasypt-1.9.2/src/main/java/org/jasypt/util/digest/Digester.java --- jasypt-1.8/src/main/java/org/jasypt/util/digest/Digester.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/util/digest/Digester.java 2014-02-25 00:22:19.000000000 +0000 @@ -22,7 +22,6 @@ import java.security.Provider; import org.jasypt.digest.StandardByteDigester; -import org.jasypt.exceptions.AlreadyInitializedException; /** *diff -Nru jasypt-1.8/src/main/java/org/jasypt/util/password/ConfigurablePasswordEncryptor.java jasypt-1.9.2/src/main/java/org/jasypt/util/password/ConfigurablePasswordEncryptor.java --- jasypt-1.8/src/main/java/org/jasypt/util/password/ConfigurablePasswordEncryptor.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/util/password/ConfigurablePasswordEncryptor.java 2014-02-25 00:22:19.000000000 +0000 @@ -24,7 +24,6 @@ import org.jasypt.digest.StandardByteDigester; import org.jasypt.digest.StandardStringDigester; import org.jasypt.digest.config.DigesterConfig; -import org.jasypt.exceptions.AlreadyInitializedException; /** *
diff -Nru jasypt-1.8/src/main/java/org/jasypt/web/pbeconfig/WebPBEInitializationContextListener.java jasypt-1.9.2/src/main/java/org/jasypt/web/pbeconfig/WebPBEInitializationContextListener.java --- jasypt-1.8/src/main/java/org/jasypt/web/pbeconfig/WebPBEInitializationContextListener.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/web/pbeconfig/WebPBEInitializationContextListener.java 2014-02-25 00:22:19.000000000 +0000 @@ -23,7 +23,6 @@ import javax.servlet.ServletContextListener; import org.jasypt.commons.CommonUtils; -import org.jasypt.encryption.pbe.config.WebPBEConfig; import org.jasypt.exceptions.EncryptionInitializationException; /** diff -Nru jasypt-1.8/src/main/java/org/jasypt/web/pbeconfig/WebPBEInitializer.java jasypt-1.9.2/src/main/java/org/jasypt/web/pbeconfig/WebPBEInitializer.java --- jasypt-1.8/src/main/java/org/jasypt/web/pbeconfig/WebPBEInitializer.java 2011-07-24 16:21:44.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/web/pbeconfig/WebPBEInitializer.java 2014-02-25 00:22:19.000000000 +0000 @@ -19,7 +19,6 @@ */ package org.jasypt.web.pbeconfig; -import org.jasypt.encryption.pbe.config.WebPBEConfig; diff -Nru jasypt-1.8/src/main/java/org/jasypt/wicket/JasyptCryptFactory.java jasypt-1.9.2/src/main/java/org/jasypt/wicket/JasyptCryptFactory.java --- jasypt-1.8/src/main/java/org/jasypt/wicket/JasyptCryptFactory.java 2011-07-24 16:21:39.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/wicket/JasyptCryptFactory.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,87 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.wicket; - -import org.apache.wicket.util.crypt.ICrypt; -import org.apache.wicket.util.crypt.ICryptFactory; -import org.jasypt.encryption.pbe.PBEByteEncryptor; -import org.jasypt.encryption.pbe.PBEStringEncryptor; - - -/** - *
- * Implementation of the Apache Wicket {@link ICryptFactory} interface - * which returns {@link JasyptCrypt} instances. - *
- *- * Requires a {@link PBEByteEncryptor} as a constructor argument, which can - * be created or retrieved from any part of the jasypt encryption configuration - * infrastructure. - *
- *- * - *
- *- * This class is thread-safe. - *
- * - * @since 1.4 - * @author Daniel Fernández - * - */ -public final class JasyptCryptFactory implements ICryptFactory { - - // Encryptor doesn't need to be instanced each time. We hold a reference. - private final JasyptCrypt jasyptCrypt; - - /** - *- * Creates a new instance of JasyptCryptFactory. - *
- *- * This factory uses an instance of {@link PBEByteEncryptor} instead of - * a {@link PBEStringEncryptor} (as could be expected) because Wicket - * requires a specific type of String encoding (URL and file safe - * BASE64), which is managed by a wicket internal class, and which - * expectes byte[] input. - *
- * - * @param encryptor the PBEByteEncryptor to be used. - */ - public JasyptCryptFactory(final PBEByteEncryptor encryptor) { - this.jasyptCrypt = new JasyptCrypt(encryptor); - } - - - /** - *- * Return a new encryptor object. - *
- *- * This method returns always the same JasyptCrypt object, instead - * of creating a new one. - *
- */ - public ICrypt newCrypt() { - return this.jasyptCrypt; - } - - -} diff -Nru jasypt-1.8/src/main/java/org/jasypt/wicket/JasyptCrypt.java jasypt-1.9.2/src/main/java/org/jasypt/wicket/JasyptCrypt.java --- jasypt-1.8/src/main/java/org/jasypt/wicket/JasyptCrypt.java 2010-10-16 18:38:03.000000000 +0000 +++ jasypt-1.9.2/src/main/java/org/jasypt/wicket/JasyptCrypt.java 1970-01-01 00:00:00.000000000 +0000 @@ -1,120 +0,0 @@ -/* - * ============================================================================= - * - * Copyright (c) 2007-2010, The JASYPT team (http://www.jasypt.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============================================================================= - */ -package org.jasypt.wicket; - -import org.apache.wicket.WicketRuntimeException; -import org.apache.wicket.util.crypt.Base64UrlSafe; -import org.apache.wicket.util.crypt.ICrypt; -import org.jasypt.encryption.pbe.PBEByteEncryptor; - - -/** - *- * Jasypt's implementation of {@link ICrypt}, based on the use of a - * {@link PBEByteEncryptor} object for encryption and decryption operations. - *
- *- * This class is thread-safe. - *
- * - * @since 1.4 - * @author Daniel Fernández - * - */ -public final class JasyptCrypt implements ICrypt { - - // Encoding used to convert java String from and to byte[] - private static final String CHARACTER_ENCODING = "UTF-8"; - - // The wrapped encryptor - private final PBEByteEncryptor encryptor; - - - /** - *- * Creates a new JasyptCrypt object, wrapping the passed - * encryptor. - *
- * - * @param encryptor the PBEByteEncryptor to be used internally. - */ - public JasyptCrypt(final PBEByteEncryptor encryptor) { - this.encryptor = encryptor; - } - - - /** - *- * Decrypts a string using URL and filename safe Base64 decoding. - *
- * - * @param text the text to be decrypted. - * @return the decrypted string. - */ - public String decryptUrlSafe(final String text) { - - try { - final byte[] base64EncryptedBytes = text.getBytes(); - final byte[] encryptedBytes = - Base64UrlSafe.decodeBase64(base64EncryptedBytes); - return new String( - this.encryptor.decrypt(encryptedBytes), CHARACTER_ENCODING); - } catch (Exception e) { - throw new WicketRuntimeException(e); - } - - } - - - /** - *- * Encrypts a string using URL and filename safe Base64 encoding. - *
- * - * @param plainText the text to be encrypted. - * @return encrypted string. - */ - public String encryptUrlSafe(final String plainText) { - - try { - final byte[] plainBytes = plainText.getBytes(CHARACTER_ENCODING); - final byte[] encryptedBytes = this.encryptor.encrypt(plainBytes); - return new String(Base64UrlSafe.encodeBase64(encryptedBytes)); - } catch (Exception e) { - throw new WicketRuntimeException(e); - } - - } - - - /** - *- * Important: Using jasypt, it makes no sense to change the encryption - * key once the encryptor has been initialized, and so this method is - * implemented to throw UnsupportedOperationException always. - *
- */ - public void setKey(final String key) { - throw new UnsupportedOperationException( - "JasyptCrypt encryptors cannot be set password by calling " + - ICrypt.class.getName() + ".setKey()"); - } - -} diff -Nru jasypt-1.8/src/main/javadoc/overview.html jasypt-1.9.2/src/main/javadoc/overview.html --- jasypt-1.8/src/main/javadoc/overview.html 2011-07-23 17:09:02.000000000 +0000 +++ jasypt-1.9.2/src/main/javadoc/overview.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,71 +0,0 @@ - - - -- Direct links to the most popular classes: -
-