Search in sources :

Example 6 with IDXResponse

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

the class AuthenticationTransaction method introspect.

static AuthenticationTransaction introspect(IDXClient client, IDXClientContext clientContext) throws ProcessingException {
    IDXResponse introspectResponse = client.introspect(clientContext);
    WrapperUtil.printRemediationOptions(introspectResponse);
    return new AuthenticationTransaction(client, clientContext, introspectResponse);
}
Also used : IDXResponse(com.okta.idx.sdk.api.response.IDXResponse)

Example 7 with IDXResponse

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

the class IDXAuthenticationWrapper method recoverPassword.

/**
 * Recover Password with the supplied username.
 *
 * @param username the username
 * @return the Authentication response
 */
public AuthenticationResponse recoverPassword(String username, ProceedContext proceedContext) {
    try {
        boolean isIdentifyInOneStep = proceedContext.isIdentifyInOneStep();
        if (isIdentifyInOneStep) {
            // recover
            AuthenticationTransaction recoverTransaction = AuthenticationTransaction.proceed(client, proceedContext, () -> {
                RecoverRequest recoverRequest = RecoverRequestBuilder.builder().withStateHandle(proceedContext.getStateHandle()).build();
                return client.recover(recoverRequest, null);
            });
            RemediationOption remediationOption = recoverTransaction.getRemediationOption(RemediationType.IDENTIFY_RECOVERY);
            IdentifyRequest identifyRequest = IdentifyRequestBuilder.builder().withIdentifier(username).withStateHandle(proceedContext.getStateHandle()).build();
            // identify user
            return recoverTransaction.proceed(() -> remediationOption.proceed(client, identifyRequest)).asAuthenticationResponse(AuthenticationStatus.AWAITING_AUTHENTICATOR_SELECTION);
        } else {
            // identify user
            AuthenticationTransaction identifyTransaction = AuthenticationTransaction.proceed(client, proceedContext, () -> {
                IdentifyRequest identifyRequest = IdentifyRequestBuilder.builder().withIdentifier(username).withStateHandle(proceedContext.getStateHandle()).build();
                return client.identify(identifyRequest, proceedContext.getHref());
            });
            IDXResponse identifyResponse = identifyTransaction.getResponse();
            if (identifyResponse.getMessages() != null) {
                return identifyTransaction.asAuthenticationResponse(AuthenticationStatus.AWAITING_USER_EMAIL_ACTIVATION);
            }
            // Check if instead of password, user is being prompted for list of authenticators to select
            if (identifyResponse.getCurrentAuthenticatorEnrollment() == null) {
                identifyTransaction = selectPasswordAuthenticatorIfNeeded(identifyTransaction);
            }
            Recover recover = identifyTransaction.getResponse().getCurrentAuthenticatorEnrollment().getValue().getRecover();
            AuthenticationTransaction recoverTransaction = identifyTransaction.proceed(() -> {
                // recover password
                RecoverRequest recoverRequest = RecoverRequestBuilder.builder().withStateHandle(proceedContext.getStateHandle()).build();
                return recover.proceed(client, recoverRequest);
            });
            return recoverTransaction.asAuthenticationResponse(AuthenticationStatus.AWAITING_AUTHENTICATOR_SELECTION);
        }
    } catch (ProcessingException e) {
        return handleProcessingException(e);
    } catch (IllegalArgumentException e) {
        return handleIllegalArgumentException(e);
    }
}
Also used : IdentifyRequest(com.okta.idx.sdk.api.request.IdentifyRequest) RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) RecoverRequest(com.okta.idx.sdk.api.request.RecoverRequest) Recover(com.okta.idx.sdk.api.model.Recover) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) WrapperUtil.handleIllegalArgumentException(com.okta.idx.sdk.api.client.WrapperUtil.handleIllegalArgumentException) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException) WrapperUtil.handleProcessingException(com.okta.idx.sdk.api.client.WrapperUtil.handleProcessingException)

Example 8 with IDXResponse

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

the class BaseIDXClient method enrollUpdateUserProfile.

@Override
public IDXResponse enrollUpdateUserProfile(EnrollUserProfileUpdateRequest enrollUserProfileUpdateRequest, String href) throws ProcessingException {
    IDXResponse idxResponse;
    try {
        Request request = new DefaultRequest(HttpMethod.POST, href, null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(enrollUserProfileUpdateRequest)), -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)

Example 9 with IDXResponse

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

the class BaseIDXClient method skip.

@Override
public IDXResponse skip(SkipAuthenticatorEnrollmentRequest skipAuthenticatorEnrollmentRequest, String href) throws ProcessingException {
    IDXResponse idxResponse;
    try {
        Request request = new DefaultRequest(HttpMethod.POST, href, null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(skipAuthenticatorEnrollmentRequest)), -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)

Example 10 with IDXResponse

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

the class BaseIDXClient method recover.

@Override
public IDXResponse recover(RecoverRequest recoverRequest, String href) throws ProcessingException {
    IDXResponse idxResponse;
    try {
        Request request = new DefaultRequest(HttpMethod.POST, Strings.hasText(href) ? href : clientConfiguration.getBaseUrl() + "/idp/idx/recover", null, getHttpHeaders(false), new ByteArrayInputStream(objectMapper.writeValueAsBytes(recoverRequest)), -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

IDXResponse (com.okta.idx.sdk.api.response.IDXResponse)16 ProcessingException (com.okta.idx.sdk.api.exception.ProcessingException)12 Response (com.okta.commons.http.Response)11 IdentifyRequest (com.okta.idx.sdk.api.request.IdentifyRequest)11 RecoverRequest (com.okta.idx.sdk.api.request.RecoverRequest)11 TokenResponse (com.okta.idx.sdk.api.response.TokenResponse)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 DefaultRequest (com.okta.commons.http.DefaultRequest)10 HttpException (com.okta.commons.http.HttpException)10 Request (com.okta.commons.http.Request)10 AnswerChallengeRequest (com.okta.idx.sdk.api.request.AnswerChallengeRequest)10 CancelRequest (com.okta.idx.sdk.api.request.CancelRequest)10 ChallengeRequest (com.okta.idx.sdk.api.request.ChallengeRequest)10 EnrollRequest (com.okta.idx.sdk.api.request.EnrollRequest)10 EnrollUserProfileUpdateRequest (com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest)10 IntrospectRequest (com.okta.idx.sdk.api.request.IntrospectRequest)10 PollRequest (com.okta.idx.sdk.api.request.PollRequest)10 SkipAuthenticatorEnrollmentRequest (com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest)10 ErrorResponse (com.okta.idx.sdk.api.response.ErrorResponse)10 InteractResponse (com.okta.idx.sdk.api.response.InteractResponse)10