Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dbptk-modules/dbptk-module-ms-access/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
<dependency>
<groupId>io.github.spannm</groupId>
<artifactId>ucanaccess</artifactId>
<version>5.1.3</version>
<version>5.1.8</version>
</dependency>
<dependency>
<groupId>com.healthmarketscience.jackcess</groupId>
<groupId>io.github.spannm</groupId>
<artifactId>jackcess-encrypt</artifactId>
<version>4.0.3</version>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public Parameters getExportModuleParameters() throws UnsupportedModuleException
}

@Override
public DatabaseImportModule buildImportModule(Map<Parameter, String> parameters, Reporter reporter) throws ModuleException {
public DatabaseImportModule buildImportModule(Map<Parameter, String> parameters, Reporter reporter)
throws ModuleException {
String pAccessFilePath = parameters.get(accessFilePath);

String pAccessPassword = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE file at the root of the source
* tree and available online at
*
* https://github.com/keeps/db-preservation-toolkit
*/
package com.databasepreservation.modules.msAccess.in;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

import org.apache.commons.lang3.StringUtils;

import io.github.spannm.jackcess.Database;
import io.github.spannm.jackcess.DatabaseBuilder;
import io.github.spannm.jackcess.DateTimeType;
import io.github.spannm.jackcess.encrypt.CryptCodecProvider;
import net.ucanaccess.jdbc.IJackcessOpenerInterface;

/**
* {@link IJackcessOpenerInterface} implementation that registers a
* {@link CryptCodecProvider} so that password-protected Microsoft Access
* databases (including the AES-encrypted format used by Access 2007+
* {@code .accdb} files) can actually be decoded. UCanAccess itself never wires
* up {@code jackcess-encrypt}, so without a custom opener like this one, any
* password passed to UCanAccess is silently ignored.
*/
public class MsAccessCryptCodecJackcessOpener implements IJackcessOpenerInterface {

@Override
public Database open(File fl, String pwd) throws IOException {
return open(fl, pwd, null);
}

@Override
public Database open(File fl, String pwd, Charset charset) throws IOException {
DatabaseBuilder dbd = new DatabaseBuilder()
.withFile(fl)
.withAutoSync(false)
.withCharset(charset);

if (StringUtils.isNotEmpty(pwd)) {
dbd.withCodecProvider(new CryptCodecProvider(pwd));
}

Database db;
try {
db = dbd.withReadOnly(false).open();
} catch (Exception ex) {
db = dbd.withReadOnly(true).open();
}
db.setDateTimeType(DateTimeType.LOCAL_DATE_TIME);
return db;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public MsAccessUCanAccessImportModule(String moduleName, File msAccessFile, Map<
super("net.ucanaccess.jdbc.UcanaccessDriver",
"jdbc:ucanaccess://" + msAccessFile.getAbsolutePath() + ";showSchema=true;", new MsAccessHelper(),
new MsAccessUCanAccessDatatypeImporter(), moduleName, properties);
this.msAccessFile = msAccessFile;
this.msAccessFile = msAccessFile;
}

public MsAccessUCanAccessImportModule(String moduleName, File msAccessFile, String password) throws ModuleException {
this(moduleName, msAccessFile, MapUtils.buildMapFromObjects(MsAccessUCanAccessModuleFactory.PARAMETER_FILE,
msAccessFile, MsAccessUCanAccessModuleFactory.PARAMETER_PASSWORD, password));
this.password = password;
this.password = password;
}

public MsAccessUCanAccessImportModule(String moduleName, String accessFilePath) throws ModuleException {
Expand All @@ -84,10 +84,12 @@ public MsAccessUCanAccessImportModule(String moduleName, String accessFilePath,

@Override
protected Connection createConnection() throws ModuleException {
UcanaccessConnectionBuilder builder = new UcanaccessConnectionBuilder().withDbPath(msAccessFile).withProp(Property.showSchema, true);
if (StringUtils.isNotEmpty(password)) {
builder.withPassword(password);
}
UcanaccessConnectionBuilder builder = new UcanaccessConnectionBuilder().withDbPath(msAccessFile).withProp(
Property.showSchema, true);
if (StringUtils.isNotEmpty(password)) {
builder.withPassword(password);
builder.withProp(Property.jackcessOpener, MsAccessCryptCodecJackcessOpener.class.getName());
}
return builder.build();
}

Expand Down