From 7ff97dee94ec4144ef22e5d12ba76f1a84ebe3c9 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 9 Sep 2020 16:20:13 -0700 Subject: [PATCH 01/10] enable ADintegrated tests for non-windows --- .../sqlserver/jdbc/SQLServerADAL4JUtils.java | 31 +++++++++++-------- .../sqlserver/jdbc/SQLServerResource.java | 2 +- .../jdbc/fedauth/ConcurrentLoginTest.java | 2 +- .../fedauth/ConnectionSuspensionTest.java | 4 +-- .../jdbc/fedauth/ErrorMessageTest.java | 23 +++++++------- .../sqlserver/jdbc/fedauth/FedauthCommon.java | 2 +- .../sqlserver/jdbc/fedauth/FedauthTest.java | 6 ++-- .../jdbc/fedauth/PooledConnectionTest.java | 4 +-- 8 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java index a94ca3cc5..7767a0fb2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerADAL4JUtils.java @@ -41,25 +41,30 @@ static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo, String use return new SqlFedAuthToken(authenticationResult.getAccessToken(), authenticationResult.getExpiresOnDate()); } catch (MalformedURLException | InterruptedException e) { throw new SQLServerException(e.getMessage(), e); - } catch (ExecutionException e) { + } catch (Exception e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution")); - Object[] msgArgs = {user, authenticationString}; + Object[] msgArgs = {user, authenticationString, e.getMessage()}; /* * the cause error message uses \\n\\r which does not give correct format change it to \r\n to provide * correct format */ - String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n"); - AuthenticationException correctedAuthenticationException = new AuthenticationException( - correctedErrorMessage); + if (null == e.getCause() || null == e.getCause().getMessage()) { + throw new SQLServerException(form.format(msgArgs), null); + } else { + String correctedErrorMessage = e.getCause().getMessage().replaceAll("\\\\r\\\\n", "\r\n"); + AuthenticationException correctedAuthenticationException = new AuthenticationException( + correctedErrorMessage); - /* - * SQLServerException is caused by ExecutionException, which is caused by AuthenticationException to match - * the exception tree before error message correction - */ - ExecutionException correctedExecutionException = new ExecutionException(correctedAuthenticationException); + /* + * SQLServerException is caused by ExecutionException, which is caused by AuthenticationException to + * match the exception tree before error message correction + */ + ExecutionException correctedExecutionException = new ExecutionException( + correctedAuthenticationException); - throw new SQLServerException(form.format(msgArgs), null, 0, correctedExecutionException); + throw new SQLServerException(form.format(msgArgs), null, 0, correctedExecutionException); + } } finally { executorService.shutdown(); } @@ -90,9 +95,9 @@ static SqlFedAuthToken getSqlFedAuthTokenIntegrated(SqlFedAuthInfo fedAuthInfo, return new SqlFedAuthToken(authenticationResult.getAccessToken(), authenticationResult.getExpiresOnDate()); } catch (InterruptedException | IOException e) { throw new SQLServerException(e.getMessage(), e); - } catch (ExecutionException e) { + } catch (Exception e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution")); - Object[] msgArgs = {"", authenticationString}; + Object[] msgArgs = {"", authenticationString, e.getMessage()}; if (null == e.getCause() || null == e.getCause().getMessage()) { // the case when Future's outcome has no AuthenticationResult but exception diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index a361c0f59..1acf9cbdd 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -404,7 +404,7 @@ protected Object[][] getContents() { "FEDAUTHINFO token stream is not long enough ({0}) to contain the data it claims to."}, {"R_FedAuthInfoDoesNotContainStsurlAndSpn", "FEDAUTHINFO token stream does not contain both STSURL and SPN."}, - {"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1})."}, + {"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1}). {2}"}, {"R_UnrequestedFeatureAckReceived", "Unrequested feature acknowledge is received. Feature ID: {0}."}, {"R_FedAuthFeatureAckContainsExtraData", "Federated authentication feature extension ack for ADAL and Security Token includes extra data."}, diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java index dbd7b32ae..b637000d2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java @@ -95,7 +95,7 @@ public void testConcurrentLogin() throws Exception { t1.start(); t2.start(); - if (isWindows && enableADIntegrated) { + if (enableADIntegrated) { Thread t3 = new Thread(r3); t3.setUncaughtExceptionHandler(handler); t3.start(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java index d7d847784..5cbda65da 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java @@ -42,7 +42,7 @@ public void testAccessTokenExpiredThenCreateNewStatementADPassword() throws SQLE @Test public void testAccessTokenExpiredThenCreateNewStatementADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testAccessTokenExpiredThenCreateNewStatement(SqlAuthentication.ActiveDirectoryIntegrated); } @@ -107,7 +107,7 @@ public void testAccessTokenExpiredThenExecuteUsingSameStatementADPassword() thro @Test public void testAccessTokenExpiredThenExecuteUsingSameStatementADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testAccessTokenExpiredThenExecuteUsingSameStatement(SqlAuthentication.ActiveDirectoryIntegrated); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java index 49d472eea..719ff8884 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java @@ -26,7 +26,7 @@ @Tag(Constants.fedAuth) public class ErrorMessageTest extends FedauthCommon { - String userName = "abc" + azureUserName; + String badUserName = "abc" + azureUserName; String connectionUrl = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase; @Test @@ -214,13 +214,14 @@ public void testSQLPasswordWithUntrustedSqlDB() throws SQLException { @Test public void testADPasswordUnregisteredUserWithConnectionStringUserName() throws SQLException { - try (Connection connection = DriverManager.getConnection(connectionUrl + ";userName=" + userName + ";password=" - + azurePassword + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { + try (Connection connection = DriverManager + .getConnection(connectionUrl + ";userName=" + badUserName + ";password=" + azurePassword + + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -232,7 +233,7 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(azureServer); ds.setDatabaseName(azureDatabase); - ds.setUser(userName); + ds.setUser(badUserName); ds.setPassword(azurePassword); ds.setAuthentication(SqlAuthentication.ActiveDirectoryPassword.toString()); @@ -241,7 +242,7 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -249,13 +250,13 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { @Test public void testADPasswordUnregisteredUserWithConnectionStringUser() throws SQLException { - try (Connection connection = DriverManager.getConnection(connectionUrl + ";user=" + userName + ";password=" + try (Connection connection = DriverManager.getConnection(connectionUrl + ";user=" + badUserName + ";password=" + azurePassword + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -268,20 +269,20 @@ public void testAuthenticationAgainstSQLServerWithActivedirectorypassword() thro info.put("Authentication", SqlAuthentication.ActiveDirectoryPassword.toString()); try (Connection connection = DriverManager - .getConnection(connectionUrl + ";user=" + userName + ";password=" + azurePassword, info)) { + .getConnection(connectionUrl + ";user=" + badUserName + ";password=" + azurePassword, info)) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (Exception e) { if (!(e instanceof SQLServerException)) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage().contains(ERR_MSG_FAILED_AUTHENTICATE - + " the user " + userName + " in Active Directory (Authentication=ActiveDirectoryPassword).")); + + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).")); } } @Test public void testAuthenticationAgainstSQLServerWithActivedirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); java.util.Properties info = new Properties(); info.put("TrustServerCertificate", "true"); 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..7854a271c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java @@ -116,7 +116,7 @@ public static void getConfigs() throws Exception { azureGroupUserName = getConfiguredProperty("azureGroupUserName"); String prop = getConfiguredProperty("enableADIntegrated"); - enableADIntegrated = (isWindows && null != prop && prop.equalsIgnoreCase("true")) ? true : false; + enableADIntegrated = (null != prop && prop.equalsIgnoreCase("true")) ? true : false; adPasswordConnectionStr = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";user=" + azureUserName + ";password=" + azurePassword + ";Authentication=" diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java index ac383935a..45308fbae 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java @@ -106,7 +106,7 @@ public void testActiveDirectoryPasswordDS() throws Exception { @Test public void testActiveDirectoryIntegratedDS() throws Exception { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(azureServer); @@ -173,7 +173,7 @@ public void testNotValidSqlPassword() throws SQLException { @Test public void testNotValidActiveDirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true); testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true); @@ -200,7 +200,7 @@ public void testValidSqlPassword() throws SQLException { @Test public void testValidActiveDirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true); testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java index c4d31c483..9183b6683 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java @@ -58,7 +58,7 @@ public void testPooledConnectionAccessTokenExpiredThenReconnectADPassword() thro @Test public void testPooledConnectionAccessTokenExpiredThenReconnectADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); // suspend 5 mins testPooledConnectionAccessTokenExpiredThenReconnect((long) 5 * 60, SqlAuthentication.ActiveDirectoryIntegrated); @@ -132,7 +132,7 @@ public void testPooledConnectionMultiThreadADPassword() throws SQLException { @Test public void testPooledConnectionMultiThreadADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); + org.junit.Assume.assumeTrue(enableADIntegrated); testPooledConnectionMultiThread(secondsBeforeExpiration, SqlAuthentication.ActiveDirectoryIntegrated); } From 7cae3b431dc533e07042f1bbc810995f78b64510 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Thu, 10 Sep 2020 22:34:42 -0700 Subject: [PATCH 02/10] fixed user test for kerberos --- .../microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 7854a271c..6a9427a78 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java @@ -158,7 +158,12 @@ void testUserName(Connection conn, String user, SqlAuthentication authentication if (SqlAuthentication.ActiveDirectoryIntegrated != authentication) { assertTrue(user.equals(rs.getString(1))); } else { - assertTrue(rs.getString(1).contains(System.getProperty("user.name"))); + if (isWindows) { + assertTrue(rs.getString(1).contains(System.getProperty("user.name"))); + } else { + // cannot verify user in kerberos tickets so just check it's not empty + assertTrue(!rs.getString(1).isEmpty()); + } } } } From e863c056cb2d36309c757e25bcf1bdc708bb9b26 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Wed, 16 Sep 2020 15:33:25 -0700 Subject: [PATCH 03/10] user name check --- .../microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 a413b425e..6891445a8 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java @@ -169,7 +169,12 @@ void testUserName(Connection conn, String user, SqlAuthentication authentication if (SqlAuthentication.ActiveDirectoryIntegrated != authentication) { assertTrue(user.equals(rs.getString(1))); } else { - assertTrue(rs.getString(1).contains(System.getProperty("user.name"))); + if (isWindows) { + assertTrue(rs.getString(1).contains(System.getProperty("user.name"))); + } else { + // cannot verify user in kerberos tickets so just check it's not empty + assertTrue(!rs.getString(1).isEmpty()); + } } } } From fc6e8a133d3d35a121a866d2a0cb59ddbffa51ce Mon Sep 17 00:00:00 2001 From: ulvii Date: Mon, 21 Sep 2020 13:51:13 -0700 Subject: [PATCH 04/10] JAVA 15 | Introduce JAVA 15 Support (#1434) --- azure-pipelines.yml | 12 ++++++------ build.gradle | 12 ++++++------ pom.xml | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 18fac75e8..2c78b59aa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -40,15 +40,15 @@ jobs: inputs: secureFile: 'mssql-jdbc_auth-9.1.0.x64-preview.dll' - task: Maven@3 - displayName: 'Maven build jre14' + displayName: 'Maven build jre15' inputs: mavenPomFile: 'pom.xml' - goals: 'clean dependency:purge-local-repository -DdllPath=$(Agent.TempDirectory) -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre14 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups) -Dpkcs12_truststore_password=$(pkcs12_truststore_password) -Dpkcs12_truststore=$(pkcs12_truststore.secureFilePath) + goals: 'clean dependency:purge-local-repository -DdllPath=$(Agent.TempDirectory) -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre15 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups) -Dpkcs12_truststore_password=$(pkcs12_truststore_password) -Dpkcs12_truststore=$(pkcs12_truststore.secureFilePath) -DapplicationClientID=$(applicationClientID) -DapplicationKey=$(applicationKey) -DkeyID=$(keyID) -DwindowsKeyPath=$(windowsKeyPath) -DenclaveAttestationUrl=$(enclaveAttestationUrl) -DenclaveAttestationProtocol=$(enclaveAttestationProtocol) -DenclaveServer=$(enclaveServer)' testResultsFiles: '**/TEST-*.xml' - testRunTitle: 'Maven build jre14' + testRunTitle: 'Maven build jre15' javaHomeOption: Path - jdkDirectory: $(JDK14) + jdkDirectory: $(JDK15) - task: Maven@3 displayName: 'Maven build jre11' inputs: @@ -58,7 +58,7 @@ jobs: testResultsFiles: '**/TEST-*.xml' testRunTitle: 'Maven build jre11' javaHomeOption: Path - jdkDirectory: $(JDK14) + jdkDirectory: $(JDK15) - task: Maven@3 displayName: 'Maven build jre8' inputs: @@ -68,4 +68,4 @@ jobs: testResultsFiles: '**/TEST-*.xml' testRunTitle: 'Maven build jre8' javaHomeOption: Path - jdkDirectory: $(JDK14) + jdkDirectory: $(JDK15) diff --git a/build.gradle b/build.gradle index 10fb10ed2..d4004c8a1 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ **************************************************************** * Instruction for Building JDBC Driver: * For building particular version of the driver, use commands: - * jre14 - - PS> gradle build - PS> gradle build -PbuildProfile=jre14 + * jre15 - - PS> gradle build + PS> gradle build -PbuildProfile=jre15 * jre11 - - PS> gradle build -PbuildProfile=jre11 * jre8 - - PS> gradle build -PbuildProfile=jre8 * @@ -35,17 +35,17 @@ test { } } -if (!hasProperty('buildProfile') || (hasProperty('buildProfile') && buildProfile == "jre14")){ +if (!hasProperty('buildProfile') || (hasProperty('buildProfile') && buildProfile == "jre15")){ - jreVersion = "jre14" + jreVersion = "jre15" excludedFile = 'com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java' jar { manifest { attributes 'Automatic-Module-Name': 'com.microsoft.sqlserver.jdbc' } } - sourceCompatibility = 14 - targetCompatibility = 14 + sourceCompatibility = 15 + targetCompatibility = 15 } if (hasProperty('buildProfile') && buildProfile == "jre11"){ diff --git a/pom.xml b/pom.xml index 1f54230fc..f0d868e0e 100644 --- a/pom.xml +++ b/pom.xml @@ -316,12 +316,12 @@ - jre14 + jre15 true - ${project.artifactId}-${project.version}.jre14${releaseExt} + ${project.artifactId}-${project.version}.jre15${releaseExt} org.apache.maven.plugins @@ -331,8 +331,8 @@ **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java - 14 - 14 + 15 + 15 @@ -439,7 +439,7 @@ org.apache.felix maven-bundle-plugin - 4.2.0 + 5.1.1 true @@ -493,7 +493,7 @@ org.jacoco jacoco-maven-plugin - 0.8.5 + 0.8.6 pre-test From 360a8d4bb6f6e680e3ee0043f32d738b806cf22e Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Mon, 21 Sep 2020 22:04:17 -0700 Subject: [PATCH 05/10] lib conflict --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2eb6487d3..971eda4cf 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ -preview - 4.2.1 + 4.2.0 1.1.2 6.0.0 5.0.0 From 12f2da986ea6412b19d6d6e14eb27de7af224966 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Mon, 21 Sep 2020 23:49:51 -0700 Subject: [PATCH 06/10] back to prev lib version --- pom.xml | 4 ++-- .../com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java | 3 ++- .../jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 971eda4cf..86c69ec1c 100644 --- a/pom.xml +++ b/pom.xml @@ -60,8 +60,8 @@ -preview - 4.2.0 - 1.1.2 + 4.1.4 + 1.0.7 6.0.0 5.0.0 4.7.2 diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java b/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java index 8862df0b9..b7f023ae7 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java @@ -24,6 +24,7 @@ import java.util.concurrent.CompletableFuture; import reactor.core.publisher.Mono; + /** * An AAD credential that acquires a token with a client secret for an AAD application. */ @@ -111,7 +112,7 @@ private ConfidentialClientApplication getConfidentialClientApplication() { } IClientCredential credential; - credential = ClientCredentialFactory.createFromSecret(clientSecret); + credential = ClientCredentialFactory.create(clientSecret); ConfidentialClientApplication.Builder applicationBuilder = ConfidentialClientApplication.builder(clientId, credential); try { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 33ca40ef6..237461fa7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -2290,7 +2290,7 @@ public void testAkvBadEncryptColumnEncryptionKeyWithAuthCallback(String serverNa @Override public String getAccessToken(String authority, String resource, String scope) { try { - IClientCredential credential = ClientCredentialFactory.createFromSecret(applicationKey); + IClientCredential credential = ClientCredentialFactory.create(applicationKey); ConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplication .builder(applicationClientID, credential).authority(authority).build(); Set scopes = new HashSet<>(); From 2b3ccd6930333ac63f25320c5a3a0ea0c243b07d Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 22 Sep 2020 22:33:46 -0700 Subject: [PATCH 07/10] fix --- .../com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java b/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java index 8862df0b9..8557d3fe2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java @@ -73,7 +73,7 @@ class KeyVaultTokenCredential implements TokenCredential { @Override public Mono getToken(TokenRequestContext request) { - if (null == authenticationCallback) { + if (null != authenticationCallback) { String accessToken = authenticationCallback.getAccessToken(this.authorization, this.resource, this.scope); return Mono.just(new AccessToken(accessToken, OffsetDateTime.MIN)); } From 216d77aa795dfd7b1ea89d9626ad0c94341c5f91 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 22 Sep 2020 22:51:29 -0700 Subject: [PATCH 08/10] fixed --- pom.xml | 4 ++-- .../sqlserver/jdbc/KeyVaultTokenCredential.java | 2 +- ...LServerColumnEncryptionAzureKeyVaultProvider.java | 12 +++++------- .../JDBCEncryptionDecryptionTest.java | 6 +----- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 86c69ec1c..2eb6487d3 100644 --- a/pom.xml +++ b/pom.xml @@ -60,8 +60,8 @@ -preview - 4.1.4 - 1.0.7 + 4.2.1 + 1.1.2 6.0.0 5.0.0 4.7.2 diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java b/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java index ddd19c14e..fb11377f1 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/KeyVaultTokenCredential.java @@ -112,7 +112,7 @@ private ConfidentialClientApplication getConfidentialClientApplication() { } IClientCredential credential; - credential = ClientCredentialFactory.create(clientSecret); + credential = ClientCredentialFactory.createFromSecret(clientSecret); ConfidentialClientApplication.Builder applicationBuilder = ConfidentialClientApplication.builder(clientId, credential); try { diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java index b15e963e3..e8ce7273a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java @@ -41,6 +41,7 @@ import com.azure.security.keyvault.keys.models.KeyType; import com.azure.security.keyvault.keys.models.KeyVaultKey; + /** * Provides implementation similar to certificate store provider. A CEK encrypted with certificate store provider should * be decryptable by this provider and vice versa. @@ -170,8 +171,6 @@ public SQLServerColumnEncryptionAzureKeyVaultProvider(TokenCredential tokenCrede createKeyvaultClients(tokenCredential); } - - /** * Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider with a callback function to authenticate to AAD and * an executor service.. This is used by KeyVaultClient at runtime to authenticate to Azure Key Vault. @@ -253,7 +252,7 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryption } // Validate encryptionAlgorithm - KeyWrapAlgorithm _encryptionAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm); + KeyWrapAlgorithm keyWrapAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm); // Validate whether the key is RSA one or not and then get the key size int keySizeInBytes = getAKVKeySize(masterKeyPath); @@ -341,7 +340,7 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryption } // Decrypt the CEK - byte[] decryptedCEK = this.AzureKeyVaultUnWrap(masterKeyPath, _encryptionAlgorithm, cipherText); + byte[] decryptedCEK = this.AzureKeyVaultUnWrap(masterKeyPath, keyWrapAlgorithm, cipherText); return decryptedCEK; } @@ -389,7 +388,7 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryption } // Validate encryptionAlgorithm - KeyWrapAlgorithm _encryptionAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm); + KeyWrapAlgorithm keyWrapAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm); // Validate whether the key is RSA one or not and then get the key size int keySizeInBytes = getAKVKeySize(masterKeyPath); @@ -409,7 +408,7 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryption keyPathLength[1] = (byte) (((short) masterKeyPathBytes.length) >> 8 & 0xff); // Encrypt the plain text - byte[] cipherText = this.AzureKeyVaultWrap(masterKeyPath, _encryptionAlgorithm, columnEncryptionKey); + byte[] cipherText = this.AzureKeyVaultWrap(masterKeyPath, keyWrapAlgorithm, columnEncryptionKey); byte[] cipherTextLength = new byte[2]; cipherTextLength[0] = (byte) (((short) cipherText.length) & 0xff); @@ -698,7 +697,6 @@ private KeyVaultKey getKeyVaultKey(String masterKeyPath) throws SQLServerExcepti retrievedKey = keyClient.getKey(keyName); } - if (null == retrievedKey) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVKeyNotFound")); Object[] msgArgs = {keyTokens[keyTokens.length - 1]}; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 237461fa7..c073fee2b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -4,7 +4,6 @@ */ package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -12,7 +11,6 @@ import com.microsoft.aad.msal4j.ClientCredentialParameters; import com.microsoft.aad.msal4j.ConfidentialClientApplication; import com.microsoft.aad.msal4j.IClientCredential; -import com.microsoft.aad.msal4j.PublicClientApplication; import com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback; import java.math.BigDecimal; import java.sql.Date; @@ -28,8 +26,6 @@ import com.azure.core.credential.TokenCredential; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import org.junit.jupiter.api.Tag; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -2290,7 +2286,7 @@ public void testAkvBadEncryptColumnEncryptionKeyWithAuthCallback(String serverNa @Override public String getAccessToken(String authority, String resource, String scope) { try { - IClientCredential credential = ClientCredentialFactory.create(applicationKey); + IClientCredential credential = ClientCredentialFactory.createFromSecret(applicationKey); ConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplication .builder(applicationClientID, credential).authority(authority).build(); Set scopes = new HashSet<>(); From 791e2b6b473f6cac5a9ecde7359527c78921d3f0 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 22 Sep 2020 23:02:38 -0700 Subject: [PATCH 09/10] update --- .../sqlserver/jdbc/SQLServerMSAL4JUtils.java | 6 ++--- .../sqlserver/jdbc/SQLServerResource.java | 2 +- .../jdbc/fedauth/ConcurrentLoginTest.java | 2 +- .../fedauth/ConnectionSuspensionTest.java | 4 ++-- .../jdbc/fedauth/ErrorMessageTest.java | 23 +++++++++---------- .../sqlserver/jdbc/fedauth/FedauthCommon.java | 2 +- .../sqlserver/jdbc/fedauth/FedauthTest.java | 6 ++--- .../jdbc/fedauth/PooledConnectionTest.java | 4 ++-- 8 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMSAL4JUtils.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMSAL4JUtils.java index 50dcc2349..633533f12 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMSAL4JUtils.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerMSAL4JUtils.java @@ -47,7 +47,7 @@ static SqlFedAuthToken getSqlFedAuthToken(SqlFedAuthInfo fedAuthInfo, String use } catch (MalformedURLException | InterruptedException e) { throw new SQLServerException(e.getMessage(), e); - } catch (Exception e) { + } catch (ExecutionException e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution")); Object[] msgArgs = {user, authenticationString}; @@ -97,9 +97,9 @@ static SqlFedAuthToken getSqlFedAuthTokenIntegrated(SqlFedAuthInfo fedAuthInfo, return new SqlFedAuthToken(authenticationResult.accessToken(), authenticationResult.expiresOnDate()); } catch (InterruptedException | IOException e) { throw new SQLServerException(e.getMessage(), e); - } catch (Exception e) { + } catch (ExecutionException e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_ADALExecution")); - Object[] msgArgs = {"", authenticationString, e.getMessage()}; + Object[] msgArgs = {"", authenticationString}; if (null == e.getCause() || null == e.getCause().getMessage()) { // the case when Future's outcome has no AuthenticationResult but exception diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index 508dac142..b83772f37 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -404,7 +404,7 @@ protected Object[][] getContents() { "FEDAUTHINFO token stream is not long enough ({0}) to contain the data it claims to."}, {"R_FedAuthInfoDoesNotContainStsurlAndSpn", "FEDAUTHINFO token stream does not contain both STSURL and SPN."}, - {"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1}). {2}"}, + {"R_ADALExecution", "Failed to authenticate the user {0} in Active Directory (Authentication={1})."}, {"R_UnrequestedFeatureAckReceived", "Unrequested feature acknowledge is received. Feature ID: {0}."}, {"R_FedAuthFeatureAckContainsExtraData", "Federated authentication feature extension ack for ADAL and Security Token includes extra data."}, diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java index b637000d2..dbd7b32ae 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConcurrentLoginTest.java @@ -95,7 +95,7 @@ public void testConcurrentLogin() throws Exception { t1.start(); t2.start(); - if (enableADIntegrated) { + if (isWindows && enableADIntegrated) { Thread t3 = new Thread(r3); t3.setUncaughtExceptionHandler(handler); t3.start(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java index 5cbda65da..d7d847784 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ConnectionSuspensionTest.java @@ -42,7 +42,7 @@ public void testAccessTokenExpiredThenCreateNewStatementADPassword() throws SQLE @Test public void testAccessTokenExpiredThenCreateNewStatementADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(enableADIntegrated); + org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); testAccessTokenExpiredThenCreateNewStatement(SqlAuthentication.ActiveDirectoryIntegrated); } @@ -107,7 +107,7 @@ public void testAccessTokenExpiredThenExecuteUsingSameStatementADPassword() thro @Test public void testAccessTokenExpiredThenExecuteUsingSameStatementADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(enableADIntegrated); + org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); testAccessTokenExpiredThenExecuteUsingSameStatement(SqlAuthentication.ActiveDirectoryIntegrated); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java index 719ff8884..49d472eea 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/ErrorMessageTest.java @@ -26,7 +26,7 @@ @Tag(Constants.fedAuth) public class ErrorMessageTest extends FedauthCommon { - String badUserName = "abc" + azureUserName; + String userName = "abc" + azureUserName; String connectionUrl = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase; @Test @@ -214,14 +214,13 @@ public void testSQLPasswordWithUntrustedSqlDB() throws SQLException { @Test public void testADPasswordUnregisteredUserWithConnectionStringUserName() throws SQLException { - try (Connection connection = DriverManager - .getConnection(connectionUrl + ";userName=" + badUserName + ";password=" + azurePassword - + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { + try (Connection connection = DriverManager.getConnection(connectionUrl + ";userName=" + userName + ";password=" + + azurePassword + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -233,7 +232,7 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(azureServer); ds.setDatabaseName(azureDatabase); - ds.setUser(badUserName); + ds.setUser(userName); ds.setPassword(azurePassword); ds.setAuthentication(SqlAuthentication.ActiveDirectoryPassword.toString()); @@ -242,7 +241,7 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -250,13 +249,13 @@ public void testADPasswordUnregisteredUserWithDatasource() throws SQLException { @Test public void testADPasswordUnregisteredUserWithConnectionStringUser() throws SQLException { - try (Connection connection = DriverManager.getConnection(connectionUrl + ";user=" + badUserName + ";password=" + try (Connection connection = DriverManager.getConnection(connectionUrl + ";user=" + userName + ";password=" + azurePassword + ";Authentication=" + SqlAuthentication.ActiveDirectoryPassword.toString())) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (SQLServerException e) { assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage() - .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + badUserName + .contains(ERR_MSG_FAILED_AUTHENTICATE + " the user " + userName + " in Active Directory (Authentication=ActiveDirectoryPassword).") && e.getCause().getCause().getMessage().contains(ERR_MSG_SIGNIN_ADD)); } @@ -269,20 +268,20 @@ public void testAuthenticationAgainstSQLServerWithActivedirectorypassword() thro info.put("Authentication", SqlAuthentication.ActiveDirectoryPassword.toString()); try (Connection connection = DriverManager - .getConnection(connectionUrl + ";user=" + badUserName + ";password=" + azurePassword, info)) { + .getConnection(connectionUrl + ";user=" + userName + ";password=" + azurePassword, info)) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } catch (Exception e) { if (!(e instanceof SQLServerException)) { fail(EXPECTED_EXCEPTION_NOT_THROWN); } assertTrue(INVALID_EXCEPION_MSG + ": " + e.getMessage(), e.getMessage().contains(ERR_MSG_FAILED_AUTHENTICATE - + " the user " + badUserName + " in Active Directory (Authentication=ActiveDirectoryPassword).")); + + " the user " + userName + " in Active Directory (Authentication=ActiveDirectoryPassword).")); } } @Test public void testAuthenticationAgainstSQLServerWithActivedirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(enableADIntegrated); + org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); java.util.Properties info = new Properties(); info.put("TrustServerCertificate", "true"); 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 b35ee72e6..6891445a8 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java @@ -120,7 +120,7 @@ public static void getConfigs() throws Exception { azureGroupUserName = getConfiguredProperty("azureGroupUserName"); String prop = getConfiguredProperty("enableADIntegrated"); - enableADIntegrated = (null != prop && prop.equalsIgnoreCase("true")) ? true : false; + enableADIntegrated = (isWindows && null != prop && prop.equalsIgnoreCase("true")) ? true : false; adPasswordConnectionStr = "jdbc:sqlserver://" + azureServer + ";database=" + azureDatabase + ";user=" + azureUserName + ";password=" + azurePassword + ";Authentication=" diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java index 45308fbae..ac383935a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthTest.java @@ -106,7 +106,7 @@ public void testActiveDirectoryPasswordDS() throws Exception { @Test public void testActiveDirectoryIntegratedDS() throws Exception { - org.junit.Assume.assumeTrue(enableADIntegrated); + org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); SQLServerDataSource ds = new SQLServerDataSource(); ds.setServerName(azureServer); @@ -173,7 +173,7 @@ public void testNotValidSqlPassword() throws SQLException { @Test public void testNotValidActiveDirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(enableADIntegrated); + org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true); testNotValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true); @@ -200,7 +200,7 @@ public void testValidSqlPassword() throws SQLException { @Test public void testValidActiveDirectoryIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(enableADIntegrated); + org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), false, true); testValid(SqlAuthentication.ActiveDirectoryIntegrated.toString(), true, true); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java index 9183b6683..c4d31c483 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java @@ -58,7 +58,7 @@ public void testPooledConnectionAccessTokenExpiredThenReconnectADPassword() thro @Test public void testPooledConnectionAccessTokenExpiredThenReconnectADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(enableADIntegrated); + org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); // suspend 5 mins testPooledConnectionAccessTokenExpiredThenReconnect((long) 5 * 60, SqlAuthentication.ActiveDirectoryIntegrated); @@ -132,7 +132,7 @@ public void testPooledConnectionMultiThreadADPassword() throws SQLException { @Test public void testPooledConnectionMultiThreadADIntegrated() throws SQLException { - org.junit.Assume.assumeTrue(enableADIntegrated); + org.junit.Assume.assumeTrue(isWindows && enableADIntegrated); testPooledConnectionMultiThread(secondsBeforeExpiration, SqlAuthentication.ActiveDirectoryIntegrated); } From a7119131d567639e5a97a35f20ffe8759745d89d Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Tue, 22 Sep 2020 23:04:34 -0700 Subject: [PATCH 10/10] merged --- .../microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java | 7 +------ 1 file changed, 1 insertion(+), 6 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 6891445a8..a413b425e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/FedauthCommon.java @@ -169,12 +169,7 @@ void testUserName(Connection conn, String user, SqlAuthentication authentication if (SqlAuthentication.ActiveDirectoryIntegrated != authentication) { assertTrue(user.equals(rs.getString(1))); } else { - if (isWindows) { - assertTrue(rs.getString(1).contains(System.getProperty("user.name"))); - } else { - // cannot verify user in kerberos tickets so just check it's not empty - assertTrue(!rs.getString(1).isEmpty()); - } + assertTrue(rs.getString(1).contains(System.getProperty("user.name"))); } } }