55
66package com .microsoft .azure .hdinsight .sdk .storage .adls ;
77
8- import com .microsoft .aad .adal4j .*;
8+ import com .microsoft .aad .msal4j .*;
99import com .microsoft .azure .datalake .store .ADLException ;
1010import com .microsoft .azure .datalake .store .ADLStoreClient ;
1111import com .microsoft .azure .datalake .store .IfExists ;
1212import com .microsoft .azure .hdinsight .common .HDInsightLoader ;
1313import com .microsoft .azure .hdinsight .sdk .common .HDIException ;
14- import com .microsoft .azure .hdinsight .sdk .storage .ADLSCertificateInfo ;
15- import com .microsoft .azure .hdinsight .sdk .storage .ADLSStorageAccount ;
16- import com .microsoft .azure .hdinsight .sdk .storage .IHDIStorageAccount ;
14+ import com .microsoft .azure .hdinsight .sdk .storage .*;
1715import com .microsoft .azuretools .azurecommons .helpers .NotNull ;
1816import org .apache .commons .io .IOUtils ;
1917
2018import java .io .*;
2119import java .net .*;
20+ import java .util .HashSet ;
21+ import java .util .Set ;
2222import java .util .concurrent .ExecutionException ;
2323import java .util .concurrent .ExecutorService ;
2424import java .util .concurrent .Executors ;
2525import java .util .concurrent .Future ;
2626
2727public class WebHDFSUtils {
28+ private static final String STORAGE_RESOURCEID = "https://storage.azure.com/" ;
2829 private static ExecutorService service = null ;
2930
3031 private static String getUserAgent () {
@@ -44,11 +45,17 @@ private static String getAccessTokenFromCertificate(@NotNull ADLSStorageAccount
4445 }
4546
4647 final ADLSCertificateInfo certificateInfo = storageAccount .getCertificateInfo ();
47- AuthenticationContext ctx = new AuthenticationContext (certificateInfo .getAadTenantId (), true , service );
48- AsymmetricKeyCredential asymmetricKeyCredential = AsymmetricKeyCredential .create (certificateInfo .getClientId (), certificateInfo .getKey (), certificateInfo .getCertificate ());
49- final Future <AuthenticationResult > result = ctx .acquireToken (certificateInfo .getResourceUri (), asymmetricKeyCredential , null );
50- final AuthenticationResult ar = result .get ();
51- return ar .getAccessToken ();
48+
49+ IClientCredential credential = ClientCredentialFactory .createFromCertificate (certificateInfo .getKey (),certificateInfo .getCertificate ());
50+
51+ ConfidentialClientApplication app = ConfidentialClientApplication
52+ .builder (certificateInfo .getClientId (),credential )
53+ .build ();
54+
55+ Set <String > scopes = new HashSet <>();
56+ scopes .add (STORAGE_RESOURCEID + "/.default" );
57+ IAuthenticationResult iAuthenticationResult = app .acquireToken (ClientCredentialParameters .builder (scopes ).build ()).get ();
58+ return iAuthenticationResult .accessToken ();
5259 }
5360
5461 public static void uploadFileToADLS (@ NotNull IHDIStorageAccount storageAccount , @ NotNull File localFile , @ NotNull String remotePath , boolean overWrite ) throws Exception {
0 commit comments