Skip to content

Commit cbdf6e6

Browse files
authored
Merge pull request #7676 from microsoft/users/v-shufeng/adal2msal
ADAL to MSAL Migration
2 parents 371ccbe + 3cc0c86 commit cbdf6e6

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

Utils/hdinsight-node-common/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,6 @@
476476
<artifactId>spark-localrun-mock</artifactId>
477477
<version>0.1.1</version>
478478
</dependency>
479-
<dependency>
480-
<groupId>com.microsoft.azure</groupId>
481-
<artifactId>adal4j</artifactId>
482-
</dependency>
483479
<dependency>
484480
<groupId>com.azure.resourcemanager</groupId>
485481
<artifactId>azure-resourcemanager-hdinsight</artifactId>

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/sdk/storage/adls/WebHDFSUtils.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@
55

66
package com.microsoft.azure.hdinsight.sdk.storage.adls;
77

8-
import com.microsoft.aad.adal4j.*;
8+
import com.microsoft.aad.msal4j.*;
99
import com.microsoft.azure.datalake.store.ADLException;
1010
import com.microsoft.azure.datalake.store.ADLStoreClient;
1111
import com.microsoft.azure.datalake.store.IfExists;
1212
import com.microsoft.azure.hdinsight.common.HDInsightLoader;
1313
import 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.*;
1715
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
1816
import org.apache.commons.io.IOUtils;
1917

2018
import java.io.*;
2119
import java.net.*;
20+
import java.util.HashSet;
21+
import java.util.Set;
2222
import java.util.concurrent.ExecutionException;
2323
import java.util.concurrent.ExecutorService;
2424
import java.util.concurrent.Executors;
2525
import java.util.concurrent.Future;
2626

2727
public 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

Comments
 (0)