use of com.okta.idx.sdk.api.client.Authenticator in project okta-idx-java by okta.
the class ResponseHandler method selectAuthenticatorForm.
/**
* Return the view for select authenticator form.
* @param response the response
* @param title the view title
* @param session the session
* @return the view associated with the response authentication status.
*/
public ModelAndView selectAuthenticatorForm(AuthenticationResponse response, String title, HttpSession session) {
boolean canSkip = authenticationWrapper.isSkipAuthenticatorPresent(response.getProceedContext());
ModelAndView modelAndView = new ModelAndView("select-authenticator");
modelAndView.addObject("canSkip", canSkip);
List<String> factorMethods = new ArrayList<>();
for (Authenticator authenticator : response.getAuthenticators()) {
for (Authenticator.Factor factor : authenticator.getFactors()) {
factorMethods.add(factor.getMethod());
}
}
session.setAttribute("authenticators", response.getAuthenticators());
modelAndView.addObject("factorList", factorMethods);
modelAndView.addObject("authenticators", response.getAuthenticators());
modelAndView.addObject("title", title);
return modelAndView;
}
use of com.okta.idx.sdk.api.client.Authenticator in project okta-idx-java by okta.
the class HomeController method displaySelectAuthenticatorPage.
/**
* Display the select authenticator page.
*
* @param session the http session
* @param completedAuthenticatorType the last enrolled/verified authenticator type
* @return the select authenticators view.
*/
@GetMapping("/select-authenticator")
public ModelAndView displaySelectAuthenticatorPage(final HttpSession session, @RequestParam(value = "completed", required = false) final String completedAuthenticatorType) {
List<Authenticator> authenticators = (List<Authenticator>) session.getAttribute("authenticators");
if (completedAuthenticatorType != null) {
authenticators.removeIf(authenticator -> authenticator.getLabel().equals(completedAuthenticatorType));
}
TokenResponse tokenResponse = (TokenResponse) session.getAttribute("tokenResponse");
if (tokenResponse != null) {
return homeHelper.proceedToHome(tokenResponse, session);
}
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
boolean canSkip = authenticationWrapper.isSkipAuthenticatorPresent(proceedContext);
ModelAndView modelAndView = new ModelAndView("select-authenticator");
modelAndView.addObject("title", "Select Authenticator");
modelAndView.addObject("canSkip", canSkip);
modelAndView.addObject("authenticators", authenticators);
return modelAndView;
}
use of com.okta.idx.sdk.api.client.Authenticator in project okta-idx-java by okta.
the class LoginController method selectAuthenticator.
/**
* Handle authenticator selection during authentication.
*
* @param authenticatorType the authenticatorType
* @param session the session
* @param action the submit or cancel action from form post
* @return select authenticator view or select factor view or error view
*/
@PostMapping(value = "/select-authenticator")
public ModelAndView selectAuthenticator(@RequestParam("authenticator-type") final String authenticatorType, @RequestParam(value = "action") final String action, final HttpSession session) {
AuthenticationResponse authenticationResponse = null;
Authenticator foundAuthenticator = null;
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
if ("skip".equals(action)) {
logger.info("Skipping {} authenticator", authenticatorType);
authenticationResponse = idxAuthenticationWrapper.skipAuthenticatorEnrollment(proceedContext);
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
List<Authenticator> authenticators = (List<Authenticator>) session.getAttribute("authenticators");
if ("webauthn".equals(authenticatorType)) {
ModelAndView modelAndView;
Optional<Authenticator> authenticatorOptional = authenticators.stream().filter(auth -> auth.getType().equals(authenticatorType)).findFirst();
String authId = authenticatorOptional.get().getId();
AuthenticationResponse enrollResponse = idxAuthenticationWrapper.enrollAuthenticator(proceedContext, authId);
Util.updateSession(session, enrollResponse.getProceedContext());
String webauthnCredentialId = enrollResponse.getWebAuthnParams().getWebauthnCredentialId();
if (webauthnCredentialId != null) {
modelAndView = new ModelAndView("select-webauthn-authenticator");
modelAndView.addObject("title", "Select Webauthn Authenticator");
modelAndView.addObject("webauthnCredentialId", webauthnCredentialId);
modelAndView.addObject("challengeData", enrollResponse.getWebAuthnParams().getCurrentAuthenticator().getValue().getContextualData().getChallengeData());
} else {
modelAndView = new ModelAndView("enroll-webauthn-authenticator");
modelAndView.addObject("title", "Enroll Webauthn Authenticator");
modelAndView.addObject("currentAuthenticator", enrollResponse.getWebAuthnParams().getCurrentAuthenticator());
}
return modelAndView;
}
if ("okta_verify".equals(authenticatorType)) {
ModelAndView modelAndView;
Optional<Authenticator> authenticatorOptional = authenticators.stream().filter(auth -> auth.getType().equals(authenticatorType)).findFirst();
Assert.isTrue(authenticatorOptional.isPresent(), "Authenticator not found");
// Looking for QRCODE factor
Optional<Authenticator.Factor> factorOptional = authenticatorOptional.get().getFactors().stream().filter(x -> "QRCODE".equals(x.getLabel())).findFirst();
Assert.isTrue(factorOptional.isPresent(), "Authenticator not found");
authenticationResponse = idxAuthenticationWrapper.selectFactor(proceedContext, factorOptional.get());
Util.setProceedContextForPoll(session, authenticationResponse.getProceedContext());
List<Authenticator.Factor> factors = authenticatorOptional.get().getFactors().stream().filter(x -> !"QRCODE".equals(x.getLabel())).collect(Collectors.toList());
modelAndView = new ModelAndView("setup-okta-verify");
modelAndView.addObject("qrCode", authenticationResponse.getContextualData().getQrcode().getHref());
modelAndView.addObject("channelName", "qrcode");
modelAndView.addObject("factors", factors);
modelAndView.addObject("authenticatorId", authenticatorOptional.get().getId());
modelAndView.addObject("pollTimeout", authenticationResponse.getProceedContext().getRefresh());
return modelAndView;
}
for (Authenticator authenticator : authenticators) {
if (authenticatorType.equals(authenticator.getType())) {
foundAuthenticator = authenticator;
if (foundAuthenticator.getFactors().size() == 1) {
authenticationResponse = idxAuthenticationWrapper.selectAuthenticator(proceedContext, authenticator);
if (authenticationResponse.getContextualData() != null) {
session.setAttribute("totp", authenticationResponse.getContextualData());
} else {
session.removeAttribute("totp");
}
} else {
// user should select the factor in a separate view
ModelAndView modelAndView = new ModelAndView("select-factor");
modelAndView.addObject("title", "Select Factor");
modelAndView.addObject("authenticatorId", foundAuthenticator.getId());
modelAndView.addObject("factors", foundAuthenticator.getFactors());
return modelAndView;
}
}
}
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("select-authenticator");
modelAndView.addObject("errors", authenticationResponse.getErrors());
return modelAndView;
}
ModelAndView terminalTransition = responseHandler.handleTerminalTransitions(authenticationResponse, session);
if (terminalTransition != null) {
return terminalTransition;
}
switch(authenticationResponse.getAuthenticationStatus()) {
case AWAITING_AUTHENTICATOR_VERIFICATION_DATA:
return responseHandler.verifyForm();
case AWAITING_AUTHENTICATOR_ENROLLMENT:
case AWAITING_AUTHENTICATOR_ENROLLMENT_DATA:
return responseHandler.registerVerifyForm(foundAuthenticator);
case AWAITING_POLL_ENROLLMENT:
return responseHandler.setupOktaVerifyForm(session);
default:
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
}
use of com.okta.idx.sdk.api.client.Authenticator in project okta-idx-java by okta.
the class LoginController method selectFactor.
/**
* Handle factor selection during authentication.
*
* @param authenticatorId the authenticator ID of selected authenticator
* @param mode the sms or voice factor mode
* @param session the session
* @return the view associated with authentication response.
*/
@PostMapping("/select-factor")
public ModelAndView selectFactor(@RequestParam("authenticatorId") final String authenticatorId, @RequestParam("mode") final String mode, final HttpSession session) {
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
List<Authenticator> authenticators = (List<Authenticator>) session.getAttribute("authenticators");
Authenticator foundAuthenticator = null;
for (Authenticator auth : authenticators) {
if (auth.getId().equals(authenticatorId)) {
foundAuthenticator = auth;
}
}
Assert.notNull(foundAuthenticator, "Authenticator not found");
AuthenticationResponse authenticationResponse = null;
Authenticator.Factor foundFactor = null;
for (Authenticator.Factor factor : foundAuthenticator.getFactors()) {
if (factor.getMethod().equals(mode)) {
foundFactor = factor;
authenticationResponse = idxAuthenticationWrapper.selectFactor(proceedContext, foundFactor);
Optional.ofNullable(authenticationResponse.getContextualData()).map(ContextualData::getQrcode).map(Qrcode::getHref).ifPresent(qrCode -> {
session.setAttribute("qrCode", qrCode);
session.setAttribute("channelName", "qrcode");
});
if ("totp".equals(foundFactor.getMethod())) {
session.setAttribute("totp", "totp");
}
break;
}
}
Assert.notNull(foundFactor, "Factor not found");
ModelAndView terminalTransition = responseHandler.handleTerminalTransitions(authenticationResponse, session);
if (terminalTransition != null) {
return terminalTransition;
}
switch(authenticationResponse.getAuthenticationStatus()) {
case AWAITING_AUTHENTICATOR_VERIFICATION_DATA:
return responseHandler.verifyForm();
case AWAITING_AUTHENTICATOR_ENROLLMENT:
case AWAITING_AUTHENTICATOR_ENROLLMENT_DATA:
return responseHandler.registerVerifyForm(foundFactor);
case AWAITING_CHANNEL_DATA_ENROLLMENT:
return responseHandler.oktaVerifyViaChannelDataForm(foundFactor, session);
case AWAITING_POLL_ENROLLMENT:
return responseHandler.setupOktaVerifyForm(session);
case AWAITING_CHALLENGE_POLL:
return responseHandler.oktaVerifyChallenge(authenticationResponse);
default:
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
}
Aggregations