Skip to content

Commit

Permalink
Logic to add config for loginContext(if-else)
Browse files Browse the repository at this point in the history
  • Loading branch information
muskan124947 committed Jan 23, 2025
1 parent 2a3d372 commit defa21d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ 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.
Configuration.setConfiguration(new JaasConfiguration(Configuration.getConfiguration()));
}

/**
* Initializes the Kerberos client security context
*
Expand Down Expand Up @@ -114,7 +108,7 @@ private void initAuthInit() throws SQLServerException {

if (null == currentSubject) {
if (useDefaultJaas) {
lc = new LoginContext(configName, null, callback, new JaasConfiguration(null));
lc = new LoginContext(configName, null, callback, new JaasConfiguration(Configuration.getConfiguration()));

Check warning on line 111 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#L111

Added line #L111 was not covered by tests
} else {
lc = new LoginContext(configName, callback);
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,32 @@ public class KerberosTest extends AbstractTest {

@BeforeAll
public static void setupTests() throws Exception {
setJaasConfiguration();
setConnection();
}

private static void setJaasConfiguration() {
AppConfigurationEntry[] entries = new AppConfigurationEntry[]{
new AppConfigurationEntry(
"com.sun.security.auth.module.Krb5LoginModule",
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
new HashMap<String, Object>() {{
put("useTicketCache", "true");
put("renewTGT", "true");
}}
)
};
Configuration.setConfiguration(new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
if ("SQLJDBCDriver".equals(name)) {
return entries;
}
return null;
}
});
}

@Test
public void testUseDefaultJaasConfigConnectionStringPropertyTrue() throws Exception {
String connectionStringUseDefaultJaasConfig = connectionStringKerberos + ";useDefaultJaasConfig=true;";
Expand Down

0 comments on commit defa21d

Please sign in to comment.