use of com.okta.idx.sdk.api.model.ContextualData in project okta-idx-java by okta.
the class LoginController method selectFactor.
/**
* Handle factor selection during authentication.
*
* @param authenticatorId the authenticator ID of selected authenticator
* @param mode the sms or voice factor mode
* @param session the session
* @return the view associated with authentication response.
*/
@PostMapping("/select-factor")
public ModelAndView selectFactor(@RequestParam("authenticatorId") final String authenticatorId, @RequestParam("mode") final String mode, final HttpSession session) {
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
List<Authenticator> authenticators = (List<Authenticator>) session.getAttribute("authenticators");
Authenticator foundAuthenticator = null;
for (Authenticator auth : authenticators) {
if (auth.getId().equals(authenticatorId)) {
foundAuthenticator = auth;
}
}
Assert.notNull(foundAuthenticator, "Authenticator not found");
AuthenticationResponse authenticationResponse = null;
Authenticator.Factor foundFactor = null;
for (Authenticator.Factor factor : foundAuthenticator.getFactors()) {
if (factor.getMethod().equals(mode)) {
foundFactor = factor;
authenticationResponse = idxAuthenticationWrapper.selectFactor(proceedContext, foundFactor);
Optional.ofNullable(authenticationResponse.getContextualData()).map(ContextualData::getQrcode).map(Qrcode::getHref).ifPresent(qrCode -> {
session.setAttribute("qrCode", qrCode);
session.setAttribute("channelName", "qrcode");
});
if ("totp".equals(foundFactor.getMethod())) {
session.setAttribute("totp", "totp");
}
break;
}
}
Assert.notNull(foundFactor, "Factor not found");
ModelAndView terminalTransition = responseHandler.handleTerminalTransitions(authenticationResponse, session);
if (terminalTransition != null) {
return terminalTransition;
}
switch(authenticationResponse.getAuthenticationStatus()) {
case AWAITING_AUTHENTICATOR_VERIFICATION_DATA:
return responseHandler.verifyForm();
case AWAITING_AUTHENTICATOR_ENROLLMENT:
case AWAITING_AUTHENTICATOR_ENROLLMENT_DATA:
return responseHandler.registerVerifyForm(foundFactor);
case AWAITING_CHANNEL_DATA_ENROLLMENT:
return responseHandler.oktaVerifyViaChannelDataForm(foundFactor, session);
case AWAITING_POLL_ENROLLMENT:
return responseHandler.setupOktaVerifyForm(session);
case AWAITING_CHALLENGE_POLL:
return responseHandler.oktaVerifyChallenge(authenticationResponse);
default:
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
}
Aggregations