Skip to content

Commit b13b41f

Browse files
committed
Remove ADAL dependency: Migrate Windows AAD Integrated Auth to MSQA APIs via mssql-auth.dll.
1 parent 303aeb9 commit b13b41f

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/AuthenticationJNI.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@ static boolean isDllLoaded() {
8585
}
8686

8787
static FedAuthDllInfo getAccessTokenForWindowsIntegrated(String stsURL, String servicePrincipalName,
88-
String clientConnectionId, String clientId, long expirationFileTime) throws DLLException {
88+
String clientConnectionId, String clientId) throws DLLException {
8989
try {
9090
lock.lock();
9191

92-
return ADALGetAccessTokenForWindowsIntegrated(stsURL, servicePrincipalName, clientConnectionId, clientId,
93-
expirationFileTime, authLogger);
92+
return MSQAGetAccessTokenForWindowsIntegrated(stsURL, servicePrincipalName, clientConnectionId, clientId, authLogger);
9493
} finally {
9594
lock.unlock();
9695
}
@@ -164,9 +163,8 @@ private static native int SNISecGenClientContext(byte[] psec, int[] secptrsize,
164163

165164
private static native int GetDNSName(String address, String[] DNSName, java.util.logging.Logger log);
166165

167-
private static native FedAuthDllInfo ADALGetAccessTokenForWindowsIntegrated(String stsURL,
168-
String servicePrincipalName, String clientConnectionId, String clientId, long expirationFileTime,
169-
java.util.logging.Logger log);
166+
private static native FedAuthDllInfo MSQAGetAccessTokenForWindowsIntegrated(String stsURL,
167+
String servicePrincipalName, String clientConnectionId, String clientId, java.util.logging.Logger log);
170168

171169
static native byte[] DecryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
172170
byte[] encryptedColumnEncryptionKey) throws DLLException;

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6798,7 +6798,7 @@ private SqlAuthenticationToken getFedAuthToken(SqlFedAuthInfo fedAuthInfo) throw
67986798
try {
67996799
FedAuthDllInfo dllInfo = AuthenticationJNI.getAccessTokenForWindowsIntegrated(
68006800
fedAuthInfo.stsurl, fedAuthInfo.spn, clientConnectionId.toString(),
6801-
ActiveDirectoryAuthentication.JDBC_FEDAUTH_CLIENT_ID, 0);
6801+
ActiveDirectoryAuthentication.JDBC_FEDAUTH_CLIENT_ID);
68026802

68036803
// AccessToken should not be null.
68046804
assert null != dllInfo.accessTokenBytes;
@@ -6811,15 +6811,15 @@ private SqlAuthenticationToken getFedAuthToken(SqlFedAuthInfo fedAuthInfo) throw
68116811

68126812
// Break out of the retry loop in successful case.
68136813
break;
6814-
} catch (DLLException adalException) {
6814+
} catch (DLLException dllException) {
68156815

6816-
// the mssql-jdbc_auth DLL return -1 for errorCategory, if unable to load the
6817-
// adalsql DLL
6818-
int errorCategory = adalException.getCategory();
6816+
// The mssql-jdbc_auth DLL returns -1 for errorCategory if unable to load the
6817+
// mssql-auth.dll
6818+
int errorCategory = dllException.getCategory();
68196819
if (-1 == errorCategory) {
68206820
MessageFormat form = new MessageFormat(
6821-
SQLServerException.getErrString("R_UnableLoadADALSqlDll"));
6822-
Object[] msgArgs = { Integer.toHexString(adalException.getState()) };
6821+
SQLServerException.getErrString("R_UnableLoadMSSQLAuthDll"));
6822+
Object[] msgArgs = { Integer.toHexString(dllException.getState()) };
68236823
throw new SQLServerException(form.format(msgArgs), null);
68246824
}
68256825

@@ -6828,21 +6828,21 @@ private SqlAuthenticationToken getFedAuthToken(SqlFedAuthInfo fedAuthInfo) throw
68286828
|| timerHasExpired(timerExpire)
68296829
|| (fedauthSleepInterval >= millisecondsRemaining)) {
68306830

6831-
String errorStatus = Integer.toHexString(adalException.getStatus());
6831+
String errorStatus = Integer.toHexString(dllException.getStatus());
68326832

68336833
if (connectionlogger.isLoggable(Level.FINER)) {
68346834
connectionlogger.fine(
68356835
toString()
6836-
+ " SQLServerConnection.getFedAuthToken.AdalException category:"
6836+
+ " SQLServerConnection.getFedAuthToken.DLLException category:"
68376837
+ errorCategory + " error: " + errorStatus);
68386838
}
68396839

68406840
MessageFormat form = new MessageFormat(
68416841
SQLServerException.getErrString("R_ADALAuthenticationMiddleErrorMessage"));
6842-
String errorCode = Integer.toHexString(adalException.getStatus()).toUpperCase();
6843-
Object[] msgArgs1 = { errorCode, adalException.getState() };
6842+
String errorCode = Integer.toHexString(dllException.getStatus()).toUpperCase();
6843+
Object[] msgArgs1 = { errorCode, dllException.getState() };
68446844
SQLServerException middleException = new SQLServerException(form.format(msgArgs1),
6845-
adalException);
6845+
dllException);
68466846

68476847
form = new MessageFormat(SQLServerException.getErrString("R_MSALExecution"));
68486848
Object[] msgArgs = { user, authenticationString };

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ protected Object[][] getContents() {
404404
{"R_GenerateSignature", "Unable to generate signature using a specified Azure Key Vault Key URL."},
405405
{"R_SignedHashLengthError", "Signed hash length does not match the RSA key size."},
406406
{"R_InvalidSignatureComputed", "Invalid signature of the encrypted column encryption key computed."},
407-
{"R_UnableLoadADALSqlDll", "Unable to load adalsql.dll. Error code: 0x{0}. For details, see: http://go.microsoft.com/fwlink/?LinkID=513072"},
407+
{"R_UnableLoadMSSQLAuthDll", "Unable to load mssql-auth.dll. Error code: 0x{0}. For details, see: http://go.microsoft.com/fwlink/?LinkID=513072"},
408408
{"R_ADALAuthenticationMiddleErrorMessage", "Error code 0x{0}; state {1}."},
409409
{"R_unsupportedDataTypeTVP", "Data type {0} not supported in Table-Valued Parameter."},
410410
{"R_moreDataInRowThanColumnInTVP", "Input array is longer than the number of columns in this table."},

0 commit comments

Comments
 (0)