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());
});
}
});
}
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;
}
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;
}
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;
}
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;
}
Aggregations