Search in sources :

Example 1 with AuthenticationException

use of com.okta.authn.sdk.AuthenticationException in project okta-oidc-android by okta.

the class SampleActivity method onSignIn.

@Override
public void onSignIn(String username, String password) {
    mSignInDialog.dismiss();
    if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
        mTvStatus.setText("Invalid username or password");
        return;
    }
    showNetworkProgress(true);
    mExecutor.submit(() -> {
        try {
            if (mAuthenticationClient == null) {
                return;
            }
            mAuthenticationClient.authenticate(username, password.toCharArray(), null, new AuthenticationStateHandlerAdapter() {

                @Override
                public void handleUnknown(AuthenticationResponse authenticationResponse) {
                    SampleActivity.this.runOnUiThread(() -> {
                        showNetworkProgress(false);
                        mTvStatus.setText(authenticationResponse.getStatus().name());
                    });
                }

                @Override
                public void handleLockedOut(AuthenticationResponse lockedOut) {
                    SampleActivity.this.runOnUiThread(() -> {
                        showNetworkProgress(false);
                        mTvStatus.setText("Account locked out");
                    });
                }

                @Override
                public void handleSuccess(AuthenticationResponse successResponse) {
                    String sessionToken = successResponse.getSessionToken();
                    mAuthClient.signIn(sessionToken, mPayload, new RequestCallback<Result, AuthorizationException>() {

                        @Override
                        public void onSuccess(@NonNull Result result) {
                            mTvStatus.setText("authentication authorized");
                            mIsSessionSignIn = true;
                            showAuthenticatedMode();
                            showNetworkProgress(false);
                        }

                        @Override
                        public void onError(String error, AuthorizationException exception) {
                            mTvStatus.setText(error);
                        }
                    });
                }
            });
        } catch (AuthenticationException e) {
            Log.e(TAG, Log.getStackTraceString(e));
            runOnUiThread(() -> {
                showNetworkProgress(false);
                mTvStatus.setText(e.getMessage());
            });
        }
    });
}
Also used : RequestCallback(com.okta.oidc.RequestCallback) AuthorizationException(com.okta.oidc.util.AuthorizationException) AuthenticationException(com.okta.authn.sdk.AuthenticationException) NonNull(androidx.annotation.NonNull) AuthenticationStateHandlerAdapter(com.okta.authn.sdk.AuthenticationStateHandlerAdapter) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) Result(com.okta.oidc.results.Result)

Example 2 with AuthenticationException

use of com.okta.authn.sdk.AuthenticationException in project okta-auth-java by okta.

the class LoginController method handlePost.

@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView handlePost(@RequestParam("username") final String username, @RequestParam("password") final String password) {
    final ModelAndView modelAndView = new ModelAndView("home");
    AuthenticationResponse authenticationResponse;
    try {
        authenticationResponse = authenticationClient.authenticate(username, password.toCharArray(), null, ignoringStateHandler);
        // handle factors, if any
        if (authenticationResponse != null && !CollectionUtils.isEmpty(authenticationResponse.getFactors())) {
            return AuthHelper.proceedToVerifyView(authenticationResponse, authenticationClient, ignoringStateHandler);
        }
    } catch (final AuthenticationException e) {
        logger.error("Authentication Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
        modelAndView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
        return modelAndView;
    }
    modelAndView.addObject("authenticationResponse", authenticationResponse);
    return modelAndView;
}
Also used : AuthenticationException(com.okta.authn.sdk.AuthenticationException) ModelAndView(org.springframework.web.servlet.ModelAndView) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with AuthenticationException

use of com.okta.authn.sdk.AuthenticationException in project okta-auth-java by okta.

the class ForgotPasswordController method handleChangePasswordPost.

@RequestMapping(value = "/change-password", method = RequestMethod.POST)
public ModelAndView handleChangePasswordPost(@RequestParam("newPassword") final String newPassword, @RequestParam("stateToken") final String stateToken) {
    final ModelAndView modelAndView = new ModelAndView("home");
    final AuthenticationResponse authenticationResponse;
    try {
        authenticationResponse = authenticationClient.resetPassword(newPassword.toCharArray(), stateToken, ignoringStateHandler);
    } catch (final AuthenticationException e) {
        logger.error("Reset Password Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
        final ModelAndView errorView = new ModelAndView("change-password");
        errorView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
        return errorView;
    }
    logger.info("Reset Password Status: {}", authenticationResponse.getStatus());
    modelAndView.addObject("authenticationResponse", authenticationResponse);
    return modelAndView;
}
Also used : AuthenticationException(com.okta.authn.sdk.AuthenticationException) ModelAndView(org.springframework.web.servlet.ModelAndView) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with AuthenticationException

use of com.okta.authn.sdk.AuthenticationException in project okta-auth-java by okta.

the class ForgotPasswordController method handleAnswerSecurityQuestionPost.

@RequestMapping(value = "/answer-sec-qn", method = RequestMethod.POST)
public ModelAndView handleAnswerSecurityQuestionPost(@RequestParam("secQnAnswer") final String secQnAnswer, @RequestParam("stateToken") final String stateToken) {
    final ModelAndView modelAndView = new ModelAndView("change-password");
    final AuthenticationResponse authenticationResponse;
    try {
        authenticationResponse = authenticationClient.answerRecoveryQuestion(secQnAnswer, stateToken, ignoringStateHandler);
    } catch (final AuthenticationException e) {
        logger.error("Answer Sec Qn Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
        final ModelAndView errorView = new ModelAndView("change-password");
        errorView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
        return errorView;
    }
    logger.info("Answer Recovery Qn Status: {}", authenticationResponse.getStatus());
    modelAndView.addObject("stateToken", stateToken);
    return modelAndView;
}
Also used : AuthenticationException(com.okta.authn.sdk.AuthenticationException) ModelAndView(org.springframework.web.servlet.ModelAndView) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with AuthenticationException

use of com.okta.authn.sdk.AuthenticationException in project okta-auth-java by okta.

the class EmailAuthenticationController method handlePost.

@RequestMapping(value = "/verify-email-authenticator", method = RequestMethod.POST)
public ModelAndView handlePost(@RequestParam(value = "passcode") final String passcode, @RequestParam(value = "factorId") final String factorId, @RequestParam(value = "stateToken") final String stateToken) {
    final ModelAndView modelAndView = new ModelAndView("home");
    final AuthenticationResponse authenticationResponse;
    try {
        final VerifyPassCodeFactorRequest verifyPassCodeFactorRequest = authenticationClient.instantiate(VerifyPassCodeFactorRequest.class);
        verifyPassCodeFactorRequest.setStateToken(stateToken);
        verifyPassCodeFactorRequest.setPassCode(passcode);
        RequestContext requestContext = new RequestContext();
        // false by default
        requestContext.addQuery("rememberDevice", "true");
        authenticationResponse = authenticationClient.verifyFactor(factorId, verifyPassCodeFactorRequest, requestContext, ignoringStateHandler);
    } catch (final AuthenticationException e) {
        logger.error("Verify Email Factor Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
        final ModelAndView errorView = new ModelAndView();
        errorView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
        return errorView;
    }
    modelAndView.addObject("authenticationResponse", authenticationResponse);
    return modelAndView;
}
Also used : VerifyPassCodeFactorRequest(com.okta.authn.sdk.resource.VerifyPassCodeFactorRequest) AuthenticationException(com.okta.authn.sdk.AuthenticationException) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestContext(com.okta.authn.sdk.http.RequestContext) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AuthenticationException (com.okta.authn.sdk.AuthenticationException)8 AuthenticationResponse (com.okta.authn.sdk.resource.AuthenticationResponse)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 NonNull (androidx.annotation.NonNull)1 LDAPException (com.novell.ldap.LDAPException)1 RDN (com.novell.ldap.util.RDN)1 AuthenticationStateHandlerAdapter (com.okta.authn.sdk.AuthenticationStateHandlerAdapter)1 AuthenticationClient (com.okta.authn.sdk.client.AuthenticationClient)1 RequestContext (com.okta.authn.sdk.http.RequestContext)1 VerifyPassCodeFactorRequest (com.okta.authn.sdk.resource.VerifyPassCodeFactorRequest)1 RequestCallback (com.okta.oidc.RequestCallback)1 Result (com.okta.oidc.results.Result)1 AuthorizationException (com.okta.oidc.util.AuthorizationException)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 OktaTarget (com.tremolosecurity.unison.okta.provisioning.OktaTarget)1