You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by dr...@apache.org on 2016/10/10 21:31:49 UTC
[07/23] hadoop git commit: HADOOP-13499. Support session credentials
for authenticating with Aliyun. Contributed by Genmao Yu.
HADOOP-13499. Support session credentials for authenticating with Aliyun. Contributed by Genmao Yu.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/6bb741b9
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/6bb741b9
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/6bb741b9
Branch: refs/heads/trunk
Commit: 6bb741b9f811d3a1c0ce4ecc91a78ac47513bb8e
Parents: bd2d97a
Author: Mingfei <mi...@intel.com>
Authored: Tue Aug 23 17:10:00 2016 +0800
Committer: Mingfei <mi...@intel.com>
Committed: Wed Sep 7 11:15:48 2016 +0800
----------------------------------------------------------------------
.../apache/hadoop/fs/aliyun/oss/Constants.java | 5 +-
.../oss/TemporaryAliyunCredentialsProvider.java | 64 ++++++++++++++++++++
.../aliyun/oss/TestOSSTemporaryCredentials.java | 64 ++++++++++++++++++++
3 files changed, 131 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/6bb741b9/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java
index 4ee4cd4..0bc6d57 100644
--- a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java
+++ b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/Constants.java
@@ -31,8 +31,9 @@ public final class Constants {
"fs.oss.credentials.provider";
// OSS access verification
- public static final String ACCESS_KEY = "fs.oss.access.key";
- public static final String SECRET_KEY = "fs.oss.secret.key";
+ public static final String ACCESS_KEY = "fs.oss.accessKeyId";
+ public static final String SECRET_KEY = "fs.oss.accessKeySecret";
+ public static final String SECURITY_TOKEN = "fs.oss.securityToken";
// Number of simultaneous connections to oss
public static final String MAXIMUM_CONNECTIONS_KEY =
http://git-wip-us.apache.org/repos/asf/hadoop/blob/6bb741b9/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/TemporaryAliyunCredentialsProvider.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/TemporaryAliyunCredentialsProvider.java b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/TemporaryAliyunCredentialsProvider.java
new file mode 100644
index 0000000..ec8e7fe
--- /dev/null
+++ b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/TemporaryAliyunCredentialsProvider.java
@@ -0,0 +1,64 @@
+/**
+ * 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.aliyun.oss;
+
+import com.aliyun.oss.common.auth.Credentials;
+import com.aliyun.oss.common.auth.CredentialsProvider;
+import com.aliyun.oss.common.auth.DefaultCredentials;
+import com.aliyun.oss.common.auth.InvalidCredentialsException;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.conf.Configuration;
+
+import java.net.URI;
+
+import static org.apache.hadoop.fs.aliyun.oss.Constants.*;
+
+/**
+ * Support session credentials for authenticating with ALiyun.
+ */
+public class TemporaryAliyunCredentialsProvider implements CredentialsProvider {
+ public static final String NAME
+ = "org.apache.hadoop.fs.aliyun.oss.TemporaryAliyunCredentialsProvider";
+ private final String accessKeyId;
+ private final String accessKeySecret;
+ private final String securityToken;
+
+ public TemporaryAliyunCredentialsProvider(URI uri, Configuration conf) {
+ this.accessKeyId = conf.get(ACCESS_KEY, null);
+ this.accessKeySecret = conf.get(SECRET_KEY, null);
+ this.securityToken = conf.get(SECURITY_TOKEN, null);
+ }
+
+ @Override
+ public void setCredentials(Credentials creds) {
+
+ }
+
+ @Override
+ public Credentials getCredentials() {
+ if (!StringUtils.isEmpty(accessKeyId)
+ && !StringUtils.isEmpty(accessKeySecret)
+ && !StringUtils.isEmpty(securityToken)) {
+ return new DefaultCredentials(accessKeyId, accessKeySecret,
+ securityToken);
+ }
+ throw new InvalidCredentialsException(
+ "AccessKeyId, AccessKeySecret or SecurityToken is unset");
+ }
+}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/6bb741b9/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestOSSTemporaryCredentials.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestOSSTemporaryCredentials.java b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestOSSTemporaryCredentials.java
new file mode 100644
index 0000000..ca2c0bc
--- /dev/null
+++ b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestOSSTemporaryCredentials.java
@@ -0,0 +1,64 @@
+/**
+ * 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.aliyun.oss;
+
+import com.aliyun.oss.common.auth.Credentials;
+import com.aliyun.oss.common.auth.InvalidCredentialsException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.aliyun.oss.contract.OSSContract;
+import org.apache.hadoop.fs.contract.AbstractFSContract;
+import org.apache.hadoop.fs.contract.AbstractFSContractTestBase;
+import org.junit.Test;
+
+import java.net.URI;
+
+import static org.apache.hadoop.fs.aliyun.oss.Constants.ACCESS_KEY;
+import static org.apache.hadoop.fs.aliyun.oss.Constants.SECRET_KEY;
+import static org.apache.hadoop.fs.aliyun.oss.Constants.SECURITY_TOKEN;
+
+/**
+ * Tests use of temporary credentials (for example, Aliyun STS & Aliyun OSS).
+ * This test extends a class that "does things to the root directory", and
+ * should only be used against transient filesystems where you don't care about
+ * the data.
+ */
+public class TestOSSTemporaryCredentials extends AbstractFSContractTestBase {
+
+ @Override
+ protected AbstractFSContract createContract(Configuration conf) {
+ return new OSSContract(conf);
+ }
+
+ @Test
+ public void testTemporaryCredentialValidation() throws Throwable {
+ Configuration conf = new Configuration();
+ conf.set(ACCESS_KEY, "accessKeyId");
+ conf.set(SECRET_KEY, "accessKeySecret");
+ conf.set(SECURITY_TOKEN, "");
+ URI uri = getFileSystem().getUri();
+ TemporaryAliyunCredentialsProvider provider
+ = new TemporaryAliyunCredentialsProvider(uri, conf);
+ try {
+ Credentials credentials = provider.getCredentials();
+ fail("Expected a CredentialInitializationException, got " + credentials);
+ } catch (InvalidCredentialsException expected) {
+ // expected
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org