Search in sources :

Example 1 with EnrollRequest

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

the class IDXAuthenticationWrapper method submitPhoneAuthenticator.

/**
 * Submit phone authenticator enrollment with the provided phone number.
 *
 * @param proceedContext the ProceedContext
 * @param phone the phone number
 * @param factor factor
 * @return the Authentication response
 */
public AuthenticationResponse submitPhoneAuthenticator(ProceedContext proceedContext, String phone, com.okta.idx.sdk.api.client.Authenticator.Factor factor) {
    try {
        Assert.notNull(proceedContext, "proceed context cannot be null");
        Authenticator phoneAuthenticator = new Authenticator();
        phoneAuthenticator.setId(factor.getId());
        phoneAuthenticator.setMethodType(factor.getMethod());
        phoneAuthenticator.setPhoneNumber(phone);
        EnrollRequest enrollRequest = EnrollRequestBuilder.builder().withAuthenticator(phoneAuthenticator).withStateHandle(proceedContext.getStateHandle()).build();
        return AuthenticationTransaction.proceed(client, proceedContext, () -> client.enroll(enrollRequest, proceedContext.getHref())).asAuthenticationResponse();
    } catch (ProcessingException e) {
        return handleProcessingException(e);
    } catch (IllegalArgumentException e) {
        return handleIllegalArgumentException(e);
    }
}
Also used : EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) Authenticator(com.okta.idx.sdk.api.model.Authenticator) 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 2 with EnrollRequest

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

the class IDXAuthenticationWrapper method enrollAuthenticator.

public AuthenticationResponse enrollAuthenticator(ProceedContext proceedContext, String authenticatorId) {
    try {
        AuthenticationResponse authenticationResponse = AuthenticationTransaction.proceed(client, proceedContext, () -> {
            Authenticator authenticator = new Authenticator();
            authenticator.setId(authenticatorId);
            EnrollRequest enrollRequest = EnrollRequestBuilder.builder().withAuthenticator(authenticator).withStateHandle(proceedContext.getStateHandle()).build();
            return client.enroll(enrollRequest, proceedContext.getHref());
        }).asAuthenticationResponse();
        if (authenticationResponse.getWebAuthnParams() != null) {
            AuthenticatorEnrollments authenticatorEnrollments = authenticationResponse.getAuthenticatorEnrollments();
            Optional<AuthenticatorEnrollment> authenticatorEnrollmentOptional = authenticatorEnrollments.stream().filter(x -> "security_key".equals(x.getType())).findAny();
            authenticatorEnrollmentOptional.ifPresent(authenticatorEnrollment -> authenticationResponse.getWebAuthnParams().setWebauthnCredentialId(authenticatorEnrollment.getCredentialId()));
        }
        return authenticationResponse;
    } 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) AuthenticatorEnrollment(com.okta.idx.sdk.api.model.AuthenticatorEnrollment) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) AuthenticatorEnrollments(com.okta.idx.sdk.api.model.AuthenticatorEnrollments) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) Authenticator(com.okta.idx.sdk.api.model.Authenticator) 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 3 with EnrollRequest

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

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

the class BaseIDXClient method enroll.

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

ProcessingException (com.okta.idx.sdk.api.exception.ProcessingException)4 EnrollRequest (com.okta.idx.sdk.api.request.EnrollRequest)4 Response (com.okta.commons.http.Response)3 WrapperUtil.handleIllegalArgumentException (com.okta.idx.sdk.api.client.WrapperUtil.handleIllegalArgumentException)3 WrapperUtil.handleProcessingException (com.okta.idx.sdk.api.client.WrapperUtil.handleProcessingException)3 Authenticator (com.okta.idx.sdk.api.model.Authenticator)3 AnswerChallengeRequest (com.okta.idx.sdk.api.request.AnswerChallengeRequest)3 ChallengeRequest (com.okta.idx.sdk.api.request.ChallengeRequest)3 EnrollUserProfileUpdateRequest (com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest)3 IdentifyRequest (com.okta.idx.sdk.api.request.IdentifyRequest)3 PollRequest (com.okta.idx.sdk.api.request.PollRequest)3 RecoverRequest (com.okta.idx.sdk.api.request.RecoverRequest)3 SkipAuthenticatorEnrollmentRequest (com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest)3 ErrorResponse (com.okta.idx.sdk.api.response.ErrorResponse)3 IDXResponse (com.okta.idx.sdk.api.response.IDXResponse)3 TokenResponse (com.okta.idx.sdk.api.response.TokenResponse)3 Assert (com.okta.commons.lang.Assert)2 AuthenticationOptions (com.okta.idx.sdk.api.model.AuthenticationOptions)2 AuthenticationStatus (com.okta.idx.sdk.api.model.AuthenticationStatus)2 AuthenticatorEnrollment (com.okta.idx.sdk.api.model.AuthenticatorEnrollment)2