10000 Added support for BasicSessionCredentials by martoc · Pull Request #211 · apache/hadoop · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added support for BasicSessionCredentials #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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 org.apache.commons.lang.StringUtils;

import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.BasicSessionCredentials;

/**
* Support session credentials for authenticating with AWS.
*
*/
public class BasicSessionAWSCredentialsProvider implements AWSCredentialsProvider {
private final String accessKey;
private final String secretKey;
private final String sessionToken;

public BasicSessionAWSCredentialsProvider(String accessKey, String secretKey, String sessionToken) {
this.accessKey = accessKey;
this.secretKey = secretKey;
this.sessionToken = sessionToken;
}

public AWSCredentials getCredentials() {
if (!StringUtils.isEmpty(accessKey) && !StringUtils.isEmpty(secretKey) && !StringUtils.isEmpty(sessionToken)) {
return new BasicSessionCredentials(accessKey, secretKey, sessionToken);
}
throw new AmazonClientException(
"Access key or secret or session token key is null");
}

public void refresh() {}

@Override
public String toString() {
return getClass().getSimpleName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class Constants {
// s3 secret key
public static final String SECRET_KEY = "fs.s3a.secret.key";

// s3 session token
public static final String SESSION_TOKEN = "fs.s3a.session.token";

// number of simultaneous connections to s3
public static final String MAXIMUM_CONNECTIONS = "fs.s3a.connection.maximum";
public static final int DEFAULT_MAXIMUM_CONNECTIONS = 15;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public void initialize(URI name, Configuration conf) throws IOException {
// Try to get our credentials or just connect anonymously
String accessKey = conf.get(ACCESS_KEY, null);
String secretKey = conf.get(SECRET_KEY, null);
String sessionToken = conf.get(SESSION_TOKEN, null);

String userInfo = name.getUserInfo();
if (userInfo != null) {
Expand All @@ -172,6 +173,7 @@ public void initialize(URI name, Configuration conf) throws IOException {
}

AWSCredentialsProviderChain credentials = new AWSCredentialsProviderChain(
new BasicSessionAWSCredentialsProvider(accessKey, secretKey, sessionToken),
new BasicAWSCredentialsProvider(accessKey, secretKey),
new InstanceProfileCredentialsProvider(),
new AnonymousAWSCredentialsProvider()
Expand Down
0