forked from microsoft/mssql-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using multiple JAAS configurations and override the configurati…
…on per connection properties. We also set a different default LoginConfig for IBM JVM, so it should work well with user-provided passwords and username for Kerberos. Should solve microsoft#66 for IBM JVM.
- Loading branch information
1 parent
c1f88c5
commit 02f1372
Showing
3 changed files
with
77 additions
and
77 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/main/java/com/microsoft/sqlserver/jdbc/JaasConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Microsoft JDBC Driver for SQL Server | ||
* | ||
* Copyright(c) Microsoft Corporation All rights reserved. | ||
* | ||
* This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information. | ||
*/ | ||
package com.microsoft.sqlserver.jdbc; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.security.auth.login.AppConfigurationEntry; | ||
import javax.security.auth.login.Configuration; | ||
|
||
/** | ||
* This class overrides JAAS Configuration and always provide a configuration is not defined for default configuration. | ||
*/ | ||
public class JaasConfiguration extends Configuration { | ||
|
||
private final Configuration delegate; | ||
private AppConfigurationEntry[] defaultValue; | ||
|
||
private static AppConfigurationEntry[] generateDefaultConfiguration() { | ||
if (Util.isIBM()) { | ||
Map<String, String> confDetailsWithoutPassword = new HashMap<String, String>(); | ||
confDetailsWithoutPassword.put("useDefaultCcache", "true"); | ||
confDetailsWithoutPassword.put("moduleBanner", "false"); | ||
Map<String, String> confDetailsWithPassword = new HashMap<String, String>(); | ||
confDetailsWithPassword.putAll(confDetailsWithPassword); | ||
confDetailsWithPassword.put("useDefaultCcache", "false"); | ||
// We generated a two configurations fallback that is suitable for password and password-less authentication | ||
return new AppConfigurationEntry[] { | ||
new AppConfigurationEntry("com.ibm.security.auth.module.Krb5LoginModule", AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, | ||
confDetailsWithoutPassword), | ||
new AppConfigurationEntry("com.ibm.security.auth.module.Krb5LoginModule", AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, | ||
confDetailsWithPassword)}; | ||
} | ||
else { | ||
Map<String, String> confDetails = new HashMap<String, String>(); | ||
confDetails.put("useTicketCache", "true"); | ||
return new AppConfigurationEntry[] {new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", | ||
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, confDetails)}; | ||
} | ||
} | ||
|
||
/** | ||
* Package protected constructor. | ||
* | ||
* @param delegate | ||
* a possibly null delegate | ||
*/ | ||
JaasConfiguration(Configuration delegate) { | ||
this.delegate = delegate; | ||
this.defaultValue = generateDefaultConfiguration(); | ||
} | ||
|
||
@Override | ||
public AppConfigurationEntry[] getAppConfigurationEntry(String name) { | ||
AppConfigurationEntry[] conf = delegate == null ? null : delegate.getAppConfigurationEntry(name); | ||
// We return our configuration only if user requested default one | ||
// In case where user did request another JAAS Configuration name, we expect he knows what he is doing. | ||
if (conf == null && name.equals(SQLServerDriverStringProperty.JAAS_CONFIG_NAME.getDefaultValue())) { | ||
return defaultValue; | ||
} | ||
return conf; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters