diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java b/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java index 6f8f30a29..d02238196 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java @@ -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; @@ -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)); @@ -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); } }