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-1647589: Fix NullPointerException when MFA is enabled in Okta and native Okta authentication is used #1887

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 18 additions & 2 deletions src/main/java/net/snowflake/client/core/SessionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,7 @@ private static String federatedFlowStep3(SFLoginInput loginInput, String tokenUr
throws SnowflakeSQLException {

String oneTimeToken = "";
boolean isMfaEnabledInOkta;
try {
URL url = new URL(tokenUrl);
URI tokenUri = url.toURI();
Expand Down Expand Up @@ -1302,17 +1303,32 @@ private static String federatedFlowStep3(SFLoginInput loginInput, String tokenUr
null,
loginInput.getHttpClientSettingsKey());

logger.debug("User is authenticated against {}.", loginInput.getAuthenticator());

// session token is in the data field of the returned json response
final JsonNode jsonNode = mapper.readTree(idpResponse);
isMfaEnabledInOkta = jsonNode.get("status").asText().equals("MFA_REQUIRED");
if (isMfaEnabledInOkta) {
SnowflakeSQLException ex =
new SnowflakeSQLLoggedException(
null,
ErrorCode.OKTA_MFA_NOT_SUPPORTED.getMessageCode(),
SqlState.FEATURE_NOT_SUPPORTED,
"MFA enabled in Okta is not supported with this authenticator type. "
+ "Please use 'externalbrowser' instead or a different authentication method.");

logger.error(
"MFA enabled in Okta is not supported with this authenticator type. "
+ "Please use 'externalbrowser' instead or a different authentication method.",
ex);
throw ex;
}
oneTimeToken =
jsonNode.get("sessionToken") != null
? jsonNode.get("sessionToken").asText()
: jsonNode.get("cookieToken").asText();
} catch (IOException | URISyntaxException ex) {
handleFederatedFlowError(loginInput, ex);
}
logger.debug("User is authenticated against {}.", loginInput.getAuthenticator());
return oneTimeToken;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/snowflake/client/jdbc/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public enum ErrorCode {
INVALID_OKTA_USERNAME(200060, SqlState.CONNECTION_EXCEPTION),
GCP_SERVICE_ERROR(200061, SqlState.SYSTEM_ERROR),
AUTHENTICATOR_REQUEST_TIMEOUT(200062, SqlState.CONNECTION_EXCEPTION),
INVALID_STRUCT_DATA(200063, SqlState.DATA_EXCEPTION);
INVALID_STRUCT_DATA(200063, SqlState.DATA_EXCEPTION),
OKTA_MFA_NOT_SUPPORTED(200064, SqlState.FEATURE_NOT_SUPPORTED);

public static final String errorMessageResource = "net.snowflake.client.jdbc.jdbc_error_messages";

Expand Down
Loading