From d842883e3e69420a7a798294cb58ac252eead011 Mon Sep 17 00:00:00 2001 From: Terry <32403408+tkyc@users.noreply.github.com> Date: Thu, 26 Jan 2023 12:52:12 -0800 Subject: [PATCH] Renamed driver DefaultAzureCredential authentication to ActiveDirectoryDefault (#2055) --- .../com/microsoft/sqlserver/jdbc/IOBuffer.java | 2 +- .../sqlserver/jdbc/SQLServerConnection.java | 14 +++++++------- .../microsoft/sqlserver/jdbc/SQLServerDriver.java | 6 +++--- .../sqlserver/jdbc/AlwaysEncrypted/MSITest.java | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index d44fd95fe..ef180a60b 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -131,7 +131,7 @@ final class TDS { static final byte ADALWORKFLOW_ACTIVEDIRECTORYINTEGRATED = 0x02; static final byte ADALWORKFLOW_ACTIVEDIRECTORYMANAGEDIDENTITY = 0x03; static final byte ADALWORKFLOW_ACTIVEDIRECTORYINTERACTIVE = 0x03; - static final byte ADALWORKFLOW_DEFAULTAZURECREDENTIAL = 0x03; + static final byte ADALWORKFLOW_ACTIVEDIRECTORYDEFAULT = 0x03; static final byte ADALWORKFLOW_ACCESSTOKENCALLBACK = 0x03; static final byte ADALWORKFLOW_ACTIVEDIRECTORYSERVICEPRINCIPAL = 0x01; // Using the Password byte as that is the // closest we have. diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 01403bc45..8abfb321c 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -524,8 +524,8 @@ class FederatedAuthenticationFeatureExtensionData implements Serializable { case "ACTIVEDIRECTORYMANAGEDIDENTITY": this.authentication = SqlAuthentication.ACTIVE_DIRECTORY_MANAGED_IDENTITY; break; - case "DEFAULTAZURECREDENTIAL": - this.authentication = SqlAuthentication.DEFAULT_AZURE_CREDENTIAL; + case "ACTIVEDIRECTORYDEFAULT": + this.authentication = SqlAuthentication.ACTIVE_DIRECTORY_DEFAULT; break; case "ACTIVEDIRECTORYSERVICEPRINCIPAL": this.authentication = SqlAuthentication.ACTIVE_DIRECTORY_SERVICE_PRINCIPAL; @@ -2467,7 +2467,7 @@ Connection connectInternal(Properties propsIn, } authenticationString = SqlAuthentication.valueOfString(sPropValue).toString().trim(); - if (authenticationString.equalsIgnoreCase(SqlAuthentication.DEFAULT_AZURE_CREDENTIAL.toString()) + if (authenticationString.equalsIgnoreCase(SqlAuthentication.ACTIVE_DIRECTORY_DEFAULT.toString()) && (!activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString()) .isEmpty())) { MessageFormat form = new MessageFormat( @@ -4816,8 +4816,8 @@ int writeFedAuthFeatureRequest(boolean write, /* if false just calculates the le case ACTIVE_DIRECTORY_MANAGED_IDENTITY: workflow = TDS.ADALWORKFLOW_ACTIVEDIRECTORYMANAGEDIDENTITY; break; - case DEFAULT_AZURE_CREDENTIAL: - workflow = TDS.ADALWORKFLOW_DEFAULTAZURECREDENTIAL; + case ACTIVE_DIRECTORY_DEFAULT: + workflow = TDS.ADALWORKFLOW_ACTIVEDIRECTORYDEFAULT; break; case ACTIVE_DIRECTORY_INTERACTIVE: workflow = TDS.ADALWORKFLOW_ACTIVEDIRECTORYINTERACTIVE; @@ -5042,7 +5042,7 @@ private void logon(LogonCommand command) throws SQLServerException { || ((authenticationString.equalsIgnoreCase(SqlAuthentication.ACTIVE_DIRECTORY_INTEGRATED.toString()) || authenticationString .equalsIgnoreCase(SqlAuthentication.ACTIVE_DIRECTORY_MANAGED_IDENTITY.toString()) - || authenticationString.equalsIgnoreCase(SqlAuthentication.DEFAULT_AZURE_CREDENTIAL.toString()) + || authenticationString.equalsIgnoreCase(SqlAuthentication.ACTIVE_DIRECTORY_DEFAULT.toString()) || authenticationString .equalsIgnoreCase(SqlAuthentication.ACTIVE_DIRECTORY_SERVICE_PRINCIPAL.toString()) || authenticationString @@ -5778,7 +5778,7 @@ private SqlAuthenticationToken getFedAuthToken(SqlFedAuthInfo fedAuthInfo) throw // Break out of the retry loop in successful case. break; - } else if (authenticationString.equalsIgnoreCase(SqlAuthentication.DEFAULT_AZURE_CREDENTIAL.toString())) { + } else if (authenticationString.equalsIgnoreCase(SqlAuthentication.ACTIVE_DIRECTORY_DEFAULT.toString())) { String managedIdentityClientId = activeConnectionProperties .getProperty(SQLServerDriverStringProperty.USER.toString()); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java index 73d14bfc4..95b0ebca7 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java @@ -71,7 +71,7 @@ enum SqlAuthentication { ACTIVE_DIRECTORY_MANAGED_IDENTITY("ActiveDirectoryManagedIdentity"), ACTIVE_DIRECTORY_SERVICE_PRINCIPAL("ActiveDirectoryServicePrincipal"), ACTIVE_DIRECTORY_INTERACTIVE("ActiveDirectoryInteractive"), - DEFAULT_AZURE_CREDENTIAL("DefaultAzureCredential"); + ACTIVE_DIRECTORY_DEFAULT("ActiveDirectoryDefault"); private final String name; @@ -109,8 +109,8 @@ static SqlAuthentication valueOfString(String value) throws SQLServerException { .equalsIgnoreCase(SqlAuthentication.ACTIVE_DIRECTORY_INTERACTIVE.toString())) { method = SqlAuthentication.ACTIVE_DIRECTORY_INTERACTIVE; } else if (value.toLowerCase(Locale.US) - .equalsIgnoreCase(SqlAuthentication.DEFAULT_AZURE_CREDENTIAL.toString())) { - method = SqlAuthentication.DEFAULT_AZURE_CREDENTIAL; + .equalsIgnoreCase(SqlAuthentication.ACTIVE_DIRECTORY_DEFAULT.toString())) { + method = SqlAuthentication.ACTIVE_DIRECTORY_DEFAULT; } else { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_InvalidConnectionSetting")); Object[] msgArgs = {"authentication", value}; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java index 92d39bb74..5afa2e78e 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/MSITest.java @@ -170,11 +170,11 @@ public void testDSManagedIdentityAuthWithManagedIdentityClientId() throws SQLExc @Tag(Constants.xSQLv14) @Tag(Constants.xSQLv15) @Test - public void testDefaultAzureCredentialAuth() throws SQLException { + public void testActiveDirectoryDefaultAuth() throws SQLException { String connStr = connectionString; connStr = TestUtils.addOrOverrideProperty(connStr, Constants.USER, managedIdentityClientId); connStr = TestUtils.addOrOverrideProperty(connStr, Constants.PASSWORD, ""); - connStr = TestUtils.addOrOverrideProperty(connStr, Constants.AUTHENTICATION, "DefaultAzureCredential"); + connStr = TestUtils.addOrOverrideProperty(connStr, Constants.AUTHENTICATION, "ActiveDirectoryDefault"); // With Managed Identity client ID try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(connStr)) {} @@ -189,13 +189,13 @@ public void testDefaultAzureCredentialAuth() throws SQLException { @Tag(Constants.xSQLv14) @Tag(Constants.xSQLv15) @Test - public void testDefaultAzureCredentialAuthDS() throws SQLException { + public void testActiveDirectoryDefaultAuthDS() throws SQLException { String connStr = connectionString; connStr = TestUtils.addOrOverrideProperty(connStr, Constants.USER, ""); connStr = TestUtils.addOrOverrideProperty(connStr, Constants.PASSWORD, ""); SQLServerDataSource ds = new SQLServerDataSource(); - ds.setAuthentication("DefaultAzureCredential"); + ds.setAuthentication("ActiveDirectoryDefault"); ds.setMSIClientId(managedIdentityClientId); AbstractTest.updateDataSource(connStr, ds);