Search in sources :

Example 1 with CurrentAuthenticatorEnrollment

use of com.okta.idx.sdk.api.model.CurrentAuthenticatorEnrollment 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

CurrentAuthenticatorEnrollment (com.okta.idx.sdk.api.model.CurrentAuthenticatorEnrollment)1 AuthenticationResponse (com.okta.idx.sdk.api.response.AuthenticationResponse)1 TokenResponse (com.okta.idx.sdk.api.response.TokenResponse)1