Skip to content

Commit 5297987

Browse files
authored
Deprecation of Security Manager fix (#2539)
1 parent 38564d9 commit 5297987

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package com.microsoft.sqlserver.jdbc;
77

8+
import java.lang.reflect.InvocationTargetException;
9+
import java.lang.reflect.Method;
810
import java.security.PrivilegedActionException;
911
import java.security.PrivilegedExceptionAction;
1012
import java.text.MessageFormat;
@@ -94,8 +96,22 @@ private void initAuthInit() throws SQLServerException {
9496
Subject currentSubject;
9597
KerbCallback callback = new KerbCallback(con);
9698
try {
97-
java.security.AccessControlContext context = java.security.AccessController.getContext();
98-
currentSubject = Subject.getSubject(context);
99+
100+
try {
101+
java.security.AccessControlContext context = java.security.AccessController.getContext();
102+
currentSubject = Subject.getSubject(context);
103+
104+
} catch (UnsupportedOperationException ue) {
105+
if (authLogger.isLoggable(Level.FINE)) {
106+
authLogger.fine("JDK version does not support Subject.getSubject(), " +
107+
"falling back to Subject.current() : " + ue.getMessage());
108+
}
109+
110+
Method current = Subject.class.getDeclaredMethod("current");
111+
current.setAccessible(true);
112+
currentSubject = (Subject) current.invoke(null);
113+
}
114+
99115
if (null == currentSubject) {
100116
if (useDefaultJaas) {
101117
lc = new LoginContext(configName, null, callback, new JaasConfiguration(null));
@@ -159,6 +175,12 @@ private void initAuthInit() throws SQLServerException {
159175
}
160176
con.terminate(SQLServerException.DRIVER_ERROR_NONE,
161177
SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
178+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
179+
if (authLogger.isLoggable(Level.FINER)) {
180+
authLogger.finer(toString() + "initAuthInit failed reflection exception:-" + ex);
181+
}
182+
con.terminate(SQLServerException.DRIVER_ERROR_NONE,
183+
SQLServerException.getErrString("R_integratedAuthenticationFailed"), ex);
162184
}
163185
}
164186

0 commit comments

Comments
 (0)