Search in sources :

Example 1 with ChallengeRequest

use of com.okta.idx.sdk.api.request.ChallengeRequest in project okta-idx-java by okta.

the class IDXAuthenticationWrapper method selectPasswordAuthenticatorIfNeeded.

// If app sign-on policy is set to "any 1 factor", the next remediation after identify is
// select-authenticator-authenticate
// Check if that's the case, and proceed to select password authenticator
private AuthenticationTransaction selectPasswordAuthenticatorIfNeeded(AuthenticationTransaction authenticationTransaction) throws ProcessingException {
    // If remediation contains challenge-authenticator for passcode, we don't need to check SELECT_AUTHENTICATOR_AUTHENTICATE
    Optional<RemediationOption> challengeRemediationOptionOptional = authenticationTransaction.getOptionalRemediationOption(RemediationType.CHALLENGE_AUTHENTICATOR);
    if (challengeRemediationOptionOptional.isPresent()) {
        // proceed with password challenge
        return authenticationTransaction;
    }
    Optional<RemediationOption> remediationOptionOptional = authenticationTransaction.getOptionalRemediationOption(RemediationType.SELECT_AUTHENTICATOR_AUTHENTICATE);
    if (!remediationOptionOptional.isPresent()) {
        // We don't need to.
        return authenticationTransaction;
    }
    Map<String, String> authenticatorOptions = remediationOptionOptional.get().getAuthenticatorOptions();
    Authenticator authenticator = new Authenticator();
    authenticator.setId(authenticatorOptions.get("password"));
    ChallengeRequest selectAuthenticatorRequest = ChallengeRequestBuilder.builder().withStateHandle(authenticationTransaction.getStateHandle()).withAuthenticator(authenticator).build();
    return authenticationTransaction.proceed(() -> remediationOptionOptional.get().proceed(client, selectAuthenticatorRequest));
}
Also used : RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) Authenticator(com.okta.idx.sdk.api.model.Authenticator) AnswerChallengeRequest(com.okta.idx.sdk.api.request.AnswerChallengeRequest) ChallengeRequest(com.okta.idx.sdk.api.request.ChallengeRequest)

Example 2 with ChallengeRequest

use of com.okta.idx.sdk.api.request.ChallengeRequest in project okta-idx-java by okta.

the class BaseIDXClient method challenge.

@Override
public IDXResponse challenge(ChallengeRequest challengeRequest, String href) throws ProcessingException {
    IDXResponse idxResponse;
    try {
        Request request = new DefaultRequest(HttpMethod.POST, href, null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(challengeRequest)), -1L);
        Response response = requestExecutor.executeRequest(request);
        if (response.getHttpStatus() != 200) {
            handleErrorResponse(request, response);
        }
        JsonNode responseJsonNode = objectMapper.readTree(response.getBody());
        idxResponse = objectMapper.convertValue(responseJsonNode, IDXResponse.class);
    } catch (IOException | HttpException e) {
        throw new ProcessingException(e);
    }
    return idxResponse;
}
Also used : ErrorResponse(com.okta.idx.sdk.api.response.ErrorResponse) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) InteractResponse(com.okta.idx.sdk.api.response.InteractResponse) Response(com.okta.commons.http.Response) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) DefaultRequest(com.okta.commons.http.DefaultRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SkipAuthenticatorEnrollmentRequest(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest) Request(com.okta.commons.http.Request) IdentifyRequest(com.okta.idx.sdk.api.request.IdentifyRequest) EnrollUserProfileUpdateRequest(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest) DefaultRequest(com.okta.commons.http.DefaultRequest) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) ChallengeRequest(com.okta.idx.sdk.api.request.ChallengeRequest) CancelRequest(com.okta.idx.sdk.api.request.CancelRequest) RecoverRequest(com.okta.idx.sdk.api.request.RecoverRequest) IntrospectRequest(com.okta.idx.sdk.api.request.IntrospectRequest) AnswerChallengeRequest(com.okta.idx.sdk.api.request.AnswerChallengeRequest) PollRequest(com.okta.idx.sdk.api.request.PollRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) HttpException(com.okta.commons.http.HttpException) IOException(java.io.IOException) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException)

Aggregations

AnswerChallengeRequest (com.okta.idx.sdk.api.request.AnswerChallengeRequest)2 ChallengeRequest (com.okta.idx.sdk.api.request.ChallengeRequest)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 ProcessingException (com.okta.idx.sdk.api.exception.ProcessingException)1 Authenticator (com.okta.idx.sdk.api.model.Authenticator)1 RemediationOption (com.okta.idx.sdk.api.model.RemediationOption)1 CancelRequest (com.okta.idx.sdk.api.request.CancelRequest)1 EnrollRequest (com.okta.idx.sdk.api.request.EnrollRequest)1 EnrollUserProfileUpdateRequest (com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest)1 IdentifyRequest (com.okta.idx.sdk.api.request.IdentifyRequest)1 IntrospectRequest (com.okta.idx.sdk.api.request.IntrospectRequest)1 PollRequest (com.okta.idx.sdk.api.request.PollRequest)1 RecoverRequest (com.okta.idx.sdk.api.request.RecoverRequest)1 SkipAuthenticatorEnrollmentRequest (com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest)1 ErrorResponse (com.okta.idx.sdk.api.response.ErrorResponse)1 IDXResponse (com.okta.idx.sdk.api.response.IDXResponse)1