use of com.okta.idx.sdk.api.model.AuthenticationOptions 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);
}
Aggregations