Search in sources :

Example 1 with RemediationOption

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

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

the class AuthenticationTransaction method createProceedContext.

ProceedContext createProceedContext() {
    if (idxResponse == null || idxResponse.remediation() == null || idxResponse.remediation().remediationOptions() == null) {
        logger.error("ProceedContext is null");
        return null;
    }
    RemediationOption[] remediationOptions = idxResponse.remediation().remediationOptions();
    String href = remediationOptions[0].getHref();
    String refresh = remediationOptions[0].getRefresh();
    String skipHref = null;
    Optional<RemediationOption> skipOptional = getOptionalRemediationOption(RemediationType.SKIP);
    if (skipOptional.isPresent()) {
        skipHref = skipOptional.get().getHref();
    }
    boolean isIdentifyInOneStep = isRemediationRequireCredentials(RemediationType.IDENTIFY);
    String selectProfileEnrollHref = null;
    Optional<RemediationOption> selectEnrollProfileRemediationOption = getOptionalRemediationOption(RemediationType.SELECT_ENROLL_PROFILE);
    if (selectEnrollProfileRemediationOption.isPresent()) {
        selectProfileEnrollHref = selectEnrollProfileRemediationOption.get().getHref();
    }
    String resendHref = null;
    PollInfo pollInfo = null;
    if (idxResponse.getCurrentAuthenticatorEnrollment() != null && idxResponse.getCurrentAuthenticatorEnrollment().getValue() != null) {
        if (idxResponse.getCurrentAuthenticatorEnrollment().getValue().getResend() != null) {
            resendHref = idxResponse.getCurrentAuthenticatorEnrollment().getValue().getResend().getHref();
        }
        if (idxResponse.getCurrentAuthenticatorEnrollment().getValue().getPoll() != null) {
            RemediationOption pollRemediationOption = idxResponse.getCurrentAuthenticatorEnrollment().getValue().getPoll();
            pollInfo = new PollInfo(pollRemediationOption.getHref(), pollRemediationOption.getRefresh());
        }
    } else if (idxResponse.getCurrentAuthenticator() != null && idxResponse.getCurrentAuthenticator().getValue() != null) {
        if (idxResponse.getCurrentAuthenticator().getValue().getResend() != null) {
            resendHref = idxResponse.getCurrentAuthenticator().getValue().getResend().getHref();
        }
        if (idxResponse.getCurrentAuthenticator().getValue().getPoll() != null) {
            RemediationOption pollRemediationOption = idxResponse.getCurrentAuthenticator().getValue().getPoll();
            pollInfo = new PollInfo(pollRemediationOption.getHref(), pollRemediationOption.getRefresh());
        }
    }
    return new ProceedContext(clientContext, getStateHandle(), href, skipHref, isIdentifyInOneStep, selectProfileEnrollHref, resendHref, pollInfo, refresh);
}
Also used : RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) PollInfo(com.okta.idx.sdk.api.model.PollInfo)

Example 3 with RemediationOption

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

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

the class IDXAuthenticationWrapper method fetchSignUpFormValues.

/**
 * Populate UI form values for signing up a new user.
 *
 * @param proceedContext the proceedContext
 * @return the authentication response
 */
public AuthenticationResponse fetchSignUpFormValues(ProceedContext proceedContext) {
    AuthenticationResponse newUserRegistrationResponse = new AuthenticationResponse();
    try {
        Assert.notNull(proceedContext.getSelectProfileEnrollHref(), "Org policy is not configured to register new users.");
        // enroll new user
        AuthenticationTransaction enrollTransaction = AuthenticationTransaction.proceed(client, proceedContext, () -> {
            EnrollRequest enrollRequest = EnrollRequestBuilder.builder().withStateHandle(proceedContext.getStateHandle()).build();
            return client.enroll(enrollRequest, proceedContext.getSelectProfileEnrollHref());
        });
        RemediationOption enrollProfileRemediationOption = enrollTransaction.getRemediationOption(RemediationType.ENROLL_PROFILE);
        List<FormValue> enrollProfileFormValues = Arrays.stream(enrollProfileRemediationOption.form()).filter(x -> "userProfile".equals(x.getName())).collect(Collectors.toList());
        newUserRegistrationResponse.setFormValues(enrollProfileFormValues);
        newUserRegistrationResponse.setProceedContext(enrollTransaction.createProceedContext());
        return newUserRegistrationResponse;
    } catch (ProcessingException e) {
        return handleProcessingException(e);
    } catch (IllegalArgumentException e) {
        return handleIllegalArgumentException(e);
    }
}
Also used : DeviceContext(com.okta.idx.sdk.api.model.DeviceContext) Arrays(java.util.Arrays) ChallengeRequestBuilder(com.okta.idx.sdk.api.request.ChallengeRequestBuilder) SkipAuthenticatorEnrollmentRequest(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) LoggerFactory(org.slf4j.LoggerFactory) IdentifyRequest(com.okta.idx.sdk.api.request.IdentifyRequest) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException) SkipAuthenticatorEnrollmentRequestBuilder(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequestBuilder) ErrorResponse(com.okta.idx.sdk.api.response.ErrorResponse) Recover(com.okta.idx.sdk.api.model.Recover) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) Map(java.util.Map) ClientUtil(com.okta.idx.sdk.api.util.ClientUtil) EnrollUserProfileUpdateRequestBuilder(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequestBuilder) Assert(com.okta.commons.lang.Assert) RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) Set(java.util.Set) AuthenticationStatus(com.okta.idx.sdk.api.model.AuthenticationStatus) Response(com.okta.commons.http.Response) WrapperUtil.handleProcessingException(com.okta.idx.sdk.api.client.WrapperUtil.handleProcessingException) EnrollRequestBuilder(com.okta.idx.sdk.api.request.EnrollRequestBuilder) Collectors(java.util.stream.Collectors) WebAuthnRequest(com.okta.idx.sdk.api.request.WebAuthnRequest) List(java.util.List) Optional(java.util.Optional) AuthenticatorEnrollment(com.okta.idx.sdk.api.model.AuthenticatorEnrollment) AnswerChallengeRequest(com.okta.idx.sdk.api.request.AnswerChallengeRequest) EnrollUserProfileUpdateRequest(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest) UserProfile(com.okta.idx.sdk.api.model.UserProfile) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) TokenType(com.okta.idx.sdk.api.model.TokenType) VerifyChannelDataOptions(com.okta.idx.sdk.api.model.VerifyChannelDataOptions) ChallengeRequest(com.okta.idx.sdk.api.request.ChallengeRequest) Authenticator(com.okta.idx.sdk.api.model.Authenticator) IdentifyRequestBuilder(com.okta.idx.sdk.api.request.IdentifyRequestBuilder) VerifyAuthenticatorOptions(com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions) AnswerChallengeRequestBuilder(com.okta.idx.sdk.api.request.AnswerChallengeRequestBuilder) RecoverRequest(com.okta.idx.sdk.api.request.RecoverRequest) VerifyAuthenticatorAnswer(com.okta.idx.sdk.api.model.VerifyAuthenticatorAnswer) Logger(org.slf4j.Logger) PollRequestBuilder(com.okta.idx.sdk.api.request.PollRequestBuilder) Credentials(com.okta.idx.sdk.api.model.Credentials) FormValue(com.okta.idx.sdk.api.model.FormValue) RemediationType(com.okta.idx.sdk.api.model.RemediationType) WrapperUtil.handleIllegalArgumentException(com.okta.idx.sdk.api.client.WrapperUtil.handleIllegalArgumentException) AuthenticationOptions(com.okta.idx.sdk.api.model.AuthenticationOptions) EmailTokenType(com.okta.idx.sdk.api.model.EmailTokenType) RecoverRequestBuilder(com.okta.idx.sdk.api.request.RecoverRequestBuilder) AuthenticatorEnrollments(com.okta.idx.sdk.api.model.AuthenticatorEnrollments) IDXClientContext(com.okta.idx.sdk.api.model.IDXClientContext) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) PollRequest(com.okta.idx.sdk.api.request.PollRequest) PollInfo(com.okta.idx.sdk.api.model.PollInfo) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) FormValue(com.okta.idx.sdk.api.model.FormValue) RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) 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 5 with RemediationOption

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

the class AuthenticationTransaction method fillOutIdps.

private void fillOutIdps(AuthenticationResponse authenticationResponse) {
    if (idxResponse == null || idxResponse.remediation() == null) {
        return;
    }
    List<Idp> idpList = new LinkedList<>();
    RemediationOption[] remediationOptions = this.getResponse().remediation().remediationOptions();
    List<RemediationOption> remediationOptionList = Arrays.stream(remediationOptions).filter(x -> "redirect-idps".equals(x.getName()) || "redirect-idp".equals(x.getName())).collect(Collectors.toList());
    for (RemediationOption remediationOption : remediationOptionList) {
        idpList.add(new Idp(remediationOption.getType(), remediationOption.getHref()));
    }
    authenticationResponse.setIdps(idpList);
}
Also used : Arrays(java.util.Arrays) OptionsForm(com.okta.idx.sdk.api.model.OptionsForm) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) CurrentAuthenticatorEnrollment(com.okta.idx.sdk.api.model.CurrentAuthenticatorEnrollment) LoggerFactory(org.slf4j.LoggerFactory) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Options(com.okta.idx.sdk.api.model.Options) Locale(java.util.Locale) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) Map(java.util.Map) LinkedList(java.util.LinkedList) Assert(com.okta.commons.lang.Assert) Logger(org.slf4j.Logger) RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) FormValue(com.okta.idx.sdk.api.model.FormValue) RemediationType(com.okta.idx.sdk.api.model.RemediationType) AuthenticationStatus(com.okta.idx.sdk.api.model.AuthenticationStatus) Response(com.okta.commons.http.Response) CurrentAuthenticatorEnrollmentValue(com.okta.idx.sdk.api.model.CurrentAuthenticatorEnrollmentValue) EmailTokenType(com.okta.idx.sdk.api.model.EmailTokenType) Collectors(java.util.stream.Collectors) List(java.util.List) IDXClientContext(com.okta.idx.sdk.api.model.IDXClientContext) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) Optional(java.util.Optional) Idp(com.okta.idx.sdk.api.model.Idp) PollInfo(com.okta.idx.sdk.api.model.PollInfo) Idp(com.okta.idx.sdk.api.model.Idp) RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) LinkedList(java.util.LinkedList)

Aggregations

RemediationOption (com.okta.idx.sdk.api.model.RemediationOption)5 ProcessingException (com.okta.idx.sdk.api.exception.ProcessingException)3 PollInfo (com.okta.idx.sdk.api.model.PollInfo)3 IDXResponse (com.okta.idx.sdk.api.response.IDXResponse)3 Response (com.okta.commons.http.Response)2 Assert (com.okta.commons.lang.Assert)2 WrapperUtil.handleIllegalArgumentException (com.okta.idx.sdk.api.client.WrapperUtil.handleIllegalArgumentException)2 WrapperUtil.handleProcessingException (com.okta.idx.sdk.api.client.WrapperUtil.handleProcessingException)2 AuthenticationStatus (com.okta.idx.sdk.api.model.AuthenticationStatus)2 Authenticator (com.okta.idx.sdk.api.model.Authenticator)2 EmailTokenType (com.okta.idx.sdk.api.model.EmailTokenType)2 FormValue (com.okta.idx.sdk.api.model.FormValue)2 IDXClientContext (com.okta.idx.sdk.api.model.IDXClientContext)2 Recover (com.okta.idx.sdk.api.model.Recover)2 RemediationType (com.okta.idx.sdk.api.model.RemediationType)2 IdentifyRequest (com.okta.idx.sdk.api.request.IdentifyRequest)2 RecoverRequest (com.okta.idx.sdk.api.request.RecoverRequest)2 AuthenticationResponse (com.okta.idx.sdk.api.response.AuthenticationResponse)2 TokenResponse (com.okta.idx.sdk.api.response.TokenResponse)2 Arrays (java.util.Arrays)2