Skip to content

Commit

Permalink
SNOW-1647589: Fix NullPointerException when MFA is enabled in Okta
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-wfateem committed Sep 4, 2024
1 parent 21c1e32 commit 22de3f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit 22de3f1

Please sign in to comment.