From dcf2f79d8dae25e5dce29f6c8f132f60f0a52de4 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Wed, 12 Aug 2020 16:33:34 -0700 Subject: [PATCH] Fix compilation errors after merging from master --- .../sqlserver/jdbc/fedauth/FedauthCommon.java | 30 ++++++++--- .../sqlserver/jdbc/fedauth/FedauthWithAE.java | 53 ++++++++----------- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java index 675fa4341..cca7fc12d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java @@ -7,22 +7,24 @@ import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import com.microsoft.aad.msal4j.IAuthenticationResult; +import com.microsoft.aad.msal4j.PublicClientApplication; +import com.microsoft.aad.msal4j.UserNamePasswordParameters; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Locale; +import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import java.util.logging.LogManager; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; -import com.microsoft.aad.adal4j.AuthenticationContext; -import com.microsoft.aad.adal4j.AuthenticationResult; import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.TestResource; @@ -142,11 +144,23 @@ public static void getConfigs() throws Exception { */ static void getFedauthInfo() { try { - AuthenticationContext context = new AuthenticationContext(stsurl, false, Executors.newFixedThreadPool(1)); - Future future = context.acquireToken(spn, fedauthClientId, azureUserName, - azurePassword, null); - secondsBeforeExpiration = future.get().getExpiresAfter(); - accessToken = future.get().getAccessToken(); + + final PublicClientApplication clientApplication = PublicClientApplication + .builder(fedauthClientId) + .executorService(Executors.newFixedThreadPool(1)) + .authority(stsurl) + .build(); + final CompletableFuture future = clientApplication.acquireToken( + UserNamePasswordParameters.builder( + Set.of(spn + "/.default"), + azureUserName, + azurePassword.toCharArray() + ).build()); + + final IAuthenticationResult authenticationResult = future.get(); + + secondsBeforeExpiration = authenticationResult.expiresOnDate().getTime(); + accessToken = authenticationResult.accessToken(); } catch (Exception e) { fail(e.getMessage()); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java index 65f1c2ac0..8c71fa847 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthWithAE.java @@ -15,9 +15,6 @@ import java.sql.Statement; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -26,9 +23,6 @@ import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; -import com.microsoft.aad.adal4j.AuthenticationContext; -import com.microsoft.aad.adal4j.AuthenticationResult; -import com.microsoft.aad.adal4j.ClientCredential; import com.microsoft.sqlserver.jdbc.RandomUtil; import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider; import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider; @@ -36,7 +30,6 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; import com.microsoft.sqlserver.jdbc.SQLServerException; -import com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.Constants; @@ -128,7 +121,7 @@ public void testFedAuthWithAE_AKV() throws SQLException { dropCMK(stmt, cmkName3); setupCMK_AKVOld(cmkName3, stmt); - createCEK(cmkName3, setupKeyStoreProvider_AKVOld(), stmt, keyIDs[0]); + createCEK(cmkName3, setupKeyStoreProvider_AKVNew(), stmt, keyIDs[0]); createCharTable(stmt, charTableOld); populateCharNormalCase(charValues, connection, charTableOld); @@ -304,30 +297,30 @@ private SQLServerColumnEncryptionKeyStoreProvider setupKeyStoreProvider_JKS() th private SQLServerColumnEncryptionKeyStoreProvider setupKeyStoreProvider_AKVNew() throws SQLServerException { SQLServerConnection.unregisterColumnEncryptionKeyStoreProviders(); return registerAKVProvider( - new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID, applicationKey)); + new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID, applicationKey, tenantID)); } - private SQLServerColumnEncryptionKeyStoreProvider setupKeyStoreProvider_AKVOld() throws SQLServerException { - ExecutorService service = Executors.newFixedThreadPool(2); - SQLServerKeyVaultAuthenticationCallback authenticationCallback = new SQLServerKeyVaultAuthenticationCallback() { - @Override - public String getAccessToken(String authority, String resource, String scope) { - AuthenticationResult result = null; - try { - AuthenticationContext context = new AuthenticationContext(authority, false, service); - ClientCredential cred = new ClientCredential(applicationClientID, applicationKey); - - Future future = context.acquireToken(resource, cred, null); - result = future.get(); - return result.getAccessToken(); - } catch (Exception e) { - fail(e.getMessage()); - return null; - } - } - }; - return new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback); - } +// private SQLServerColumnEncryptionKeyStoreProvider setupKeyStoreProvider_AKVOld() throws SQLServerException { +// ExecutorService service = Executors.newFixedThreadPool(2); +// SQLServerKeyVaultAuthenticationCallback authenticationCallback = new SQLServerKeyVaultAuthenticationCallback() { +// @Override +// public String getAccessToken(String authority, String resource, String scope) { +// AuthenticationResult result = null; +// try { +// AuthenticationContext context = new AuthenticationContext(authority, false, service); +// ClientCredential cred = new ClientCredential(applicationClientID, applicationKey); +// +// Future future = context.acquireToken(resource, cred, null); +// result = future.get(); +// return result.getAccessToken(); +// } catch (Exception e) { +// fail(e.getMessage()); +// return null; +// } +// } +// }; +// return new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback); +// } private SQLServerColumnEncryptionKeyStoreProvider registerAKVProvider( SQLServerColumnEncryptionKeyStoreProvider provider) throws SQLServerException {