Skip to content

Commit

Permalink
Deprecation of Security Manager fix (#2539)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyc authored Nov 20, 2024
1 parent 38564d9 commit 5297987
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.microsoft.sqlserver.jdbc;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.text.MessageFormat;
Expand Down Expand Up @@ -94,8 +96,22 @@ private void initAuthInit() throws SQLServerException {
Subject currentSubject;
KerbCallback callback = new KerbCallback(con);
try {
java.security.AccessControlContext context = java.security.AccessController.getContext();
currentSubject = Subject.getSubject(context);

try {
java.security.AccessControlContext context = java.security.AccessController.getContext();
currentSubject = Subject.getSubject(context);

} catch (UnsupportedOperationException ue) {
if (authLogger.isLoggable(Level.FINE)) {
authLogger.fine("JDK version does not support Subject.getSubject(), " +
"falling back to Subject.current() : " + ue.getMessage());
}

Method current = Subject.class.getDeclaredMethod("current");
current.setAccessible(true);
currentSubject = (Subject) current.invoke(null);
}

if (null == currentSubject) {
if (useDefaultJaas) {
lc = new LoginContext(configName, null, callback, new JaasConfiguration(null));
Expand Down Expand Up @@ -159,6 +175,12 @@ private void initAuthInit() throws SQLServerException {
}
con.terminate(SQLServerException.DRIVER_ERROR_NONE,
SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
if (authLogger.isLoggable(Level.FINER)) {
authLogger.finer(toString() + "initAuthInit failed reflection exception:-" + ex);
}
con.terminate(SQLServerException.DRIVER_ERROR_NONE,
SQLServerException.getErrString("R_integratedAuthenticationFailed"), ex);
}
}

Expand Down

0 comments on commit 5297987

Please sign in to comment.