From ae462f95cd3a568158084406364ac81f305dd3f4 Mon Sep 17 00:00:00 2001 From: Ananya Garg Date: Sat, 30 Nov 2024 01:18:44 +0530 Subject: [PATCH] Remove exception and validation for user/password with AccessTokenCallback (#2549) * Removed the if statement, that throws exception R_AccessTokenCallbackWithUserPassword. This logic may be too restrictive and may be removed * Updated testDSPooledConnectionAccessTokenCallbackClassExceptions test case in PooledConnectionTest.java * Updated testDSPooledConnectionAccessTokenCallbackClassExceptions test case. * Added import statement. --- .../sqlserver/jdbc/SQLServerConnection.java | 7 ------ .../jdbc/fedauth/PooledConnectionTest.java | 23 +++++-------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 18a27cc95..6874deab4 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -2802,13 +2802,6 @@ Connection connectInternal(Properties propsIn, && !activeConnectionProperties .getProperty(SQLServerDriverStringProperty.ACCESS_TOKEN_CALLBACK_CLASS.toString()) .isEmpty(); - if ((null != accessTokenCallback || hasAccessTokenCallbackClass) && (!activeConnectionProperties - .getProperty(SQLServerDriverStringProperty.USER.toString()).isEmpty() - || !activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString()) - .isEmpty())) { - throw new SQLServerException( - SQLServerException.getErrString("R_AccessTokenCallbackWithUserPassword"), null); - } sPropKey = SQLServerDriverStringProperty.ACCESS_TOKEN_CALLBACK_CLASS.toString(); sPropValue = activeConnectionProperties.getProperty(sPropKey); 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 a7bf0f8c4..85a232fd0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fedauth/PooledConnectionTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.lang.reflect.Field; import java.sql.Connection; @@ -435,27 +436,15 @@ public void testDSPooledConnectionAccessTokenCallbackClassExceptions() throws Ex // User/password is not required for access token callback AbstractTest.updateDataSource(accessTokenCallbackConnectionString, ds); + ds.setAccessTokenCallbackClass(AccessTokenCallbackClass.class.getName()); ds.setUser("user"); - SQLServerPooledConnection pc; - - // Should fail with user set - try { - pc = (SQLServerPooledConnection) ds.getPooledConnection(); - fail(TestResource.getResource("R_expectedFailPassed")); - } catch (SQLServerException e) { - assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AccessTokenCallbackWithUserPassword"))); - } - - ds.setUser(""); ds.setPassword(UUID.randomUUID().toString()); + SQLServerPooledConnection pc; - // Should fail with password set - try { - pc = (SQLServerPooledConnection) ds.getPooledConnection(); - fail(TestResource.getResource("R_expectedFailPassed")); - } catch (SQLServerException e) { - assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AccessTokenCallbackWithUserPassword"))); + pc = (SQLServerPooledConnection) ds.getPooledConnection(); + try (Connection conn1 = pc.getConnection()) { + assertNotNull(conn1); } // Should fail with invalid accessTokenCallbackClass value