Search in sources :

Example 1 with VerifyAuthenticatorOptions

use of com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions in project okta-idx-java by okta.

the class LoginController method verify.

/**
 * Handle authenticator verification functionality.
 *
 * @param code                  the verification code
 * @param securityQuestionKey   the security question key
 * @param session               the session
 * @return the view associated with authentication response.
 */
@PostMapping("/verify")
public ModelAndView verify(@RequestParam("code") final String code, @RequestParam(value = "security_question_key", required = false) final String securityQuestionKey, final HttpSession session) {
    logger.info(":: Verify Code :: {}", code);
    ProceedContext proceedContext = Util.getProceedContextFromSession(session);
    AuthenticationResponse authenticationResponse;
    if (!Strings.isEmpty(securityQuestionKey)) {
        authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, new VerifyAuthenticatorAnswer(code, securityQuestionKey));
    } else if ("totp".equals(String.valueOf(session.getAttribute("totp")))) {
        authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, new VerifyChannelDataOptions("totp", code));
    } else {
        VerifyAuthenticatorOptions verifyAuthenticatorOptions = new VerifyAuthenticatorOptions(code);
        authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, verifyAuthenticatorOptions);
    }
    if (responseHandler.needsToShowErrors(authenticationResponse)) {
        ModelAndView modelAndView = new ModelAndView("verify");
        modelAndView.addObject("errors", authenticationResponse.getErrors());
        return modelAndView;
    }
    return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
Also used : VerifyAuthenticatorAnswer(com.okta.idx.sdk.api.model.VerifyAuthenticatorAnswer) VerifyAuthenticatorOptions(com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions) VerifyChannelDataOptions(com.okta.idx.sdk.api.model.VerifyChannelDataOptions) ModelAndView(org.springframework.web.servlet.ModelAndView) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) ProceedContext(com.okta.idx.sdk.api.client.ProceedContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with VerifyAuthenticatorOptions

use of com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions in project okta-idx-java by okta.

the class LoginController method registerPassword.

/**
 * Handle change password functionality.
 *
 * @param newPassword the new password
 * @param confirmNewPassword the confirmation of the new password
 * @param session the session
 * @return the view associated with authentication response.
 */
@PostMapping("/register-password")
public ModelAndView registerPassword(@RequestParam("new-password") final String newPassword, @RequestParam("confirm-new-password") final String confirmNewPassword, final HttpSession session) {
    logger.info(":: Change Password ::");
    if (!newPassword.equals(confirmNewPassword)) {
        ModelAndView mav = new ModelAndView("register-password");
        mav.addObject("errors", "Passwords do not match");
        return mav;
    }
    ProceedContext proceedContext = Util.getProceedContextFromSession(session);
    VerifyAuthenticatorOptions verifyAuthenticatorOptions = new VerifyAuthenticatorOptions(newPassword);
    AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, verifyAuthenticatorOptions);
    if (responseHandler.needsToShowErrors(authenticationResponse)) {
        ModelAndView modelAndView = new ModelAndView("register-password");
        modelAndView.addObject("errors", authenticationResponse.getErrors());
        return modelAndView;
    }
    return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
Also used : VerifyAuthenticatorOptions(com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions) ModelAndView(org.springframework.web.servlet.ModelAndView) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) ProceedContext(com.okta.idx.sdk.api.client.ProceedContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with VerifyAuthenticatorOptions

use of com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions in project okta-idx-java by okta.

the class HomeController method displayIndexOrHomePage.

/**
 * Display one of:
 * <p>
 * a) index page - if the user is not authenticated yet (does not have token response in session).
 * b) home page - if the user is authenticated (or) we have obtained a token for the user from the interaction code or otp in callback.
 * c) info page - if the user is unauthenticated yet and has received an otp in callback. the info page will ask the user to input
 *                otp in the original browser to continue with the flow.
 * d) error page - if the received state does not correlate with the state in client context or if the callback
 *                 contains error parameters.
 * <p>
 * where index page refers to the root view with table of contents,
 * and home page refers to the view that shows the user profile information along with token information.
 *
 * @param interactionCode the interaction code from callback (optional)
 * @param state the state value from callback (optional)
 * @param otp the one time password or verification code (optional)
 * @param error the error from callback when interaction_code could not be sent (optional)
 * @param errDesc the error_description from callback (optional)
 * @param session the http session
 * @return the index page view with table of contents or the home page view if we have a token or the info page.
 */
@RequestMapping(value = { "/", "**/callback" }, method = RequestMethod.GET)
public ModelAndView displayIndexOrHomePage(@RequestParam(name = "interaction_code", required = false) final String interactionCode, @RequestParam(name = "state", required = false) final String state, @RequestParam(name = "otp", required = false) final String otp, @RequestParam(name = "error", required = false) final String error, @RequestParam(name = "error_description", required = false) final String errDesc, final HttpSession session) {
    ProceedContext proceedContext = Util.getProceedContextFromSession(session);
    TokenResponse tokenResponse = (TokenResponse) session.getAttribute("tokenResponse");
    // render home page if token is already present in session
    if (tokenResponse != null) {
        return homeHelper.proceedToHome(tokenResponse, session);
    }
    // correlate received state with the client context
    if ((Strings.hasText(interactionCode) || Strings.hasText(otp)) && proceedContext != null && (Strings.isEmpty(state) || !state.equals(proceedContext.getClientContext().getState()))) {
        ModelAndView mav = new ModelAndView("error");
        mav.addObject("errors", "Could not correlate client context with the received state value " + state + " in callback");
        return mav;
    }
    AuthenticationResponse authenticationResponse;
    // if interaction code is present, exchange it for a token
    if (Strings.hasText(interactionCode)) {
        authenticationResponse = authenticationWrapper.fetchTokenWithInteractionCode(proceedContext, interactionCode);
        return responseHandler.handleKnownTransitions(authenticationResponse, session);
    }
    // if otp is present, proceed with introspect to finish the flow
    if (Strings.hasText(otp)) {
        if (proceedContext == null) {
            // different browser case
            ModelAndView mav = new ModelAndView("info");
            mav.addObject("message", "Please enter OTP " + otp + " in the original browser tab to finish the flow.");
            return mav;
        }
        VerifyAuthenticatorOptions verifyAuthenticatorOptions = new VerifyAuthenticatorOptions(otp);
        authenticationResponse = authenticationWrapper.verifyAuthenticator(proceedContext, verifyAuthenticatorOptions);
        return responseHandler.handleKnownTransitions(authenticationResponse, session);
    }
    // if error params are present, show error page
    if (Strings.hasText(error) || Strings.hasText(errDesc)) {
        ModelAndView mav = new ModelAndView("error");
        mav.addObject("errors", error + ":" + errDesc);
        return mav;
    }
    // return the root view
    return new ModelAndView("index");
}
Also used : VerifyAuthenticatorOptions(com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) ModelAndView(org.springframework.web.servlet.ModelAndView) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) ProceedContext(com.okta.idx.sdk.api.client.ProceedContext) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ProceedContext (com.okta.idx.sdk.api.client.ProceedContext)3 VerifyAuthenticatorOptions (com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions)3 AuthenticationResponse (com.okta.idx.sdk.api.response.AuthenticationResponse)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 VerifyAuthenticatorAnswer (com.okta.idx.sdk.api.model.VerifyAuthenticatorAnswer)1 VerifyChannelDataOptions (com.okta.idx.sdk.api.model.VerifyChannelDataOptions)1 TokenResponse (com.okta.idx.sdk.api.response.TokenResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1