Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed how Kerberos authentication acquires subject to provide compatibility for Kerberos with Java 23 and above #2539

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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);

Check warning on line 102 in src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java#L101-L102

Added lines #L101 - L102 were not covered by tests

} catch (UnsupportedOperationException ue) {

Check warning on line 104 in src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L104 was not covered by tests
if (authLogger.isLoggable(Level.FINE)) {
tkyc marked this conversation as resolved.
Show resolved Hide resolved
authLogger.fine("JDK version does not support Subject.getSubject(), " +
"falling back to Subject.current() : " + ue.getMessage());

Check warning on line 107 in src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java#L106-L107

Added lines #L106 - L107 were not covered by tests
}

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

Check warning on line 113 in src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java#L110-L113

Added lines #L110 - L113 were not covered by tests

if (null == currentSubject) {
if (useDefaultJaas) {
lc = new LoginContext(configName, null, callback, new JaasConfiguration(null));
Expand Down Expand Up @@ -159,6 +175,12 @@
}
con.terminate(SQLServerException.DRIVER_ERROR_NONE,
SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {

Check warning on line 178 in src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L178 was not covered by tests
if (authLogger.isLoggable(Level.FINER)) {
authLogger.finer(toString() + "initAuthInit failed reflection exception:-" + ex);

Check warning on line 180 in src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L180 was not covered by tests
}
con.terminate(SQLServerException.DRIVER_ERROR_NONE,
SQLServerException.getErrString("R_integratedAuthenticationFailed"), ex);

Check warning on line 183 in src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java#L182-L183

Added lines #L182 - L183 were not covered by tests
}
}

Expand Down