Skip to content

Commit 22de3f1

Browse files
SNOW-1647589: Fix NullPointerException when MFA is enabled in Okta
1 parent 21c1e32 commit 22de3f1

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/main/java/net/snowflake/client/core/SessionUtil.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,7 @@ private static String federatedFlowStep3(SFLoginInput loginInput, String tokenUr
12661266
throws SnowflakeSQLException {
12671267

12681268
String oneTimeToken = "";
1269+
boolean isMfaEnabledInOkta;
12691270
try {
12701271
URL url = new URL(tokenUrl);
12711272
URI tokenUri = url.toURI();
@@ -1302,17 +1303,32 @@ private static String federatedFlowStep3(SFLoginInput loginInput, String tokenUr
13021303
null,
13031304
loginInput.getHttpClientSettingsKey());
13041305

1305-
logger.debug("User is authenticated against {}.", loginInput.getAuthenticator());
1306-
13071306
// session token is in the data field of the returned json response
13081307
final JsonNode jsonNode = mapper.readTree(idpResponse);
1308+
isMfaEnabledInOkta = jsonNode.get("status").asText().equals("MFA_REQUIRED");
1309+
if (isMfaEnabledInOkta) {
1310+
SnowflakeSQLException ex =
1311+
new SnowflakeSQLLoggedException(
1312+
null,
1313+
ErrorCode.OKTA_MFA_NOT_SUPPORTED.getMessageCode(),
1314+
SqlState.FEATURE_NOT_SUPPORTED,
1315+
"MFA enabled in Okta is not supported with this authenticator type. "
1316+
+ "Please use 'externalbrowser' instead or a different authentication method.");
1317+
1318+
logger.error(
1319+
"MFA enabled in Okta is not supported with this authenticator type. "
1320+
+ "Please use 'externalbrowser' instead or a different authentication method.",
1321+
ex);
1322+
throw ex;
1323+
}
13091324
oneTimeToken =
13101325
jsonNode.get("sessionToken") != null
13111326
? jsonNode.get("sessionToken").asText()
13121327
: jsonNode.get("cookieToken").asText();
13131328
} catch (IOException | URISyntaxException ex) {
13141329
handleFederatedFlowError(loginInput, ex);
13151330
}
1331+
logger.debug("User is authenticated against {}.", loginInput.getAuthenticator());
13161332
return oneTimeToken;
13171333
}
13181334

src/main/java/net/snowflake/client/jdbc/ErrorCode.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public enum ErrorCode {
8383
INVALID_OKTA_USERNAME(200060, SqlState.CONNECTION_EXCEPTION),
8484
GCP_SERVICE_ERROR(200061, SqlState.SYSTEM_ERROR),
8585
AUTHENTICATOR_REQUEST_TIMEOUT(200062, SqlState.CONNECTION_EXCEPTION),
86-
INVALID_STRUCT_DATA(200063, SqlState.DATA_EXCEPTION);
86+
INVALID_STRUCT_DATA(200063, SqlState.DATA_EXCEPTION),
87+
OKTA_MFA_NOT_SUPPORTED(200064, SqlState.FEATURE_NOT_SUPPORTED);
8788

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

0 commit comments

Comments
 (0)