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));
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations