|
5 | 5 |
|
6 | 6 | package com.microsoft.sqlserver.jdbc; |
7 | 7 |
|
| 8 | +import java.lang.reflect.InvocationTargetException; |
| 9 | +import java.lang.reflect.Method; |
8 | 10 | import java.security.PrivilegedActionException; |
9 | 11 | import java.security.PrivilegedExceptionAction; |
10 | 12 | import java.text.MessageFormat; |
@@ -94,8 +96,22 @@ private void initAuthInit() throws SQLServerException { |
94 | 96 | Subject currentSubject; |
95 | 97 | KerbCallback callback = new KerbCallback(con); |
96 | 98 | try { |
97 | | - java.security.AccessControlContext context = java.security.AccessController.getContext(); |
98 | | - currentSubject = Subject.getSubject(context); |
| 99 | + |
| 100 | + try { |
| 101 | + java.security.AccessControlContext context = java.security.AccessController.getContext(); |
| 102 | + currentSubject = Subject.getSubject(context); |
| 103 | + |
| 104 | + } catch (UnsupportedOperationException ue) { |
| 105 | + if (authLogger.isLoggable(Level.FINE)) { |
| 106 | + authLogger.fine("JDK version does not support Subject.getSubject(), " + |
| 107 | + "falling back to Subject.current() : " + ue.getMessage()); |
| 108 | + } |
| 109 | + |
| 110 | + Method current = Subject.class.getDeclaredMethod("current"); |
| 111 | + current.setAccessible(true); |
| 112 | + currentSubject = (Subject) current.invoke(null); |
| 113 | + } |
| 114 | + |
99 | 115 | if (null == currentSubject) { |
100 | 116 | if (useDefaultJaas) { |
101 | 117 | lc = new LoginContext(configName, null, callback, new JaasConfiguration(null)); |
@@ -159,6 +175,12 @@ private void initAuthInit() throws SQLServerException { |
159 | 175 | } |
160 | 176 | con.terminate(SQLServerException.DRIVER_ERROR_NONE, |
161 | 177 | SQLServerException.getErrString("R_integratedAuthenticationFailed"), ge); |
| 178 | + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { |
| 179 | + if (authLogger.isLoggable(Level.FINER)) { |
| 180 | + authLogger.finer(toString() + "initAuthInit failed reflection exception:-" + ex); |
| 181 | + } |
| 182 | + con.terminate(SQLServerException.DRIVER_ERROR_NONE, |
| 183 | + SQLServerException.getErrString("R_integratedAuthenticationFailed"), ex); |
162 | 184 | } |
163 | 185 | } |
164 | 186 |
|
|
0 commit comments