use of com.okta.idx.sdk.api.model.Qrcode in project okta-idx-java by okta.
the class LoginController method selectAuthenticator.
/**
* Handle authenticator selection during authentication.
*
* @param authenticatorType the authenticatorType
* @param session the session
* @param action the submit or cancel action from form post
* @return select authenticator view or select factor view or error view
*/
@PostMapping(value = "/select-authenticator")
public ModelAndView selectAuthenticator(@RequestParam("authenticator-type") final String authenticatorType, @RequestParam(value = "action") final String action, final HttpSession session) {
AuthenticationResponse authenticationResponse = null;
Authenticator foundAuthenticator = null;
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
if ("skip".equals(action)) {
logger.info("Skipping {} authenticator", authenticatorType);
authenticationResponse = idxAuthenticationWrapper.skipAuthenticatorEnrollment(proceedContext);
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
List<Authenticator> authenticators = (List<Authenticator>) session.getAttribute("authenticators");
if ("webauthn".equals(authenticatorType)) {
ModelAndView modelAndView;
Optional<Authenticator> authenticatorOptional = authenticators.stream().filter(auth -> auth.getType().equals(authenticatorType)).findFirst();
String authId = authenticatorOptional.get().getId();
AuthenticationResponse enrollResponse = idxAuthenticationWrapper.enrollAuthenticator(proceedContext, authId);
Util.updateSession(session, enrollResponse.getProceedContext());
String webauthnCredentialId = enrollResponse.getWebAuthnParams().getWebauthnCredentialId();
if (webauthnCredentialId != null) {
modelAndView = new ModelAndView("select-webauthn-authenticator");
modelAndView.addObject("title", "Select Webauthn Authenticator");
modelAndView.addObject("webauthnCredentialId", webauthnCredentialId);
modelAndView.addObject("challengeData", enrollResponse.getWebAuthnParams().getCurrentAuthenticator().getValue().getContextualData().getChallengeData());
} else {
modelAndView = new ModelAndView("enroll-webauthn-authenticator");
modelAndView.addObject("title", "Enroll Webauthn Authenticator");
modelAndView.addObject("currentAuthenticator", enrollResponse.getWebAuthnParams().getCurrentAuthenticator());
}
return modelAndView;
}
if ("okta_verify".equals(authenticatorType)) {
ModelAndView modelAndView;
Optional<Authenticator> authenticatorOptional = authenticators.stream().filter(auth -> auth.getType().equals(authenticatorType)).findFirst();
Assert.isTrue(authenticatorOptional.isPresent(), "Authenticator not found");
// Looking for QRCODE factor
Optional<Authenticator.Factor> factorOptional = authenticatorOptional.get().getFactors().stream().filter(x -> "QRCODE".equals(x.getLabel())).findFirst();
Assert.isTrue(factorOptional.isPresent(), "Authenticator not found");
authenticationResponse = idxAuthenticationWrapper.selectFactor(proceedContext, factorOptional.get());
Util.setProceedContextForPoll(session, authenticationResponse.getProceedContext());
List<Authenticator.Factor> factors = authenticatorOptional.get().getFactors().stream().filter(x -> !"QRCODE".equals(x.getLabel())).collect(Collectors.toList());
modelAndView = new ModelAndView("setup-okta-verify");
modelAndView.addObject("qrCode", authenticationResponse.getContextualData().getQrcode().getHref());
modelAndView.addObject("channelName", "qrcode");
modelAndView.addObject("factors", factors);
modelAndView.addObject("authenticatorId", authenticatorOptional.get().getId());
modelAndView.addObject("pollTimeout", authenticationResponse.getProceedContext().getRefresh());
return modelAndView;
}
for (Authenticator authenticator : authenticators) {
if (authenticatorType.equals(authenticator.getType())) {
foundAuthenticator = authenticator;
if (foundAuthenticator.getFactors().size() == 1) {
authenticationResponse = idxAuthenticationWrapper.selectAuthenticator(proceedContext, authenticator);
if (authenticationResponse.getContextualData() != null) {
session.setAttribute("totp", authenticationResponse.getContextualData());
} else {
session.removeAttribute("totp");
}
} else {
// user should select the factor in a separate view
ModelAndView modelAndView = new ModelAndView("select-factor");
modelAndView.addObject("title", "Select Factor");
modelAndView.addObject("authenticatorId", foundAuthenticator.getId());
modelAndView.addObject("factors", foundAuthenticator.getFactors());
return modelAndView;
}
}
}
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("select-authenticator");
modelAndView.addObject("errors", authenticationResponse.getErrors());
return modelAndView;
}
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(foundAuthenticator);
case AWAITING_POLL_ENROLLMENT:
return responseHandler.setupOktaVerifyForm(session);
default:
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
}
Aggregations