Skip to content

Instantly share code, notes, and snippets.

@stliu
Created November 26, 2012 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stliu/4147126 to your computer and use it in GitHub Desktop.
Save stliu/4147126 to your computer and use it in GitHub Desktop.
Index: src/main/java/org/jasypt/hibernate4/connectionprovider/EncryptedPasswordC3P0ConnectionProvider.java
===================================================================
--- src/main/java/org/jasypt/hibernate4/connectionprovider/EncryptedPasswordC3P0ConnectionProvider.java (revision 609)
+++ src/main/java/org/jasypt/hibernate4/connectionprovider/EncryptedPasswordC3P0ConnectionProvider.java (working copy)
@@ -19,6 +19,7 @@
*/
package org.jasypt.hibernate4.connectionprovider;
+import java.util.Map;
import java.util.Properties;
import org.hibernate.cfg.AvailableSettings;
@@ -94,58 +95,51 @@
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(AvailableSettings.DRIVER);
- final String url = props.getProperty(AvailableSettings.URL);
- final String user = props.getProperty(AvailableSettings.USER);
- final String password = props.getProperty(AvailableSettings.PASS);
+ public void configure(Map props) {
+ final String encryptorRegisteredName =
+ (String)props.get(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
- // Perform decryption operations as needed and store the new values
- if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
- props.setProperty(
- AvailableSettings.DRIVER,
- PropertyValueEncryptionUtils.decrypt(driver, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
- props.setProperty(
- AvailableSettings.URL,
- PropertyValueEncryptionUtils.decrypt(url, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
- props.setProperty(
- AvailableSettings.USER,
- PropertyValueEncryptionUtils.decrypt(user, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
- props.setProperty(
- AvailableSettings.PASS,
- PropertyValueEncryptionUtils.decrypt(password, encryptor));
- }
-
- // Let Hibernate do the rest
- super.configure(props);
-
- }
+ 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 = (String)props.get(AvailableSettings.DRIVER);
+ final String url = (String)props.get(AvailableSettings.URL);
+ final String user = (String)props.get(AvailableSettings.USER);
+ final String password = (String)props.get(AvailableSettings.PASS);
+
+ // Perform decryption operations as needed and store the new values
+ if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
+ props.put(
+ AvailableSettings.DRIVER,
+ PropertyValueEncryptionUtils.decrypt(driver, encryptor));
+ }
+ if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
+ props.put(
+ AvailableSettings.URL,
+ PropertyValueEncryptionUtils.decrypt(url, encryptor));
+ }
+ if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
+ props.put(
+ AvailableSettings.USER,
+ PropertyValueEncryptionUtils.decrypt(user, encryptor));
+ }
+ if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
+ props.put(
+ AvailableSettings.PASS,
+ PropertyValueEncryptionUtils.decrypt(password, encryptor));
+ }
+
+ // Let Hibernate do the rest
+ super.configure(props);
+ }
}
Index: src/main/java/org/jasypt/hibernate4/connectionprovider/EncryptedPasswordDriverManagerConnectionProvider.java
===================================================================
--- src/main/java/org/jasypt/hibernate4/connectionprovider/EncryptedPasswordDriverManagerConnectionProvider.java (revision 609)
+++ src/main/java/org/jasypt/hibernate4/connectionprovider/EncryptedPasswordDriverManagerConnectionProvider.java (working copy)
@@ -19,6 +19,7 @@
*/
package org.jasypt.hibernate4.connectionprovider;
+import java.util.Map;
import java.util.Properties;
import org.hibernate.cfg.AvailableSettings;
@@ -92,57 +93,53 @@
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 + "\"");
- }
+ public void configure(Map props) {
+ final String encryptorRegisteredName =
+ (String)props.get(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
- // Get the original values, which may be encrypted
- final String driver = props.getProperty(AvailableSettings.DRIVER);
- final String url = props.getProperty(AvailableSettings.URL);
- final String user = props.getProperty(AvailableSettings.USER);
- final String password = props.getProperty(AvailableSettings.PASS);
+ final HibernatePBEEncryptorRegistry encryptorRegistry =
+ HibernatePBEEncryptorRegistry.getInstance();
+ final PBEStringEncryptor encryptor =
+ encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
- // Perform decryption operations as needed and store the new values
- if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
- props.setProperty(
- AvailableSettings.DRIVER,
- PropertyValueEncryptionUtils.decrypt(driver, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
- props.setProperty(
- AvailableSettings.URL,
- PropertyValueEncryptionUtils.decrypt(url, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
- props.setProperty(
- AvailableSettings.USER,
- PropertyValueEncryptionUtils.decrypt(user, encryptor));
- }
- if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
- props.setProperty(
- AvailableSettings.PASS,
- PropertyValueEncryptionUtils.decrypt(password, encryptor));
- }
-
- // Let Hibernate process
- super.configure(props);
-
- }
+ 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 = (String)props.get(AvailableSettings.DRIVER);
+ final String url = (String)props.get(AvailableSettings.URL);
+ final String user = (String)props.get(AvailableSettings.USER);
+ final String password = (String)props.get(AvailableSettings.PASS);
+
+ // Perform decryption operations as needed and store the new values
+ if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
+ props.put(
+ AvailableSettings.DRIVER,
+ PropertyValueEncryptionUtils.decrypt(driver, encryptor));
+ }
+ if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
+ props.put(
+ AvailableSettings.URL,
+ PropertyValueEncryptionUtils.decrypt(url, encryptor));
+ }
+ if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
+ props.put(
+ AvailableSettings.USER,
+ PropertyValueEncryptionUtils.decrypt(user, encryptor));
+ }
+ if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
+ props.put(
+ AvailableSettings.PASS,
+ PropertyValueEncryptionUtils.decrypt(password, encryptor));
+ }
+
+ // Let Hibernate process
+ super.configure(props);
+ }
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment