Search in sources :

Example 1 with UserProfile

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

Example 2 with UserProfile

use of com.okta.idx.sdk.api.model.UserProfile in project okta-idx-java by okta.

the class IDXAuthenticationWrapper method fetchSignUpFormValues.

/**
 * Populate UI form values for signing up a new user.
 *
 * @param proceedContext the proceedContext
 * @return the authentication response
 */
public AuthenticationResponse fetchSignUpFormValues(ProceedContext proceedContext) {
    AuthenticationResponse newUserRegistrationResponse = new AuthenticationResponse();
    try {
        Assert.notNull(proceedContext.getSelectProfileEnrollHref(), "Org policy is not configured to register new users.");
        // enroll new user
        AuthenticationTransaction enrollTransaction = AuthenticationTransaction.proceed(client, proceedContext, () -> {
            EnrollRequest enrollRequest = EnrollRequestBuilder.builder().withStateHandle(proceedContext.getStateHandle()).build();
            return client.enroll(enrollRequest, proceedContext.getSelectProfileEnrollHref());
        });
        RemediationOption enrollProfileRemediationOption = enrollTransaction.getRemediationOption(RemediationType.ENROLL_PROFILE);
        List<FormValue> enrollProfileFormValues = Arrays.stream(enrollProfileRemediationOption.form()).filter(x -> "userProfile".equals(x.getName())).collect(Collectors.toList());
        newUserRegistrationResponse.setFormValues(enrollProfileFormValues);
        newUserRegistrationResponse.setProceedContext(enrollTransaction.createProceedContext());
        return newUserRegistrationResponse;
    } catch (ProcessingException e) {
        return handleProcessingException(e);
    } catch (IllegalArgumentException e) {
        return handleIllegalArgumentException(e);
    }
}
Also used : DeviceContext(com.okta.idx.sdk.api.model.DeviceContext) Arrays(java.util.Arrays) ChallengeRequestBuilder(com.okta.idx.sdk.api.request.ChallengeRequestBuilder) SkipAuthenticatorEnrollmentRequest(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequest) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) LoggerFactory(org.slf4j.LoggerFactory) IdentifyRequest(com.okta.idx.sdk.api.request.IdentifyRequest) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException) SkipAuthenticatorEnrollmentRequestBuilder(com.okta.idx.sdk.api.request.SkipAuthenticatorEnrollmentRequestBuilder) ErrorResponse(com.okta.idx.sdk.api.response.ErrorResponse) Recover(com.okta.idx.sdk.api.model.Recover) IDXResponse(com.okta.idx.sdk.api.response.IDXResponse) Map(java.util.Map) ClientUtil(com.okta.idx.sdk.api.util.ClientUtil) EnrollUserProfileUpdateRequestBuilder(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequestBuilder) Assert(com.okta.commons.lang.Assert) RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) Set(java.util.Set) AuthenticationStatus(com.okta.idx.sdk.api.model.AuthenticationStatus) Response(com.okta.commons.http.Response) WrapperUtil.handleProcessingException(com.okta.idx.sdk.api.client.WrapperUtil.handleProcessingException) EnrollRequestBuilder(com.okta.idx.sdk.api.request.EnrollRequestBuilder) Collectors(java.util.stream.Collectors) WebAuthnRequest(com.okta.idx.sdk.api.request.WebAuthnRequest) List(java.util.List) Optional(java.util.Optional) AuthenticatorEnrollment(com.okta.idx.sdk.api.model.AuthenticatorEnrollment) AnswerChallengeRequest(com.okta.idx.sdk.api.request.AnswerChallengeRequest) EnrollUserProfileUpdateRequest(com.okta.idx.sdk.api.request.EnrollUserProfileUpdateRequest) UserProfile(com.okta.idx.sdk.api.model.UserProfile) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) TokenType(com.okta.idx.sdk.api.model.TokenType) VerifyChannelDataOptions(com.okta.idx.sdk.api.model.VerifyChannelDataOptions) ChallengeRequest(com.okta.idx.sdk.api.request.ChallengeRequest) Authenticator(com.okta.idx.sdk.api.model.Authenticator) IdentifyRequestBuilder(com.okta.idx.sdk.api.request.IdentifyRequestBuilder) VerifyAuthenticatorOptions(com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions) AnswerChallengeRequestBuilder(com.okta.idx.sdk.api.request.AnswerChallengeRequestBuilder) RecoverRequest(com.okta.idx.sdk.api.request.RecoverRequest) VerifyAuthenticatorAnswer(com.okta.idx.sdk.api.model.VerifyAuthenticatorAnswer) Logger(org.slf4j.Logger) PollRequestBuilder(com.okta.idx.sdk.api.request.PollRequestBuilder) Credentials(com.okta.idx.sdk.api.model.Credentials) FormValue(com.okta.idx.sdk.api.model.FormValue) RemediationType(com.okta.idx.sdk.api.model.RemediationType) WrapperUtil.handleIllegalArgumentException(com.okta.idx.sdk.api.client.WrapperUtil.handleIllegalArgumentException) AuthenticationOptions(com.okta.idx.sdk.api.model.AuthenticationOptions) EmailTokenType(com.okta.idx.sdk.api.model.EmailTokenType) RecoverRequestBuilder(com.okta.idx.sdk.api.request.RecoverRequestBuilder) AuthenticatorEnrollments(com.okta.idx.sdk.api.model.AuthenticatorEnrollments) IDXClientContext(com.okta.idx.sdk.api.model.IDXClientContext) TokenResponse(com.okta.idx.sdk.api.response.TokenResponse) PollRequest(com.okta.idx.sdk.api.request.PollRequest) PollInfo(com.okta.idx.sdk.api.model.PollInfo) EnrollRequest(com.okta.idx.sdk.api.request.EnrollRequest) FormValue(com.okta.idx.sdk.api.model.FormValue) RemediationOption(com.okta.idx.sdk.api.model.RemediationOption) AuthenticationResponse(com.okta.idx.sdk.api.response.AuthenticationResponse) WrapperUtil.handleIllegalArgumentException(com.okta.idx.sdk.api.client.WrapperUtil.handleIllegalArgumentException) ProcessingException(com.okta.idx.sdk.api.exception.ProcessingException) WrapperUtil.handleProcessingException(com.okta.idx.sdk.api.client.WrapperUtil.handleProcessingException)

Aggregations

Assert (com.okta.commons.lang.Assert)2 AuthenticationOptions (com.okta.idx.sdk.api.model.AuthenticationOptions)2 AuthenticationStatus (com.okta.idx.sdk.api.model.AuthenticationStatus)2 FormValue (com.okta.idx.sdk.api.model.FormValue)2 UserProfile (com.okta.idx.sdk.api.model.UserProfile)2 VerifyAuthenticatorAnswer (com.okta.idx.sdk.api.model.VerifyAuthenticatorAnswer)2 VerifyAuthenticatorOptions (com.okta.idx.sdk.api.model.VerifyAuthenticatorOptions)2 VerifyChannelDataOptions (com.okta.idx.sdk.api.model.VerifyChannelDataOptions)2 WebAuthnRequest (com.okta.idx.sdk.api.request.WebAuthnRequest)2 AuthenticationResponse (com.okta.idx.sdk.api.response.AuthenticationResponse)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Response (com.okta.commons.http.Response)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