use of com.okta.idx.sdk.api.client.ProceedContext in project okta-idx-java by okta.
the class LoginController method login.
/**
* Handle login with the supplied username and password.
*
* @param username the username
* @param password the password
* @param session the session
* @return the home page view (if login is successful), else the login page with errors.
*/
@PostMapping("/login")
public ModelAndView login(@RequestParam("username") final String username, @RequestParam("password") final String password, final HttpSession session) {
// begin transaction
AuthenticationResponse beginResponse = idxAuthenticationWrapper.begin();
// get proceed context
ProceedContext proceedContext = beginResponse.getProceedContext();
// trigger authentication
AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.authenticate(new AuthenticationOptions(username, password.toCharArray()), proceedContext);
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("redirect:/login");
modelAndView.addObject("errors", authenticationResponse.getErrors());
return modelAndView;
}
if (authenticationResponse.getAuthenticatorEnrollments() != null) {
authenticationResponse.getAuthenticatorEnrollments().stream().filter(x -> x.getDisplayName().equals("Okta Verify")).findFirst().flatMap(enroll -> Arrays.stream(enroll.getMethods()).filter(methodType -> methodType.getType().equals("totp")).findFirst()).ifPresent(methodType -> session.setAttribute("totp", "totp"));
}
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 pollResults.
/**
* Handle poll functionality.
*
* @param session the session
* @return the view associated with authentication response.
*/
@GetMapping("/poll")
@ResponseBody
public PollResults pollResults(final HttpSession session) {
PollResults pollResults = new PollResults();
ProceedContext proceedContext = Util.getProceedContextForPoll(session);
if (proceedContext == null) {
proceedContext = Util.getProceedContextFromSession(session);
}
AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.poll(proceedContext);
if (responseHandler.needsToShowErrors(authenticationResponse)) {
pollResults.setErrors(authenticationResponse.getErrors());
}
pollResults.setStatus(authenticationResponse.getAuthenticationStatus());
if (authenticationResponse.getAuthenticationStatus() == AuthenticationStatus.SUCCESS) {
responseHandler.handleTerminalTransitions(authenticationResponse, session);
}
return pollResults;
}
use of com.okta.idx.sdk.api.client.ProceedContext in project okta-idx-java by okta.
the class LoginController method verify.
/**
* Handle authenticator verification functionality.
*
* @param code the verification code
* @param securityQuestionKey the security question key
* @param session the session
* @return the view associated with authentication response.
*/
@PostMapping("/verify")
public ModelAndView verify(@RequestParam("code") final String code, @RequestParam(value = "security_question_key", required = false) final String securityQuestionKey, final HttpSession session) {
logger.info(":: Verify Code :: {}", code);
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
AuthenticationResponse authenticationResponse;
if (!Strings.isEmpty(securityQuestionKey)) {
authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, new VerifyAuthenticatorAnswer(code, securityQuestionKey));
} else if ("totp".equals(String.valueOf(session.getAttribute("totp")))) {
authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, new VerifyChannelDataOptions("totp", code));
} else {
VerifyAuthenticatorOptions verifyAuthenticatorOptions = new VerifyAuthenticatorOptions(code);
authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, verifyAuthenticatorOptions);
}
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("verify");
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 verifyChannelData.
/**
* Handle channel data verification functionality.
*
* @param channelName the channel name
* @param channelValue the value for channel
* @param session the session
* @return the view associated with authentication response.
*/
@PostMapping("/verify-channel-data")
public ModelAndView verifyChannelData(@RequestParam("channelName") final String channelName, @RequestParam("channelValue") final String channelValue, final HttpSession session) {
logger.info(":: Verify Channel Name, Value :: {}, {}", channelName, channelValue);
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
VerifyChannelDataOptions verifyChannelDataOptions = new VerifyChannelDataOptions(channelName, channelValue);
AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, verifyChannelDataOptions);
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("verify");
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 registerPassword.
/**
* Handle change password functionality.
*
* @param newPassword the new password
* @param confirmNewPassword the confirmation of the new password
* @param session the session
* @return the view associated with authentication response.
*/
@PostMapping("/register-password")
public ModelAndView registerPassword(@RequestParam("new-password") final String newPassword, @RequestParam("confirm-new-password") final String confirmNewPassword, final HttpSession session) {
logger.info(":: Change Password ::");
if (!newPassword.equals(confirmNewPassword)) {
ModelAndView mav = new ModelAndView("register-password");
mav.addObject("errors", "Passwords do not match");
return mav;
}
ProceedContext proceedContext = Util.getProceedContextFromSession(session);
VerifyAuthenticatorOptions verifyAuthenticatorOptions = new VerifyAuthenticatorOptions(newPassword);
AuthenticationResponse authenticationResponse = idxAuthenticationWrapper.verifyAuthenticator(proceedContext, verifyAuthenticatorOptions);
if (responseHandler.needsToShowErrors(authenticationResponse)) {
ModelAndView modelAndView = new ModelAndView("register-password");
modelAndView.addObject("errors", authenticationResponse.getErrors());
return modelAndView;
}
return responseHandler.handleKnownTransitions(authenticationResponse, session);
}
Aggregations