Search in sources :

Example 6 with TokenResponse

use of com.okta.idx.sdk.api.response.TokenResponse in project okta-idx-java by okta.

the class HomeController method displayLoginPage.

/**
 * Display the login page.
 *
 * @param session the http session
 * @return the login view
 */
@GetMapping(value = "/login")
public ModelAndView displayLoginPage(final HttpSession session) {
    TokenResponse tokenResponse = (TokenResponse) session.getAttribute("tokenResponse");
    // render token response if a successful one is already present in session
    if (tokenResponse != null) {
        return homeHelper.proceedToHome(tokenResponse, session);
    }
    AuthenticationResponse authenticationResponse = begin(session);
    if (authenticationResponse.getErrors().size() > 0) {
        ModelAndView modelAndView = new ModelAndView("error");
        modelAndView.addObject("errors", authenticationResponse.getErrors());
        return modelAndView;
    }
    ModelAndView modelAndView = new ModelAndView("login");
    if (!CollectionUtils.isEmpty(authenticationResponse.getIdps())) {
        modelAndView.addObject("idps", authenticationResponse.getIdps());
    }
    return modelAndView;
}
Also used : TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) ModelAndView(org.springframework.web.servlet.ModelAndView) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 7 with TokenResponse

use of com.okta.idx.sdk.api.response.TokenResponse in project okta-idx-java by okta.

the class AuthenticationTransaction method asAuthenticationResponse.

AuthenticationResponse asAuthenticationResponse(AuthenticationStatus defaultStatus) throws ProcessingException {
    AuthenticationResponse authenticationResponse = new AuthenticationResponse();
    authenticationResponse.setProceedContext(createProceedContext());
    copyErrorMessages(idxResponse, authenticationResponse);
    fillOutIdps(authenticationResponse);
    fillOutAuthenticators(authenticationResponse);
    if (idxResponse == null) {
        return authenticationResponse;
    }
    if (idxResponse.isLoginSuccessful()) {
        // login successful
        logger.info("Login Successful!");
        TokenResponse tokenResponse = idxResponse.getSuccessWithInteractionCode().exchangeCode(client, clientContext);
        authenticationResponse.setAuthenticationStatus(AuthenticationStatus.SUCCESS);
        authenticationResponse.setTokenResponse(tokenResponse);
        return authenticationResponse;
    }
    if (idxResponse.getCurrentAuthenticator() != null) {
        authenticationResponse.getWebAuthnParams().setCurrentAuthenticator(idxResponse.getCurrentAuthenticator());
    }
    if (idxResponse.getCurrentAuthenticatorEnrollment() != null) {
        authenticationResponse.setCurrentAuthenticatorEnrollment(idxResponse.getCurrentAuthenticatorEnrollment());
    }
    if (idxResponse.getAuthenticatorEnrollments() != null) {
        authenticationResponse.setAuthenticatorEnrollments(idxResponse.getAuthenticatorEnrollments());
    }
    String firstRemediation = "";
    if (idxResponse.remediation() != null && idxResponse.remediation().remediationOptions().length > 0) {
        firstRemediation = idxResponse.remediation().remediationOptions()[0].getName();
    }
    switch(firstRemediation) {
        case RemediationType.REENROLL_AUTHENTICATOR:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.PASSWORD_EXPIRED);
            break;
        case RemediationType.AUTHENTICATOR_VERIFICATION_DATA:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_AUTHENTICATOR_VERIFICATION_DATA);
            break;
        case RemediationType.AUTHENTICATOR_ENROLLMENT_DATA:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_AUTHENTICATOR_ENROLLMENT_DATA);
            break;
        case RemediationType.CHALLENGE_AUTHENTICATOR:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_AUTHENTICATOR_VERIFICATION);
            break;
        case RemediationType.SELECT_AUTHENTICATOR_AUTHENTICATE:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_AUTHENTICATOR_SELECTION);
            break;
        case RemediationType.SELECT_AUTHENTICATOR_ENROLL:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_AUTHENTICATOR_ENROLLMENT_SELECTION);
            break;
        case RemediationType.ENROLL_PROFILE:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_PROFILE_ENROLLMENT);
            break;
        case RemediationType.ENROLL_AUTHENTICATOR:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_AUTHENTICATOR_ENROLLMENT);
            break;
        case RemediationType.ENROLL_POLL:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_POLL_ENROLLMENT);
            break;
        case RemediationType.ENROLLMENT_CHANNEL_DATA:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_CHANNEL_DATA_ENROLLMENT);
            break;
        case RemediationType.CHALLENGE_POLL:
            authenticationResponse.setAuthenticationStatus(AuthenticationStatus.AWAITING_CHALLENGE_POLL);
            break;
        default:
            authenticationResponse.setAuthenticationStatus(defaultStatus);
            break;
    }
    Optional.ofNullable(idxResponse.getCurrentAuthenticator()).map(CurrentAuthenticatorEnrollment::getValue).map(CurrentAuthenticatorEnrollmentValue::getContextualData).ifPresent(authenticationResponse::setContextualData);
    return authenticationResponse;
}
Also used : CurrentAuthenticatorEnrollment(com.okta.idx.sdk.api.model.CurrentAuthenticatorEnrollment) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse)

Aggregations

TokenResponse (com.okta.idx.sdk.api.response.TokenResponse)7 AuthenticationResponse (com.okta.idx.sdk.api.response.AuthenticationResponse)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 ProceedContext (com.okta.idx.sdk.api.client.ProceedContext)2 ProcessingException (com.okta.idx.sdk.api.exception.ProcessingException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DefaultRequest (com.okta.commons.http.DefaultRequest)1 HttpException (com.okta.commons.http.HttpException)1 Request (com.okta.commons.http.Request)1 Response (com.okta.commons.http.Response)1 Authenticator (com.okta.idx.sdk.api.client.Authenticator)1 WrapperUtil.handleProcessingException (com.okta.idx.sdk.api.client.WrapperUtil.handleProcessingException)1 CurrentAuthenticatorEnrollment (com.okta.idx.sdk.api.model.CurrentAuthenticatorEnrollment)1 VerifyAuthenticatorOptions (com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions)1 AnswerChallengeRequest (com.okta.idx.sdk.api.request.AnswerChallengeRequest)1 CancelRequest (com.okta.idx.sdk.api.request.CancelRequest)1 ChallengeRequest (com.okta.idx.sdk.api.request.ChallengeRequest)1 EnrollRequest (com.okta.idx.sdk.api.request.EnrollRequest)1 EnrollUserProfileUpdateRequest (com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest)1