Author: kmarsden
Date: Thu May 10 12:23:14 2007
New Revision: 536972
URL: http://svn.apache.org/viewvc?view=rev&rev=536972
Log:
DERBY-2555 backout change until tinderbox failures are resolved.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/EncryptionKeyTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/EncryptionKeyTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/EncryptionKeyTest.java?view=diff&rev=536972&r1=536971&r2=536972
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/EncryptionKeyTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/EncryptionKeyTest.java
Thu May 10 12:23:14 2007
@@ -276,7 +276,7 @@
shutdown(dbName);
// Create a new database from backup.
String dbNameRestored = dbName + "Restored";
- con = getConnection(dbNameRestored, CORRECT_KEY,
+ con = getPrivilegedConnection(dbNameRestored, CORRECT_KEY,
"createFrom=" + backupDbLocation);
validateDBContents(con);
con.close();
@@ -284,7 +284,7 @@
// Try to create a new database from backup with the wrong key.
dbNameRestored = dbName + "RestoreAttemptedWrongKey";
try {
- con = getConnection(dbNameRestored, WRONG_KEY,
+ con = getPrivilegedConnection(dbNameRestored, WRONG_KEY,
"createFrom=" + backupDbLocation);
fail("Created database from encrypted backup with wrong key.");
} catch (SQLException sqle) {
@@ -295,7 +295,7 @@
// Try to create a new database from backup with an invalid key.
dbNameRestored = dbName + "RestoreAttemptedInvalidKey";
try {
- con = getConnection(dbNameRestored, INVALID_CHAR_KEY,
+ con = getPrivilegedConnection(dbNameRestored, INVALID_CHAR_KEY,
"createFrom=" + backupDbLocation);
fail("Created database from encrypted backup with an invalid key.");
} catch (SQLException sqle) {
@@ -306,7 +306,7 @@
// Try to create a new database from backup with an odd length key.
dbNameRestored = dbName + "RestoreAttemptedOddLengthKey";
try {
- con = getConnection(dbNameRestored, ODD_LENGTH_KEY,
+ con = getPrivilegedConnection(dbNameRestored, ODD_LENGTH_KEY,
"createFrom=" + backupDbLocation);
fail("Created db from encrypted backup with an odd length key.");
} catch (SQLException sqle) {
@@ -332,7 +332,7 @@
assertTrue(con.isClosed());
// Create a new database from backup again.
dbNameRestored = dbName + "RestoredOnceMore";
- con = getConnection(dbNameRestored, CORRECT_KEY,
+ con = getPrivilegedConnection(dbNameRestored, CORRECT_KEY,
"createFrom=" + backupDbLocation);
validateDBContents(con);
con.close();
@@ -376,7 +376,7 @@
// the existing database we are trying to restore to/into. This is
// expected behavior currently, but should maybe change?
try {
- con = getConnection(dbNameRestored, INVALID_CHAR_KEY,
+ con = getPrivilegedConnection(dbNameRestored, INVALID_CHAR_KEY,
";restoreFrom=" + obtainDbName(dbName, null));
fail("Restored database with an invalid key.");
} catch (SQLException sqle) {
@@ -486,7 +486,7 @@
shutdown(sourceDb);
confirmNonBootedDB(sourceDb);
// Use the restoreFrom attribute.
- con = getConnection(targetDb, CORRECT_KEY,
+ con = getPrivilegedConnection(targetDb, CORRECT_KEY,
";restoreFrom=" + obtainDbName(sourceDb, "backups"));
validateDBContents(con);
con.close();
@@ -524,6 +524,39 @@
}
/**
+ * Try to establish a connection to the named database with the
+ * specified type of key and recovery mode.
+ * <p>
+ * The connection is made in a privileged block of code to allow Derby to
+ * read the database backup used for recovery.
+ *
+ * @param dbName name of the database
+ * @param keyMode what kind of key to use (correct, wrong, invalid, odd)
+ * @param recoveryAttribute attribute to recover a database from a backup,
+ * for instance <code>createFrom</code> or <code>restoreFrom</code>.
+ * Both the attribute and its value is expected.
+ * @return A connection to the database.
+ * @throws SQLException if connection fails
+ */
+ private Connection getPrivilegedConnection(final String dbName,
+ final int keyMode,
+ final String recoveryAttribute)
+ throws SQLException {
+ try {
+ return (Connection)AccessController.doPrivileged(
+ new PrivilegedExceptionAction() {
+ public Object run()
+ throws SQLException {
+ return getConnection(dbName, keyMode,
+ recoveryAttribute);
+ }
+ });
+ } catch (PrivilegedActionException pae) {
+ throw (SQLException)pae.getException();
+ }
+ }
+
+ /**
* Create a new connection to the specified database, using the given
* connection attributes.
*
@@ -577,8 +610,7 @@
str.append(";");
JDBCDataSource.setBeanProperty(
ds, "connectionAttributes", str.toString());
- return ds.getConnection();
-
+ return ds.getConnection();
}
/**
|