Skip to content

Commit be9bd4a

Browse files
committed
IBM Semeru Runtime Certified Edition for z/OS, Kerberos and mssql-jdbc don't work together #2576
1 parent 5bb3353 commit be9bd4a

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java

+24-16
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,32 @@ public class JaasConfiguration extends Configuration {
1919
private final Configuration delegate;
2020
private AppConfigurationEntry[] defaultValue;
2121

22-
private static AppConfigurationEntry[] generateDefaultConfiguration() {
23-
if (Util.isIBM()) {
24-
Map<String, String> confDetailsWithoutPassword = new HashMap<>();
25-
confDetailsWithoutPassword.put("useDefaultCcache", "true");
26-
Map<String, String> confDetailsWithPassword = new HashMap<>();
27-
// We generated a two configurations fallback that is suitable for password and password-less authentication
28-
// See
29-
// https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.security.component.80.doc/security-component/jgssDocs/jaas_login_user.html
30-
final String ibmLoginModule = "com.ibm.security.auth.module.Krb5LoginModule";
31-
return new AppConfigurationEntry[] {
32-
new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
33-
confDetailsWithoutPassword),
34-
new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
35-
confDetailsWithPassword)};
36-
} else {
22+
private static AppConfigurationEntry[] generateDefaultConfiguration() throws SQLServerException {
23+
try {
24+
Class.forName("com.sun.security.auth.module.Krb5LoginModule");
3725
Map<String, String> confDetails = new HashMap<>();
3826
confDetails.put("useTicketCache", "true");
3927
return new AppConfigurationEntry[] {
4028
new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
4129
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, confDetails)};
30+
} catch (ClassNotFoundException e) {
31+
try {
32+
Class.forName("com.ibm.security.auth.module.Krb5LoginModule");
33+
Map<String, String> confDetailsWithoutPassword = new HashMap<>();
34+
confDetailsWithoutPassword.put("useDefaultCcache", "true");
35+
Map<String, String> confDetailsWithPassword = new HashMap<>();
36+
// We generated a two configurations fallback that is suitable for password and password-less authentication
37+
// See
38+
// https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.security.component.80.doc/security-component/jgssDocs/jaas_login_user.html
39+
final String ibmLoginModule = "com.ibm.security.auth.module.Krb5LoginModule";
40+
return new AppConfigurationEntry[] {
41+
new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
42+
confDetailsWithoutPassword),
43+
new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
44+
confDetailsWithPassword)};
45+
} catch (ClassNotFoundException ex) {
46+
throw new SQLServerException(SQLServerException.getErrString("R_moduleNotFound"), null);
47+
}
4248
}
4349
}
4450

@@ -47,8 +53,10 @@ private static AppConfigurationEntry[] generateDefaultConfiguration() {
4753
*
4854
* @param delegate
4955
* a possibly null delegate
56+
* @throws SQLServerException
57+
* if neither Kerberos module is found: com.sun.security.auth.module.Krb5LoginModule or com.ibm.security.auth.module.Krb5LoginModule
5058
*/
51-
JaasConfiguration(Configuration delegate) {
59+
JaasConfiguration(Configuration delegate) throws SQLServerException {
5260
this.delegate = delegate;
5361
this.defaultValue = generateDefaultConfiguration();
5462
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ final class KerbAuthentication extends SSPIAuthentication {
4545
static {
4646
// Overrides the default JAAS configuration loader.
4747
// This one will forward to the default one in all cases but the default configuration is empty.
48-
Configuration.setConfiguration(new JaasConfiguration(Configuration.getConfiguration()));
48+
try {
49+
Configuration.setConfiguration(new JaasConfiguration(Configuration.getConfiguration()));
50+
} catch (SQLServerException e) {
51+
e.printStackTrace();
52+
}
4953
}
5054

5155
/**

0 commit comments

Comments
 (0)