Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1D68F200B6D for ; Tue, 23 Aug 2016 11:31:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1C0A1160AAD; Tue, 23 Aug 2016 09:31:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3C014160AA5 for ; Tue, 23 Aug 2016 11:31:36 +0200 (CEST) Received: (qmail 39730 invoked by uid 500); 23 Aug 2016 09:31:35 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 39721 invoked by uid 99); 23 Aug 2016 09:31:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Aug 2016 09:31:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3DC51DFCC0; Tue, 23 Aug 2016 09:31:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: shimingfei@apache.org To: common-commits@hadoop.apache.org Message-Id: <585e213cebeb4c178e1380094ca91553@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HADOOP-13499. Support session credentials for authenticating with Aliyun. Contributed by Genmao Yu. Date: Tue, 23 Aug 2016 09:31:35 +0000 (UTC) archived-at: Tue, 23 Aug 2016 09:31:37 -0000 Repository: hadoop Updated Branches: refs/heads/HADOOP-12756 2e713ed9f -> 787750d1f 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/787750d1 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/787750d1 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/787750d1 Branch: refs/heads/HADOOP-12756 Commit: 787750d1ffe5045508a32f69691d13e82565f109 Parents: 2e713ed Author: Mingfei Authored: Tue Aug 23 17:10:00 2016 +0800 Committer: Mingfei Committed: Tue Aug 23 17:10:00 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/787750d1/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/787750d1/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/787750d1/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