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 61e2a52
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);

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)) {
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 @@ private void initAuthInit() throws SQLServerException {
}
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

0 comments on commit 61e2a52

Please sign in to comment.