Skip to content

Commit e368af4

Browse files
committed
Address Review comments
1 parent dee5a7d commit e368af4

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/oauth2/WorkloadIdentityTokenProvider.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020

2121
import java.io.File;
2222
import java.io.IOException;
23+
import java.nio.charset.StandardCharsets;
24+
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
2328
import org.apache.commons.io.FileUtils;
2429
import org.apache.hadoop.classification.VisibleForTesting;
2530
import org.apache.hadoop.conf.Configuration;
2631
import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
2732
import org.apache.hadoop.util.Preconditions;
28-
import org.slf4j.Logger;
29-
import org.slf4j.LoggerFactory;
33+
34+
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.EMPTY_STRING;
3035

3136
/**
3237
* Provides tokens based on Azure AD Workload Identity.
@@ -45,7 +50,7 @@ public class WorkloadIdentityTokenProvider extends AccessTokenProvider {
4550
private static class FileBasedClientAssertionProvider implements ClientAssertionProvider {
4651
private final String tokenFile;
4752

48-
public FileBasedClientAssertionProvider(String tokenFile) {
53+
FileBasedClientAssertionProvider(String tokenFile) {
4954
this.tokenFile = tokenFile;
5055
}
5156

@@ -56,13 +61,14 @@ public void initialize(Configuration configuration, String accountName) throws I
5661

5762
@Override
5863
public String getClientAssertion() throws IOException {
59-
String clientAssertion = "";
64+
String clientAssertion = EMPTY_STRING;
6065
try {
6166
File file = new File(tokenFile);
62-
clientAssertion = FileUtils.readFileToString(file, "UTF-8");
67+
clientAssertion = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
6368
} catch (Exception e) {
6469
throw new IOException(TOKEN_FILE_READ_ERROR + tokenFile, e);
6570
}
71+
clientAssertion = clientAssertion.trim();
6672
if (Strings.isNullOrEmpty(clientAssertion)) {
6773
throw new IOException(EMPTY_TOKEN_FILE_ERROR + tokenFile);
6874
}

0 commit comments

Comments
 (0)