Search in sources :

Example 1 with AuthenticationResponse

use of com.okta.authn.sdk.resource.AuthenticationResponse 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 AuthenticationResponse

use of com.okta.authn.sdk.resource.AuthenticationResponse 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 AuthenticationResponse

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

the class AuthHelper method proceedToVerifyView.

public static ModelAndView proceedToVerifyView(final AuthenticationResponse authenticationResponse, final AuthenticationClient authenticationClient, final AuthenticationStateHandler ignoringStateHandler) throws AuthenticationException {
    final String factorId = authenticationResponse.getFactors().get(0).getId();
    final FactorType factorType = authenticationResponse.getFactors().get(0).getType();
    final String stateToken = authenticationResponse.getStateToken();
    // we only support Email factor for sample purpose
    if (factorType == FactorType.EMAIL) {
        AuthenticationResponse authResponse = authenticationClient.verifyFactor(factorId, stateToken, ignoringStateHandler);
        final ModelAndView emailAuthView = new ModelAndView("verify-email-authenticator");
        emailAuthView.addObject("authenticationResponse", authResponse);
        return emailAuthView;
    } else {
        final ModelAndView errorView = new ModelAndView("home");
        errorView.addObject("error", "Factor type " + factorType + " + is not supported in this sample yet");
        return errorView;
    }
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FactorType(com.okta.authn.sdk.resource.FactorType) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse)

Example 4 with AuthenticationResponse

use of com.okta.authn.sdk.resource.AuthenticationResponse 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 5 with AuthenticationResponse

use of com.okta.authn.sdk.resource.AuthenticationResponse 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)

Aggregations

AuthenticationResponse (com.okta.authn.sdk.resource.AuthenticationResponse)29 Path (javax.ws.rs.Path)9 Test (org.junit.Test)9 User (com.okta.authn.sdk.resource.User)8 AuthResponse (com.nike.cerberus.auth.connector.AuthResponse)7 AuthStatus (com.nike.cerberus.auth.connector.AuthStatus)7 AuthenticationException (com.okta.authn.sdk.AuthenticationException)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 ExampleAuthenticationStateHandler (com.okta.authn.sdk.example.ExampleAuthenticationStateHandler)6 POST (javax.ws.rs.POST)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 MfaVerifyView (com.okta.authn.sdk.example.views.authn.MfaVerifyView)3 FactorType (com.okta.authn.sdk.resource.FactorType)3 GET (javax.ws.rs.GET)3 DefaultFactor (com.okta.authn.sdk.impl.resource.DefaultFactor)2 FactorProvider (com.okta.authn.sdk.resource.FactorProvider)2 NonNull (androidx.annotation.NonNull)1 AuthenticationStateHandlerAdapter (com.okta.authn.sdk.AuthenticationStateHandlerAdapter)1 PasswordRecoveryView (com.okta.authn.sdk.example.views.authn.PasswordRecoveryView)1 RecoveryView (com.okta.authn.sdk.example.views.authn.RecoveryView)1