Skip to content
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

SNOW-1226600: Add parameter to disable SAML URL check #1748

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/net/snowflake/client/core/SFLoginInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class SFLoginInput {
private String inFlightCtx; // Opaque string sent for Snowsight account activation

private boolean disableConsoleLogin = true;
private boolean disableSamlUrlCheck = false;

// Additional headers to add for Snowsight.
Map<String, String> additionalHttpHeadersForSnowsight;
Expand Down Expand Up @@ -378,6 +379,15 @@ SFLoginInput setInFlightCtx(String inFlightCtx) {
return this;
}

boolean getDisableSamlUrlCheck() {
return disableSamlUrlCheck;
}

SFLoginInput setDisableSamlUrlCheck(boolean disableSamlUrlCheck) {
this.disableSamlUrlCheck = disableSamlUrlCheck;
return this;
}

Map<String, String> getAdditionalHttpHeadersForSnowsight() {
return additionalHttpHeadersForSnowsight;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,12 @@ public synchronized void open() throws SFException, SnowflakeSQLException {
connectionPropertiesMap.get(SFSessionProperty.DISABLE_CONSOLE_LOGIN) != null
? getBooleanValue(
connectionPropertiesMap.get(SFSessionProperty.DISABLE_CONSOLE_LOGIN))
: true);
: true)
.setDisableSamlUrlCheck(
connectionPropertiesMap.get(SFSessionProperty.DISABLE_SAML_URL_CHECK) != null
? getBooleanValue(
connectionPropertiesMap.get(SFSessionProperty.DISABLE_SAML_URL_CHECK))
: false);

// Enable or disable OOB telemetry based on connection parameter. Default is disabled.
// The value may still change later when session parameters from the server are read.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public enum SFSessionProperty {

DISABLE_GCS_DEFAULT_CREDENTIALS("disableGcsDefaultCredentials", false, Boolean.class),

JDBC_ARROW_TREAT_DECIMAL_AS_INT("JDBC_ARROW_TREAT_DECIMAL_AS_INT", false, Boolean.class);
JDBC_ARROW_TREAT_DECIMAL_AS_INT("JDBC_ARROW_TREAT_DECIMAL_AS_INT", false, Boolean.class),

DISABLE_SAML_URL_CHECK("disableSamlUrlCheck", false, Boolean.class);

// property key in string
private String propertyKey;
Expand Down
43 changes: 23 additions & 20 deletions src/main/java/net/snowflake/client/core/SessionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1154,26 +1154,29 @@ private static String federatedFlowStep4(
loginInput.getHttpClientSettingsKey());

// step 5
String postBackUrl = getPostBackUrlFromHTML(responseHtml);
if (!isPrefixEqual(postBackUrl, loginInput.getServerUrl())) {
URL idpDestinationUrl = new URL(postBackUrl);
URL clientDestinationUrl = new URL(loginInput.getServerUrl());
String idpDestinationHostName = idpDestinationUrl.getHost();
String clientDestinationHostName = clientDestinationUrl.getHost();

logger.error(
"The Snowflake hostname specified in the client connection {} does not match "
+ "the destination hostname in the SAML response returned by the IdP: {}",
clientDestinationHostName,
idpDestinationHostName);

// Session is in process of getting created, so exception constructor takes in null session
// value
throw new SnowflakeSQLLoggedException(
null,
ErrorCode.IDP_INCORRECT_DESTINATION.getMessageCode(),
SqlState.SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
/* session = */ );
if (!loginInput.getDisableSamlUrlCheck()) {
String postBackUrl = getPostBackUrlFromHTML(responseHtml);
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
if (!isPrefixEqual(postBackUrl, loginInput.getServerUrl())) {
URL idpDestinationUrl = new URL(postBackUrl);
URL clientDestinationUrl = new URL(loginInput.getServerUrl());
String idpDestinationHostName = idpDestinationUrl.getHost();
String clientDestinationHostName = clientDestinationUrl.getHost();

logger.error(
"The Snowflake hostname specified in the client connection {} does not match "
+ "the destination hostname in the SAML response returned by the IdP: {}",
clientDestinationHostName,
idpDestinationHostName);

// Session is in process of getting created, so exception constructor takes in null
// session
// value
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
throw new SnowflakeSQLLoggedException(
null,
ErrorCode.IDP_INCORRECT_DESTINATION.getMessageCode(),
SqlState.SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
/* session = */ );
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
}
}
} catch (IOException | URISyntaxException ex) {
handleFederatedFlowError(loginInput, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ private SFLoginInput createOktaLoginInput() {
input.setLoginTimeout(1000);
input.setSessionParameters(new HashMap<>());
input.setAuthenticator("https://testauth.okta.com");
input.setDisableSamlUrlCheck(false);
sfc-gh-ext-simba-jy marked this conversation as resolved.
Show resolved Hide resolved
return input;
}

Expand Down
Loading