Skip to content

Commit

Permalink
Resolve #247 (#313)
Browse files Browse the repository at this point in the history
See #247

Despite the defaults listed in README.md, certain implementations of ConfigContext result in NullPointerExceptions. 

Handling unset values in bare `StandardConfigContext`s needs to be done explicitly because null is not a boolean value at runtime.

* Resolve #247. Handle potentially-NPE-inducing configuration params that have documented defaults

* Use BaseChainedConfigContext.DEFAULT_CONFIG for default values and make DefaultsConfigContext final

* Create constants for default config values

* Use .getClass().equals() instead of instanceof when detecting a DefaultsConfigContext

* Leave DefaultsConfigContext as non-final

* Update CHANGELOG.md
  • Loading branch information
tjcelaya authored Aug 22, 2017
1 parent bcda6b1 commit 836b34a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
This project aims to adhere to [Semantic Versioning](http://semver.org/).

## [3.1.7-SNAPSHOT] - Coming soon!
### Fixed
- NullPointerException as a result of some configuration parameters
[not being handled correctly unless explicity set](https://github.com/joyent/java-manta/issues/247).


## [3.1.6] - 2017-08-15
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.http.HttpEntity;
Expand Down Expand Up @@ -205,7 +206,9 @@ public MantaClient(final ConfigContext config) {
final KeyPair keyPair = keyPairFactory.createKeyPair();

final Signer.Builder builder = new Signer.Builder(keyPair);
if (config.disableNativeSignatures()) {
if (ObjectUtils.firstNonNull(
config.disableNativeSignatures(),
DefaultsConfigContext.DEFAULT_DISABLE_NATIVE_SIGNATURES)) {
builder.providerCode("stdlib");
}
final ThreadLocalSigner signer = new ThreadLocalSigner(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ public byte[] getEncryptionPrivateKeyBytes() {
public void overwriteWithContext(final ConfigContext context) {
/* If a default context is being used to overwrite after this
* context has been initialized, then we want to be careful to not
* overwrite values that have already been set with defaults. */
boolean isDefaultContext = context instanceof DefaultsConfigContext;
* overwrite values that have already been set by non-default contexts. */
boolean isDefaultContext = context.getClass().equals(DefaultsConfigContext.class);

if (isDefaultContext) {
overwriteWithDefaultContext((DefaultsConfigContext)context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public class DefaultsConfigContext implements ConfigContext {
+ "TLS_RSA_WITH_AES_256_CBC_SHA256,"
+ "TLS_RSA_WITH_AES_128_CBC_SHA256";

/**
* HTTP Signatures for authentication are enabled by default.
*/
public static final boolean DEFAULT_NO_AUTH = false;

/**
* Usage of native extensions for http signatures is enabled by default.
*/
public static final boolean DEFAULT_DISABLE_NATIVE_SIGNATURES = false;

/**
* Default number of milliseconds to wait for a TCP socket's connection to
* timeout.
Expand Down Expand Up @@ -174,12 +184,12 @@ public String getHttpsCipherSuites() {

@Override
public Boolean noAuth() {
return false;
return DEFAULT_NO_AUTH;
}

@Override
public Boolean disableNativeSignatures() {
return false;
return DEFAULT_DISABLE_NATIVE_SIGNATURES;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.DynamicMBean;
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.io.Closeable;
import java.io.IOException;
import java.lang.management.ManagementFactory;
Expand All @@ -78,6 +74,10 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import javax.management.DynamicMBean;
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;

/**
* Factory class that creates instances of
Expand Down Expand Up @@ -160,15 +160,12 @@ public MantaConnectionFactory(final ConfigContext config,

// Setup configurator helper

final boolean useNativeCodeToSign;

useNativeCodeToSign = config.disableNativeSignatures() == null
|| !config.disableNativeSignatures();

final HttpSignatureAuthScheme authScheme;

// If we have auth disabled, then we don't assign any signer classes
if (config.noAuth()) {
if (ObjectUtils.firstNonNull(
config.noAuth(),
DefaultsConfigContext.DEFAULT_NO_AUTH)) {
this.signatureConfigurator = null;
authScheme = null;
this.signerThreadLocalRef = new WeakReference<>(null);
Expand Down

0 comments on commit 836b34a

Please sign in to comment.