Search in sources :

Example 1 with ContextualData

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);
    }
}
Also used : ContextualData(com.okta.idx.sdk.api.model.ContextualData) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) Authenticator(com.okta.idx.sdk.api.client.Authenticator) ProceedContext(com.okta.idx.sdk.api.client.ProceedContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

Authenticator (com.okta.idx.sdk.api.client.Authenticator)1 ProceedContext (com.okta.idx.sdk.api.client.ProceedContext)1 ContextualData (com.okta.idx.sdk.api.model.ContextualData)1 AuthenticationResponse (com.okta.idx.sdk.api.response.AuthenticationResponse)1 List (java.util.List)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1