2020
2121import java .io .File ;
2222import java .io .IOException ;
23+ import java .nio .charset .StandardCharsets ;
24+
25+ import org .slf4j .Logger ;
26+ import org .slf4j .LoggerFactory ;
27+
2328import org .apache .commons .io .FileUtils ;
2429import org .apache .hadoop .classification .VisibleForTesting ;
2530import org .apache .hadoop .conf .Configuration ;
2631import org .apache .hadoop .thirdparty .com .google .common .base .Strings ;
2732import 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