Skip to content

Commit

Permalink
Deprecation of Security Manager fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyc committed Nov 14, 2024
1 parent ef6b770 commit 6259d04
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 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 @@ -48,7 +50,7 @@ final class KerbAuthentication extends SSPIAuthentication {

/**
* Initializes the Kerberos client security context
*
*
* @throws SQLServerException
*/
@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -87,15 +89,29 @@ private void initAuthInit() throws SQLServerException {
if (authLogger.isLoggable(Level.WARNING)) {
authLogger.warning(toString()
+ String.format("Using default JAAS configuration, configured %s=%s will not be used.",
SQLServerDriverStringProperty.JAAS_CONFIG_NAME, configName));
SQLServerDriverStringProperty.JAAS_CONFIG_NAME, configName));
}
configName = SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue();
}
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 Expand Up @@ -217,7 +239,7 @@ private byte[] initAuthHandShake(byte[] pin, boolean[] done) throws SQLServerExc
}

/**
*
*
* @param con
* @param address
* @param port
Expand Down

0 comments on commit 6259d04

Please sign in to comment.