-
Notifications
You must be signed in to change notification settings - Fork 41
SQL-2920: Add configuration properties to support GSSAPI #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bucaojit
wants to merge
4
commits into
mongodb:master
Choose a base branch
from
bucaojit:SQL-2920
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
595ecc0
SQL-2920: Add configuration properties to support GSSAPI
bucaojit 10bd5ad
SQL-2920: Fix null password check
bucaojit 33588a0
Update src/main/java/com/mongodb/jdbc/MongoConnection.java
bucaojit ceea88e
Update src/main/java/com/mongodb/jdbc/MongoDriver.java
bucaojit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.mongodb.jdbc; | ||
|
||
import static com.mongodb.AuthenticationMechanism.GSSAPI; | ||
import static com.mongodb.AuthenticationMechanism.MONGODB_OIDC; | ||
import static com.mongodb.AuthenticationMechanism.MONGODB_X509; | ||
|
||
|
@@ -184,28 +185,59 @@ private MongoClientSettings createMongoClientSettings( | |
if (credential != null) { | ||
AuthenticationMechanism authMechanism = credential.getAuthenticationMechanism(); | ||
|
||
if (authMechanism != null && authMechanism.equals(MONGODB_OIDC)) { | ||
// Handle OIDC authentication | ||
OidcCallback oidcCallback = new JdbcOidcCallback(this.logger); | ||
credential = | ||
MongoCredential.createOidcCredential( | ||
connectionProperties.getConnectionString().getUsername()) | ||
.withMechanismProperty( | ||
MongoCredential.OIDC_HUMAN_CALLBACK_KEY, oidcCallback); | ||
settingsBuilder.credential(credential); | ||
} else if (authMechanism != null && authMechanism.equals(MONGODB_X509)) { | ||
String pemPath = connectionProperties.getX509PemPath(); | ||
if (pemPath == null || pemPath.isEmpty()) { | ||
pemPath = System.getenv(MONGODB_JDBC_X509_CLIENT_CERT_PATH); | ||
} | ||
if (pemPath == null || pemPath.isEmpty()) { | ||
throw new IllegalStateException( | ||
"PEM file path is required for X.509 authentication but was not provided."); | ||
} | ||
if (authMechanism != null) { | ||
if (authMechanism.equals(MONGODB_OIDC)) { | ||
// Handle OIDC authentication | ||
OidcCallback oidcCallback = new JdbcOidcCallback(this.logger); | ||
credential = | ||
MongoCredential.createOidcCredential( | ||
connectionProperties | ||
.getConnectionString() | ||
.getUsername()) | ||
.withMechanismProperty( | ||
MongoCredential.OIDC_HUMAN_CALLBACK_KEY, oidcCallback); | ||
settingsBuilder.credential(credential); | ||
} else if (authMechanism.equals(GSSAPI)) { | ||
String jaasPath = connectionProperties.getJaasConfigPath(); | ||
if (jaasPath != null && !jaasPath.isEmpty()) { | ||
System.setProperty("java.security.auth.login.config", jaasPath); | ||
logger.log(Level.INFO, "Using custom JAAS config: " + jaasPath); | ||
} else { | ||
String existingConfig = | ||
System.getProperty("java.security.auth.login.config"); | ||
if (existingConfig != null) { | ||
logger.log( | ||
Level.INFO, | ||
"Using JAAS config from system property: " + existingConfig); | ||
} else { | ||
logger.log( | ||
Level.INFO, | ||
"No JAAS config specified. Relying on classpath or JVM defaults."); | ||
} | ||
} | ||
|
||
String gssNative = connectionProperties.getGssNativeMode(); | ||
if (gssNative != null && !gssNative.isEmpty()) { | ||
System.setProperty("sun.security.jgss.native", gssNative); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, we want to look at using a local conf to make sure we don't impact other drivers when using Tableau for example.
|
||
logger.log( | ||
Level.INFO, "Set sun.security.jgss.native = " + gssNative.trim()); | ||
} | ||
|
||
X509Authentication x509Authentication = new X509Authentication(logger); | ||
x509Authentication.configureX509Authentication( | ||
settingsBuilder, pemPath, this.x509Passphrase); | ||
settingsBuilder.credential(credential); | ||
} else if (authMechanism.equals(MONGODB_X509)) { | ||
String pemPath = connectionProperties.getX509PemPath(); | ||
if (pemPath == null || pemPath.isEmpty()) { | ||
pemPath = System.getenv(MONGODB_JDBC_X509_CLIENT_CERT_PATH); | ||
} | ||
if (pemPath == null || pemPath.isEmpty()) { | ||
throw new IllegalStateException( | ||
"PEM file path is required for X.509 authentication but was not provided."); | ||
} | ||
|
||
X509Authentication x509Authentication = new X509Authentication(logger); | ||
x509Authentication.configureX509Authentication( | ||
settingsBuilder, pemPath, this.x509Passphrase); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conf changes will affect more than our driver. It will affect everything currently running JVM.
This is a problem, especially with tools like Tableau. We need to talk about it a bit more.
Here is a starting point from Gemini on how we could use a local conf (possibly, we want to try it out to make sure this is true):