Skip to content

Commit

Permalink
Added error string and useIbmModule boolean flag
Browse files Browse the repository at this point in the history
  • Loading branch information
muskan124947 committed Jan 24, 2025
1 parent b698940 commit ab0181a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
41 changes: 24 additions & 17 deletions src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,39 @@ public class JaasConfiguration extends Configuration {
private final Configuration delegate;
private AppConfigurationEntry[] defaultValue;

private static boolean useIbmModule = false;

Check warning on line 22 in src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L22 was not covered by tests

private static AppConfigurationEntry[] generateDefaultConfiguration() throws SQLServerException {
try {
if (useIbmModule) {
return loadIbmModule();

Check warning on line 27 in src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L27 was not covered by tests
}
Class.forName("com.sun.security.auth.module.Krb5LoginModule");
Map<String, String> confDetails = new HashMap<>();
confDetails.put("useTicketCache", "true");
return new AppConfigurationEntry[] {

Check warning on line 32 in src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java#L29-L32

Added lines #L29 - L32 were not covered by tests
new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, confDetails)};
} catch (ClassNotFoundException e) {
try {
Class.forName("com.ibm.security.auth.module.Krb5LoginModule");
Map<String, String> confDetailsWithoutPassword = new HashMap<>();
confDetailsWithoutPassword.put("useDefaultCcache", "true");
Map<String, String> confDetailsWithPassword = new HashMap<>();
// We generated a two configurations fallback that is suitable for password and password-less authentication
// See
// https://www.ibm.com/support/knowledgecenter/SSYKE2_8.0.0/com.ibm.java.security.component.80.doc/security-component/jgssDocs/jaas_login_user.html
final String ibmLoginModule = "com.ibm.security.auth.module.Krb5LoginModule";
return new AppConfigurationEntry[] {
new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
confDetailsWithoutPassword),
new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
confDetailsWithPassword)};
} catch (ClassNotFoundException ex) {
throw new SQLServerException(SQLServerException.getErrString("R_moduleNotFound"), null);
}
return loadIbmModule();

Check warning on line 36 in src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java#L35-L36

Added lines #L35 - L36 were not covered by tests
}
}

private static AppConfigurationEntry[] loadIbmModule() throws SQLServerException {
try {
Class.forName("com.ibm.security.auth.module.Krb5LoginModule");
useIbmModule = true;

Check warning on line 43 in src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java#L42-L43

Added lines #L42 - L43 were not covered by tests
Map<String, String> confDetailsWithoutPassword = new HashMap<>();
confDetailsWithoutPassword.put("useDefaultCcache", "true");
Map<String, String> confDetailsWithPassword = new HashMap<>();
final String ibmLoginModule = "com.ibm.security.auth.module.Krb5LoginModule";
return new AppConfigurationEntry[] {
new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
confDetailsWithoutPassword),
new AppConfigurationEntry(ibmLoginModule, AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
confDetailsWithPassword)};
} catch (ClassNotFoundException ex) {
throw new SQLServerException(SQLServerException.getErrString("R_moduleNotFound"), null);

Check warning on line 54 in src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java#L53-L54

Added lines #L53 - L54 were not covered by tests
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.logging.Level;

import javax.security.auth.Subject;
//import javax.security.auth.login.Configuration;
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;

Expand Down Expand Up @@ -42,15 +42,15 @@ final class KerbAuthentication extends SSPIAuthentication {
private boolean useDefaultNativeGSSCredential = false;
private GSSContext peerContext = null;

// static {
// // Overrides the default JAAS configuration loader.
// // This one will forward to the default one in all cases but the default configuration is empty.
// try {
// Configuration.setConfiguration(new JaasConfiguration(Configuration.getConfiguration()));
// } catch (SQLServerException e) {
// e.printStackTrace();
// }
// }
static {
// Overrides the default JAAS configuration loader.
// This one will forward to the default one in all cases but the default configuration is empty.
try {
Configuration.setConfiguration(new JaasConfiguration(Configuration.getConfiguration()));
} catch (SQLServerException e) {
e.printStackTrace();
}

Check warning on line 52 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#L49-L52

Added lines #L49 - L52 were not covered by tests
}

/**
* Initializes the Kerberos client security context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ protected Object[][] getContents() {
{"R_InvalidRuleFormat", "Wrong number of parameters supplied to rule. Number of parameters: {0}, expected: 2 or 3."},
{"R_InvalidRetryInterval", "Current retry interval: {0}, is longer than queryTimeout: {1}."},
{"R_UnableToFindClass", "Unable to locate specified class: {0}"},
{"R_moduleNotFound", "Neither com.sun.security.auth.module.Krb5LoginModule nor com.ibm.security.auth.module.Krb5LoginModule was found."},
};
}
// @formatter:on

0 comments on commit ab0181a

Please sign in to comment.