use of com.okta.idx.sdk.api.client.ProceedContext in project okta-idx-java by okta.
the class LoginController method registerPhone.
/**
* Handle phone authenticator enrollment functionality.
*
* @param phone the phone number
* @param mode the delivery mode - sms or voice
* @param session the session
* @return the view associated with authentication response.
*/
@PostMapping(value = "/register-phone")
public ModelAndView registerPhone(@RequestParam("phone") final String phone, @RequestParam(value = "mode", required = false) final String mode, final HttpSession session) {
logger.info(":: Enroll Phone Authenticator ::");
if (!Strings.hasText(phone)) {
ModelAndView mav = new ModelAndView("register-phone");
mav.addObject("errors", "Phone is required");
return mav;
}
if (!Strings.hasText(mode)) {
ModelAndView modelAndView = new ModelAndView("select-phone-factor");
modelAndView.addObject("phone", phone);
return modelAndView;
}
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.submitPhoneAuthenticator(proceedContext, phone, getPhoneFactorFromMethod(session, mode));
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("register-phone");
modelAndView.addObject("mode", mode);
modelAndView.addObject("errors", authenticationResponse.getErrors());
return modelAndView;
}
ModelAndView terminalTransition = responseHandler.handleTerminalTransitions(authenticationResponse, session);
if (terminalTransition != null) {
return terminalTransition;
}
return responseHandler.verifyForm();
}
use of com.okta.idx.sdk.api.client.ProceedContext in project okta-idx-java by okta.
the class LoginController method enrollWebauthn.
/**
* Handle webauthn authenticator enrollment functionality.
*
* @param webauthnRequest body
* @param session the session
* @return the view associated with authentication response.
*/
@PostMapping(value = "/enroll-webauthn")
public ModelAndView enrollWebauthn(@RequestBody final WebAuthnRequest webauthnRequest, final HttpSession session) {
logger.info(":: Enroll Webauthn Authenticator ::");
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.verifyWebAuthn(proceedContext, webauthnRequest);
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
use of com.okta.idx.sdk.api.client.ProceedContext 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);
}
}
use of com.okta.idx.sdk.api.client.ProceedContext in project okta-idx-java by okta.
the class LoginController method register.
/**
* Handle new user registration functionality.
*
* @param userProfileAttributes string array for user profile attributes from register form
* @param session the session
* @return the enroll authenticators view.
*/
@PostMapping("/register")
public ModelAndView register(@RequestParam(value = "userProfileAttribute[]") final String[] userProfileAttributes, final HttpSession session) {
logger.info(":: Register ::");
AuthenticationResponse beginResponse = idxAuthenticationWrapper.begin();
if (responseHandler.needsToShowErrors(beginResponse)) {
ModelAndView modelAndView = new ModelAndView("register");
modelAndView.addObject("errors", beginResponse.getErrors());
return modelAndView;
}
ProceedContext beginProceedContext = beginResponse.getProceedContext();
AuthenticationResponse newUserRegistrationResponse = idxAuthenticationWrapper.fetchSignUpFormValues(beginProceedContext);
if (responseHandler.needsToShowErrors(newUserRegistrationResponse)) {
ModelAndView modelAndView = new ModelAndView("register");
modelAndView.addObject("errors", newUserRegistrationResponse.getErrors());
return modelAndView;
}
if (responseHandler.needsToShowErrors(newUserRegistrationResponse)) {
ModelAndView mav = new ModelAndView("register");
mav.addObject("errors", newUserRegistrationResponse.getErrors());
return mav;
}
UserProfile userProfile = new UserProfile();
// FormValue userProfileFormValue = null;
// for (FormValue formValue: newUserRegistrationResponse.getFormValues()) {
// if (formValue.getName().contentEquals("userProfile")) {
// userProfileFormValue = formValue;
// }
// }
Optional<FormValue> userProfileFormValue = newUserRegistrationResponse.getFormValues().stream().filter(x -> x.getName().equals("userProfile")).findFirst();
if (!userProfileFormValue.isPresent()) {
ModelAndView modelAndView = new ModelAndView("register");
modelAndView.addObject("errors", "Unknown error occurred!");
return modelAndView;
}
int i = 0;
for (FormValue value : userProfileFormValue.get().form().getValue()) {
// Build the user profile
userProfile.addAttribute(value.getName(), userProfileAttributes[i]);
i++;
}
ProceedContext proceedContext = newUserRegistrationResponse.getProceedContext();
AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.register(proceedContext, userProfile);
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("register");
modelAndView.addObject("errors", authenticationResponse.getErrors());
return modelAndView;
}
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
use of com.okta.idx.sdk.api.client.ProceedContext in project okta-idx-java by okta.
the class LoginController method verifyWebAuthn.
/**
* Handle webauthn authenticator verification functionality.
*
* @param webauthnRequest
* @param session the session
* @return the view associated with authentication response.
*/
@PostMapping("/verify-webauthn")
public ModelAndView verifyWebAuthn(@RequestBody final WebAuthnRequest webauthnRequest, final HttpSession session) {
logger.info(":: Verify Webauthn ::");
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.verifyWebAuthn(proceedContext, webauthnRequest);
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("verify-webauthn");
modelAndView.addObject("errors", authenticationResponse.getErrors());
return modelAndView;
}
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
Aggregations