Skip to content

Commit 648e1b8

Browse files
committed
Merge branch 'access-token-callback' of https://github.com/microsoft/mssql-jdbc into access-token-callback
2 parents f851bf7 + cd34338 commit 648e1b8

18 files changed

+137
-158
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ dependencies {
130130
implementation 'org.osgi:org.osgi.core:6.0.0',
131131
'org.osgi:org.osgi.compendium:5.0.0'
132132
compileOnly 'com.azure:azure-security-keyvault-keys:4.2.8',
133-
'com.azure:azure-identity:1.3.3',
133+
'com.azure:azure-identity:1.7.0-beta.2',
134134
'org.antlr:antlr4-runtime:4.9.2',
135135
'com.google.code.gson:gson:2.8.7',
136136
'org.bouncycastle:bcprov-jdk15on:1.69',
@@ -152,7 +152,7 @@ dependencies {
152152
'com.google.code.gson:gson:2.8.7',
153153
'org.bouncycastle:bcprov-jdk15on:1.69',
154154
'com.azure:azure-security-keyvault-keys:4.2.8',
155-
'com.azure:azure-identity:1.3.3',
155+
'com.azure:azure-identity:1.7.0-beta.2',
156156
'com.microsoft.azure:adal4j:1.6.7',
157157
'com.h2database:h2:1.4.200'
158158
}

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363

6464
<!-- Driver Dependencies -->
6565
<org.osgi.core.version>6.0.0</org.osgi.core.version>
66-
<azure-security-keyvault-keys.version>4.4.4</azure-security-keyvault-keys.version>
66+
<azure-security-keyvault-keys.version>4.5.1</azure-security-keyvault-keys.version>
6767
<azure-identity.version>1.7.0-beta.2</azure-identity.version>
68-
<msal.version>1.13.0</msal.version>
68+
<msal.version>1.13.3</msal.version>
6969
<org.osgi.compendium.version>5.0.0</org.osgi.compendium.version>
7070
<antlr-runtime.version>4.9.3</antlr-runtime.version>
7171
<com.google.code.gson.version>2.9.0</com.google.code.gson.version>
@@ -109,7 +109,7 @@
109109
<dependency>
110110
<groupId>com.microsoft.azure</groupId>
111111
<artifactId>msal4j</artifactId>
112-
<version>1.13.0</version>
112+
<version>1.13.3</version>
113113
<optional>true</optional>
114114
</dependency>
115115

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ enum Result {
24162416

24172417
// list of addresses for ip selection by type preference
24182418
private static ArrayList<InetAddress> addressList = new ArrayList<>();
2419-
private static final Lock ADDRESS_LIST_LOCK = new ReentrantLock();
2419+
private static final Lock addressListLock = new ReentrantLock();
24202420

24212421
/**
24222422
* Constructs a new SocketFinder object with appropriate traceId
@@ -2765,7 +2765,7 @@ private SocketFactory getSocketFactory() throws IOException {
27652765
*/
27662766
private InetSocketAddress getInetAddressByIPPreference(String hostName,
27672767
int portNumber) throws IOException, SQLServerException {
2768-
ADDRESS_LIST_LOCK.lock();
2768+
addressListLock.lock();
27692769
try {
27702770
InetSocketAddress addr = InetSocketAddress.createUnresolved(hostName, portNumber);
27712771
for (int i = 0; i < addressList.size(); i++) {
@@ -2775,7 +2775,7 @@ private InetSocketAddress getInetAddressByIPPreference(String hostName,
27752775
}
27762776
return addr;
27772777
} finally {
2778-
ADDRESS_LIST_LOCK.unlock();
2778+
addressListLock.unlock();
27792779
}
27802780
}
27812781

@@ -2838,7 +2838,7 @@ private Socket getSocketByIPPreference(String hostName, int portNumber, int time
28382838
// Note that Socket(host, port) throws an UnknownHostException if the host name
28392839
// cannot be resolved, but that InetSocketAddress(host, port) does not - it sets
28402840
// the returned InetSocketAddress as unresolved.
2841-
if (addr.isUnresolved()) {
2841+
if (addr != null && addr.isUnresolved()) {
28422842
if (logger.isLoggable(Level.FINER)) {
28432843
logger.finer(this.toString() + "Failed to resolve host name: " + hostName
28442844
+ ". Using IP address from DNS cache.");
@@ -2859,7 +2859,7 @@ private Socket getSocketByIPPreference(String hostName, int portNumber, int time
28592859
* Boolean switch for IPv6 first
28602860
*/
28612861
private void fillAddressList(InetAddress[] addresses, boolean ipv6first) {
2862-
ADDRESS_LIST_LOCK.lock();
2862+
addressListLock.lock();
28632863
try {
28642864
addressList.clear();
28652865
if (ipv6first) {
@@ -2876,7 +2876,7 @@ private void fillAddressList(InetAddress[] addresses, boolean ipv6first) {
28762876
}
28772877
}
28782878
} finally {
2879-
ADDRESS_LIST_LOCK.unlock();
2879+
addressListLock.unlock();
28802880
}
28812881
}
28822882

@@ -4155,7 +4155,7 @@ void writeString(String value) throws SQLServerException {
41554155
int charsCopied = 0;
41564156
int length = value.length();
41574157
while (charsCopied < length) {
4158-
long bytesToCopy = 2 * (length - charsCopied);
4158+
long bytesToCopy = 2 * ((long) length - charsCopied);
41594159

41604160
if (bytesToCopy > valueBytes.length)
41614161
bytesToCopy = valueBytes.length;
@@ -6053,7 +6053,8 @@ private void writeScaledTemporal(GregorianCalendar cal, int subSecondNanos, int
60536053
+ 60 * 60 * cal.get(Calendar.HOUR_OF_DAY);
60546054

60556055
// Scale nanos since midnight to the desired scale, rounding the value as necessary
6056-
long divisor = Nanos.PER_MAX_SCALE_INTERVAL * (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - scale);
6056+
long divisor = Nanos.PER_MAX_SCALE_INTERVAL
6057+
* (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - (double) scale);
60576058

60586059
// The scaledNanos variable represents the fractional seconds of the value at the scale
60596060
// indicated by the scale variable. So, for example, scaledNanos = 3 means 300 nanoseconds
@@ -6195,7 +6196,8 @@ byte[] writeEncryptedScaledTemporal(GregorianCalendar cal, int subSecondNanos, i
61956196
+ 60 * 60 * cal.get(Calendar.HOUR_OF_DAY);
61966197

61976198
// Scale nanos since midnight to the desired scale, rounding the value as necessary
6198-
divisor = Nanos.PER_MAX_SCALE_INTERVAL * (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - scale);
6199+
divisor = Nanos.PER_MAX_SCALE_INTERVAL
6200+
* (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - (double) scale);
61996201

62006202
// The scaledNanos variable represents the fractional seconds of the value at the scale
62016203
// indicated by the scale variable. So, for example, scaledNanos = 3 means 300 nanoseconds

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public void run() {
469469
} else {
470470
try {
471471
if (connectRetryCount > 1) {
472-
Thread.sleep(con.getRetryInterval() * 1000);
472+
Thread.sleep((long) (con.getRetryInterval()) * 1000);
473473
}
474474
} catch (InterruptedException ie) {
475475
// re-interrupt thread

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ private int findColumn(String columnName) throws SQLServerException {
13651365

13661366
// 1. Search using case-sensitive non-locale specific (binary) compare first.
13671367
// 2. Search using case-insensitive, non-locale specific (binary) compare last.
1368-
Integer matchPos = parameterNames.get(columnNameWithSign);
1368+
Integer matchPos = (parameterNames != null) ? parameterNames.get(columnNameWithSign) : null;
13691369
if (null == matchPos) {
13701370
matchPos = insensitiveParameterNames.get(columnNameWithSign);
13711371
}

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

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial
227227
* lock instance for "this"
228228
**/
229229
private final Lock lock = new ReentrantLock();
230+
230231
/**
231232
* static lock instance for the class
232233
**/
233-
private static final Lock LOCK = new ReentrantLock();
234+
private static final Lock sLock = new ReentrantLock();
234235

235236
/**
236237
* Return an existing cached SharedTimer associated with this Connection or create a new one.
@@ -947,7 +948,7 @@ public static void registerColumnEncryptionKeyStoreProviders(
947948
loggerExternal.entering(loggingClassNameBase, "registerColumnEncryptionKeyStoreProviders",
948949
"Registering Column Encryption Key Store Providers");
949950

950-
LOCK.lock();
951+
sLock.lock();
951952
try {
952953
if (null == clientKeyStoreProviders) {
953954
throw new SQLServerException(null, SQLServerException.getErrString("R_CustomKeyStoreProviderMapNull"),
@@ -988,7 +989,7 @@ public static void registerColumnEncryptionKeyStoreProviders(
988989
globalCustomColumnEncryptionKeyStoreProviders.put(providerName, provider);
989990
}
990991
} finally {
991-
LOCK.unlock();
992+
sLock.unlock();
992993
}
993994

994995
loggerExternal.exiting(loggingClassNameBase, "registerColumnEncryptionKeyStoreProviders",
@@ -1004,14 +1005,14 @@ public static void unregisterColumnEncryptionKeyStoreProviders() {
10041005
loggerExternal.entering(loggingClassNameBase, "unregisterColumnEncryptionKeyStoreProviders",
10051006
"Removing Column Encryption Key Store Provider");
10061007

1007-
LOCK.lock();
1008+
sLock.lock();
10081009
try {
10091010
if (null != globalCustomColumnEncryptionKeyStoreProviders) {
10101011
globalCustomColumnEncryptionKeyStoreProviders.clear();
10111012
globalCustomColumnEncryptionKeyStoreProviders = null;
10121013
}
10131014
} finally {
1014-
LOCK.unlock();
1015+
sLock.unlock();
10151016
}
10161017

10171018
loggerExternal.exiting(loggingClassNameBase, "unregisterColumnEncryptionKeyStoreProviders",
@@ -1233,15 +1234,15 @@ public static void setColumnEncryptionTrustedMasterKeyPaths(Map<String, List<Str
12331234
loggerExternal.entering(loggingClassNameBase, "setColumnEncryptionTrustedMasterKeyPaths",
12341235
"Setting Trusted Master Key Paths");
12351236

1236-
LOCK.lock();
1237+
sLock.lock();
12371238
try {
12381239
// Use upper case for server and instance names.
12391240
columnEncryptionTrustedMasterKeyPaths.clear();
12401241
for (Map.Entry<String, List<String>> entry : trustedKeyPaths.entrySet()) {
12411242
columnEncryptionTrustedMasterKeyPaths.put(entry.getKey().toUpperCase(), entry.getValue());
12421243
}
12431244
} finally {
1244-
LOCK.unlock();
1245+
sLock.unlock();
12451246
}
12461247

12471248
loggerExternal.exiting(loggingClassNameBase, "setColumnEncryptionTrustedMasterKeyPaths",
@@ -1260,12 +1261,12 @@ public static void updateColumnEncryptionTrustedMasterKeyPaths(String server, Li
12601261
loggerExternal.entering(loggingClassNameBase, "updateColumnEncryptionTrustedMasterKeyPaths",
12611262
"Updating Trusted Master Key Paths");
12621263

1263-
LOCK.lock();
1264+
sLock.lock();
12641265
try {
12651266
// Use upper case for server and instance names.
12661267
columnEncryptionTrustedMasterKeyPaths.put(server.toUpperCase(), trustedKeyPaths);
12671268
} finally {
1268-
LOCK.unlock();
1269+
sLock.unlock();
12691270
}
12701271

12711272
loggerExternal.exiting(loggingClassNameBase, "updateColumnEncryptionTrustedMasterKeyPaths",
@@ -1282,12 +1283,12 @@ public static void removeColumnEncryptionTrustedMasterKeyPaths(String server) {
12821283
loggerExternal.entering(loggingClassNameBase, "removeColumnEncryptionTrustedMasterKeyPaths",
12831284
"Removing Trusted Master Key Paths");
12841285

1285-
LOCK.lock();
1286+
sLock.lock();
12861287
try {
12871288
// Use upper case for server and instance names.
12881289
columnEncryptionTrustedMasterKeyPaths.remove(server.toUpperCase());
12891290
} finally {
1290-
LOCK.unlock();
1291+
sLock.unlock();
12911292
}
12921293

12931294
loggerExternal.exiting(loggingClassNameBase, "removeColumnEncryptionTrustedMasterKeyPaths",
@@ -1303,7 +1304,7 @@ public static Map<String, List<String>> getColumnEncryptionTrustedMasterKeyPaths
13031304
loggerExternal.entering(loggingClassNameBase, "getColumnEncryptionTrustedMasterKeyPaths",
13041305
"Getting Trusted Master Key Paths");
13051306

1306-
LOCK.lock();
1307+
sLock.lock();
13071308
try {
13081309
Map<String, List<String>> masterKeyPathCopy = new HashMap<>();
13091310

@@ -1316,12 +1317,12 @@ public static Map<String, List<String>> getColumnEncryptionTrustedMasterKeyPaths
13161317

13171318
return masterKeyPathCopy;
13181319
} finally {
1319-
LOCK.unlock();
1320+
sLock.unlock();
13201321
}
13211322
}
13221323

13231324
static List<String> getColumnEncryptionTrustedMasterKeyPaths(String server, Boolean[] hasEntry) {
1324-
LOCK.lock();
1325+
sLock.lock();
13251326
try {
13261327
if (columnEncryptionTrustedMasterKeyPaths.containsKey(server)) {
13271328
hasEntry[0] = true;
@@ -1331,7 +1332,7 @@ static List<String> getColumnEncryptionTrustedMasterKeyPaths(String server, Bool
13311332
return null;
13321333
}
13331334
} finally {
1334-
LOCK.unlock();
1335+
sLock.unlock();
13351336
}
13361337
}
13371338

@@ -1340,11 +1341,11 @@ static List<String> getColumnEncryptionTrustedMasterKeyPaths(String server, Bool
13401341
* request to acquire an access token.
13411342
*/
13421343
public static void clearUserTokenCache() {
1343-
LOCK.lock();
1344+
sLock.lock();
13441345
try {
13451346
PersistentTokenCacheAccessAspect.clearUserTokenCache();
13461347
} finally {
1347-
LOCK.unlock();
1348+
sLock.unlock();
13481349
}
13491350
}
13501351

@@ -7478,7 +7479,7 @@ void doSecurityCheck() {
74787479
*/
74797480
public static void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL,
74807481
TimeUnit unit) throws SQLServerException {
7481-
LOCK.lock();
7482+
sLock.lock();
74827483
try {
74837484
if (columnEncryptionKeyCacheTTL < 0 || unit.equals(TimeUnit.MILLISECONDS)
74847485
|| unit.equals(TimeUnit.MICROSECONDS) || unit.equals(TimeUnit.NANOSECONDS)) {
@@ -7488,16 +7489,16 @@ public static void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTT
74887489

74897490
columnEncryptionKeyCacheTtl = TimeUnit.SECONDS.convert(columnEncryptionKeyCacheTTL, unit);
74907491
} finally {
7491-
LOCK.unlock();
7492+
sLock.unlock();
74927493
}
74937494
}
74947495

74957496
static long getColumnEncryptionKeyCacheTtl() {
7496-
LOCK.lock();
7497+
sLock.lock();
74977498
try {
74987499
return columnEncryptionKeyCacheTtl;
74997500
} finally {
7500-
LOCK.unlock();
7501+
sLock.unlock();
75017502
}
75027503
}
75037504

0 commit comments

Comments
 (0)