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

Added retry logic for authentication with Okta #1661

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
28 changes: 14 additions & 14 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
**JDBC Driver 3.15.0**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \||Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.14.5**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \||Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.14.4**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \||Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.14.3**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \||Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.14.2**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \||Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.14.1**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \||Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.14.0**

- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \||Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.13.33**

- \|| Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \|| Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.13.32**


- \|| Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \|| Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.13.31**

- \|| Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \|| Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.13.30**

- \|| Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \|| Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.13.29**

- \|| Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \|| Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.13.28**

- \|| Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \|| Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.13.27**

- \|| Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
- \|| Please Refer to Release Notes at https://community.snowflake.com/s/article/JDBC-Driver-Release-Notes

**JDBC Driver 3.13.26**

Expand Down
10 changes: 0 additions & 10 deletions parent-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<commons.pool.version>1.5.4</commons.pool.version>
<c3p0.version>0.9.5.4</c3p0.version>
<google.api.grpc.version>2.22.0</google.api.grpc.version>
<google.auth.library.oauth2.http.version>1.19.0</google.auth.library.oauth2.http.version>
<google.cloud.core.version>2.21.0</google.cloud.core.version>
<google.cloud.storage.version>2.22.6</google.cloud.storage.version>
<google.code.gson.version>2.10.1</google.code.gson.version>
Expand Down Expand Up @@ -162,11 +161,6 @@
<artifactId>proto-google-common-protos</artifactId>
<version>${google.api.grpc.version}</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>${google.auth.library.oauth2.http.version}</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
Expand Down Expand Up @@ -520,10 +514,6 @@
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/snowflake/client/core/JsonSqlInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
int columnSubType = fieldMetadata.getType();
int scale = fieldMetadata.getScale();

Timestamp result =
SqlInputTimestampUtil.getTimestampFromType(
columnSubType, (String) value, session, sessionTimeZone, tz);

if (result != null) {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Array;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.SQLInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.math.BigDecimal;
import java.sql.Array;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.SQLInput;
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/net/snowflake/client/core/SFBaseSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ public abstract class SFBaseSession {
// we need to allow for it to maintain backwards compatibility.
private boolean enablePatternSearch = true;

/** Disable lookup for default credentials by GCS library */
private boolean disableGcsDefaultCredentials = false;

private Map<String, Object> commonParameters;

private boolean isJdbcArrowTreatDecimalAsInt = true;
Expand Down Expand Up @@ -748,14 +745,6 @@ public void setEnablePatternSearch(boolean enablePatternSearch) {
this.enablePatternSearch = enablePatternSearch;
}

public boolean getDisableGcsDefaultCredentials() {
return disableGcsDefaultCredentials;
}

public void setDisableGcsDefaultCredentials(boolean disableGcsDefaultCredentials) {
this.disableGcsDefaultCredentials = disableGcsDefaultCredentials;
}

public int getClientResultChunkSize() {
return clientResultChunkSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import java.math.BigDecimal;
import java.sql.Array;
import java.sql.Date;
import java.sql.SQLInput;
import java.sql.Time;
Expand Down Expand Up @@ -88,6 +87,7 @@ public Object getObject(int columnIndex) throws SFException {
} else {
throw new SFException(ErrorCode.FEATURE_UNSUPPORTED, "data type: " + type);
}

case Types.ARRAY:
if (StructureTypeHelper.isStructureTypeEnabled()) {
return getArray(columnIndex);
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/net/snowflake/client/core/SFResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,22 @@ public SFResultSet(
Telemetry telemetryClient,
boolean sortResult)
throws SQLException {
super(resultSetSerializable.getTimeZone(), new Converters(session, resultSetSerializable));
super(
resultSetSerializable.getTimeZone(),
new Converters(
resultSetSerializable.getTimeZone(),
session,
resultSetSerializable.getResultVersion(),
resultSetSerializable.isHonorClientTZForTimestampNTZ(),
resultSetSerializable.getTreatNTZAsUTC(),
resultSetSerializable.getUseSessionTimezone(),
resultSetSerializable.getFormatDateWithTimeZone(),
resultSetSerializable.getBinaryFormatter(),
resultSetSerializable.getDateFormatter(),
resultSetSerializable.getTimeFormatter(),
resultSetSerializable.getTimestampNTZFormatter(),
resultSetSerializable.getTimestampLTZFormatter(),
resultSetSerializable.getTimestampTZFormatter()));
this.resultSetSerializable = resultSetSerializable;
this.columnCount = 0;
this.sortResult = sortResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ public List<Boolean> getIsAutoIncrementList() {
return isAutoIncrementList;
}

@SnowflakeJdbcInternalApi
public List<SnowflakeColumnMetadata> getColumnMetadata() {
List<SnowflakeColumnMetadata> getColumnMetadata() {
return columnMetadata;
}
}
5 changes: 0 additions & 5 deletions src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,6 @@ public void addSFSessionProperty(String propertyName, Object propertyValue) thro
setEnablePatternSearch(getBooleanValue(propertyValue));
}
break;
case DISABLE_GCS_DEFAULT_CREDENTIALS:
if (propertyValue != null) {
setDisableGcsDefaultCredentials(getBooleanValue(propertyValue));
}
break;

case JDBC_ARROW_TREAT_DECIMAL_AS_INT:
if (propertyValue != null) {
Expand Down
54 changes: 42 additions & 12 deletions src/main/java/net/snowflake/client/core/SessionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,21 @@ private static SFLoginOutput newSession(
}
} else if (authenticatorType == ClientAuthnDTO.AuthenticatorType.OKTA) {
// okta authenticator v1
tokenOrSamlResponse = getSamlResponseUsingOkta(loginInput);
while (true) {
try {
tokenOrSamlResponse = getSamlResponseUsingOkta(loginInput);
} catch (SnowflakeSQLException ex) {
// This error gets thrown if the okta request encountered a retry-able error that
// requires getting a new one-time token.
if (ex.getErrorCode() == ErrorCode.AUTHENTICATOR_REQUEST_TIMEOUT.getMessageCode()) {
logger.debug("Failed to get Okta SAML response. Retrying.");
continue;
} else {
throw ex;
}
}
break;
}
} else if (authenticatorType == ClientAuthnDTO.AuthenticatorType.SNOWFLAKE_JWT) {
SessionUtilKeyPair s =
new SessionUtilKeyPair(
Expand Down Expand Up @@ -651,16 +665,31 @@ private static SFLoginOutput newSession(
loginInput.getHttpClientSettingsKey());
} catch (SnowflakeSQLException ex) {
if (ex.getErrorCode() == ErrorCode.AUTHENTICATOR_REQUEST_TIMEOUT.getMessageCode()) {
if (authenticatorType == ClientAuthnDTO.AuthenticatorType.SNOWFLAKE_JWT) {
SessionUtilKeyPair s =
new SessionUtilKeyPair(
loginInput.getPrivateKey(),
loginInput.getPrivateKeyFile(),
loginInput.getPrivateKeyFilePwd(),
loginInput.getAccountName(),
loginInput.getUserName());

data.put(ClientAuthnParameter.TOKEN.name(), s.issueJwtToken());
if (authenticatorType == ClientAuthnDTO.AuthenticatorType.SNOWFLAKE_JWT
|| authenticatorType == ClientAuthnDTO.AuthenticatorType.OKTA) {

if (authenticatorType == ClientAuthnDTO.AuthenticatorType.SNOWFLAKE_JWT) {
SessionUtilKeyPair s =
new SessionUtilKeyPair(
loginInput.getPrivateKey(),
loginInput.getPrivateKeyFile(),
loginInput.getPrivateKeyFilePwd(),
loginInput.getAccountName(),
loginInput.getUserName());

data.put(ClientAuthnParameter.TOKEN.name(), s.issueJwtToken());
} else if (authenticatorType == ClientAuthnDTO.AuthenticatorType.OKTA) {
logger.debug("Retrieve new token for Okta authentication.");
// If we need to retry, we need to get a new Okta token
tokenOrSamlResponse = getSamlResponseUsingOkta(loginInput);
sfc-gh-dprzybysz marked this conversation as resolved.
Show resolved Hide resolved
data.put(ClientAuthnParameter.RAW_SAML_RESPONSE.name(), tokenOrSamlResponse);
authnData.setData(data);
String updatedJson = mapper.writeValueAsString(authnData);

StringEntity updatedInput = new StringEntity(updatedJson, StandardCharsets.UTF_8);
updatedInput.setContentType("application/json");
postRequest.setEntity(updatedInput);
}

long elapsedSeconds = ex.getElapsedSeconds();

Expand Down Expand Up @@ -690,7 +719,8 @@ private static SFLoginOutput newSession(
}
}

// JWT renew should not count as a retry, so we pass back the current retry count.
// JWT or Okta renew should not count as a retry, so we pass back the current retry
// count.
retryCount = ex.getRetryCount();

continue;
Expand Down
77 changes: 0 additions & 77 deletions src/main/java/net/snowflake/client/core/SfSqlArray.java

This file was deleted.

Loading
Loading