Search in sources :

Example 1 with Authenticator

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

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

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

Aggregations

Authenticator (com.okta.idx.sdk.api.model.Authenticator)3 WrapperUtil.handleIllegalArgumentException (com.okta.idx.sdk.api.client.WrapperUtil.handleIllegalArgumentException)2 WrapperUtil.handleProcessingException (com.okta.idx.sdk.api.client.WrapperUtil.handleProcessingException)2 ProcessingException (com.okta.idx.sdk.api.exception.ProcessingException)2 RemediationOption (com.okta.idx.sdk.api.model.RemediationOption)2 AnswerChallengeRequest (com.okta.idx.sdk.api.request.AnswerChallengeRequest)2 ChallengeRequest (com.okta.idx.sdk.api.request.ChallengeRequest)2 EnrollRequest (com.okta.idx.sdk.api.request.EnrollRequest)2 Response (com.okta.commons.http.Response)1 Assert (com.okta.commons.lang.Assert)1 AuthenticationOptions (com.okta.idx.sdk.api.model.AuthenticationOptions)1 AuthenticationStatus (com.okta.idx.sdk.api.model.AuthenticationStatus)1 AuthenticatorEnrollment (com.okta.idx.sdk.api.model.AuthenticatorEnrollment)1 AuthenticatorEnrollments (com.okta.idx.sdk.api.model.AuthenticatorEnrollments)1 Credentials (com.okta.idx.sdk.api.model.Credentials)1 DeviceContext (com.okta.idx.sdk.api.model.DeviceContext)1 EmailTokenType (com.okta.idx.sdk.api.model.EmailTokenType)1 FormValue (com.okta.idx.sdk.api.model.FormValue)1 IDXClientContext (com.okta.idx.sdk.api.model.IDXClientContext)1 PollInfo (com.okta.idx.sdk.api.model.PollInfo)1