Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.amazonaws.SdkBaseException;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
import com.amazonaws.auth.Signer;
import com.amazonaws.auth.SignerFactory;
import com.amazonaws.retry.RetryUtils;
import com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException;
import com.amazonaws.services.dynamodbv2.model.LimitExceededException;
Expand Down Expand Up @@ -1239,7 +1241,22 @@ public static void initConnectionSettings(Configuration conf,
awsConf.setSocketBufferSizeHints(sockSendBuffer, sockRecvBuffer);
String signerOverride = conf.getTrimmed(SIGNING_ALGORITHM, "");
if (!signerOverride.isEmpty()) {
LOG.debug("Signer override = {}", signerOverride);
try {
SignerFactory.getSignerByTypeAndService(signerOverride, null);
} catch (IllegalArgumentException e) {
LOG.debug("{}, preparing to load custom signer : {} ",
e.getMessage(), signerOverride);
Class<? extends Signer> klass;
try {
klass = (Class<? extends Signer>) Class.forName(signerOverride);
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException(
String.format("Signer Class %s not found",
signerOverride), cnfe);
}
SignerFactory.registerSigner(signerOverride, klass);
}
LOG.debug("Signer override = {}", signerOverride);
awsConf.setSignerOverride(signerOverride);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,11 @@ public interface S3ATestConstants {
*/
String S3GUARD_DDB_TEST_TABLE_NAME_KEY =
"fs.s3a.s3guard.ddb.test.table";


/**
* Custom Signer Name to be set in the conf for Test
*/
String S3A_SIGNING_ALGORITHM = "com.amazonaws.services.s3.internal.AWSS3V4Signer";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.fs.s3a;

import com.amazonaws.ClientConfiguration;
import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
import org.junit.Test;

import java.util.Objects;


/**
* Test whether or not Custom Signing Algorithm Override works by turning it on.
*/
public class TestS3ASigningAlgorithmOverride extends AbstractS3ATestBase {

@Override
protected Configuration createConfiguration() {
// awsConf is instantiated here
Configuration conf = super.createConfiguration();
conf.set(Constants.SIGNING_ALGORITHM,
S3ATestConstants.S3A_SIGNING_ALGORITHM);
return conf;
}

@Test
public void testCustomSignerOverride() throws AssertionError {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a testing principle in your test: Arrange, Act, Assert - http://wiki.c2.com/?ArrangeActAssert

assertIsCustomSignerLoaded();
}

private void assertIsCustomSignerLoaded() {
final ClientConfiguration awsConf = new ClientConfiguration();
Assert.assertEquals(awsConf.getSignerOverride(),
S3ATestConstants.S3A_SIGNING_ALGORITHM);
}
}