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
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
package org.apache.hadoop.hbase.io.crypto;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.io.crypto.aes.CommonsCryptoAES;
import org.apache.yetus.audience.InterfaceAudience;

import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;

/**
* The default cipher provider. Supports AES via the Commons Crypto.
*/
Expand All @@ -30,6 +32,7 @@ public final class CryptoCipherProvider implements CipherProvider {

private static CryptoCipherProvider instance;

@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.UNITTEST)
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
justification = "singleton pattern")
public static CryptoCipherProvider getInstance() {
Expand All @@ -40,14 +43,16 @@ public static CryptoCipherProvider getInstance() {
return instance;
}

private Configuration conf = HBaseConfiguration.create();
private Configuration conf; // set via setConf() before use

// Prevent instantiation
private CryptoCipherProvider() {
}

@Override
public Configuration getConf() {
Preconditions.checkState(conf != null,
"Configuration not set; call setConf() before using this provider");
return conf;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
package org.apache.hadoop.hbase.io.crypto;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.io.crypto.aes.AES;
import org.apache.yetus.audience.InterfaceAudience;

import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;

/**
* The default cipher provider. Supports AES via the JCE.
*/
Expand All @@ -30,6 +32,7 @@ public final class DefaultCipherProvider implements CipherProvider {

private static DefaultCipherProvider instance;

@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.UNITTEST)
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
justification = "singleton pattern")
public static DefaultCipherProvider getInstance() {
Expand All @@ -40,14 +43,16 @@ public static DefaultCipherProvider getInstance() {
return instance;
}

private Configuration conf = HBaseConfiguration.create();
private Configuration conf; // set via setConf() before use

// Prevent instantiation
private DefaultCipherProvider() {
}

@Override
public Configuration getConf() {
Preconditions.checkState(conf != null,
"Configuration not set; call setConf() before using this provider");
return conf;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
Expand Down Expand Up @@ -153,4 +154,20 @@ public void testDefaultProvider() {
assertEquals(AES.KEY_LENGTH, a.getKeyLength());
}

@Test
public void testDefaultProviderGetConfWithoutConf() {
// The singleton no longer eagerly parses a Configuration at construction; getConf() must fail
// loudly when called before setConf() rather than NPE-ing deep inside cipher construction.
DefaultCipherProvider provider = DefaultCipherProvider.getInstance();
provider.setConf(null);
assertThrows(IllegalStateException.class, provider::getConf);
}

@Test
public void testCryptoProviderGetConfWithoutConf() {
CryptoCipherProvider provider = CryptoCipherProvider.getInstance();
provider.setConf(null);
assertThrows(IllegalStateException.class, provider::getConf);
}

}