Search in sources :

Example 1 with AuthenticationOptions

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);
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) Qrcode(com.okta.idx.sdk.api.model.Qrcode) ContextualData(com.okta.idx.sdk.api.model.ContextualData) Util(com.okta.spring.example.helpers.Util) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) Authenticator(com.okta.idx.sdk.api.client.Authenticator) UserProfile(com.okta.idx.sdk.api.model.UserProfile) ResponseHandler(com.okta.spring.example.helpers.ResponseHandler) RequestBody(org.springframework.web.bind.annotation.RequestBody) ProceedContext(com.okta.idx.sdk.api.client.ProceedContext) IDXAuthenticationWrapper(com.okta.idx.sdk.api.client.IDXAuthenticationWrapper) VerifyChannelDataOptions(com.okta.idx.sdk.api.model.VerifyChannelDataOptions) PollResults(com.okta.spring.example.helpers.PollResults) GetMapping(org.springframework.web.bind.annotation.GetMapping) VerifyAuthenticatorOptions(com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions) HttpSession(javax.servlet.http.HttpSession) PostMapping(org.springframework.web.bind.annotation.PostMapping) Strings(com.okta.commons.lang.Strings) VerifyAuthenticatorAnswer(com.okta.idx.sdk.api.model.VerifyAuthenticatorAnswer) Assert(com.okta.commons.lang.Assert) Logger(org.slf4j.Logger) FormValue(com.okta.idx.sdk.api.model.FormValue) AuthenticationOptions(com.okta.idx.sdk.api.model.AuthenticationOptions) AuthenticationStatus(com.okta.idx.sdk.api.model.AuthenticationStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) WebAuthnRequest(com.okta.idx.sdk.api.request.WebAuthnRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) Optional(java.util.Optional) AuthenticationOptions(com.okta.idx.sdk.api.model.AuthenticationOptions) ModelAndView(org.springframework.web.servlet.ModelAndView) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) ProceedContext(com.okta.idx.sdk.api.client.ProceedContext) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

Assert (com.okta.commons.lang.Assert)1 Strings (com.okta.commons.lang.Strings)1 Authenticator (com.okta.idx.sdk.api.client.Authenticator)1 IDXAuthenticationWrapper (com.okta.idx.sdk.api.client.IDXAuthenticationWrapper)1 ProceedContext (com.okta.idx.sdk.api.client.ProceedContext)1 AuthenticationOptions (com.okta.idx.sdk.api.model.AuthenticationOptions)1 AuthenticationStatus (com.okta.idx.sdk.api.model.AuthenticationStatus)1 ContextualData (com.okta.idx.sdk.api.model.ContextualData)1 FormValue (com.okta.idx.sdk.api.model.FormValue)1 Qrcode (com.okta.idx.sdk.api.model.Qrcode)1 UserProfile (com.okta.idx.sdk.api.model.UserProfile)1 VerifyAuthenticatorAnswer (com.okta.idx.sdk.api.model.VerifyAuthenticatorAnswer)1 VerifyAuthenticatorOptions (com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions)1 VerifyChannelDataOptions (com.okta.idx.sdk.api.model.VerifyChannelDataOptions)1 WebAuthnRequest (com.okta.idx.sdk.api.request.WebAuthnRequest)1 AuthenticationResponse (com.okta.idx.sdk.api.response.AuthenticationResponse)1 PollResults (com.okta.spring.example.helpers.PollResults)1 ResponseHandler (com.okta.spring.example.helpers.ResponseHandler)1 Util (com.okta.spring.example.helpers.Util)1 Arrays (java.util.Arrays)1