use of com.okta.authn.sdk.AuthenticationException in project okta-auth-java by okta.
the class ForgotPasswordController method handleVerifyRecoveryTokenPost.
@RequestMapping(value = "/verify-recovery-token", method = RequestMethod.POST)
public ModelAndView handleVerifyRecoveryTokenPost(@RequestParam("recoveryToken") final String recoveryToken) {
final ModelAndView modelAndView = new ModelAndView("answer-sec-qn");
final AuthenticationResponse authenticationResponse;
try {
authenticationResponse = authenticationClient.verifyRecoveryToken(recoveryToken, ignoringStateHandler);
} catch (final AuthenticationException e) {
logger.error("Verify Recovery Token Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
final ModelAndView errorView = new ModelAndView("verify-recovery-token");
errorView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
return errorView;
}
final String stateToken = authenticationResponse.getStateToken();
final String secQn = authenticationResponse.getUser().getRecoveryQuestion().get("question");
logger.info("Verify Recovery Token Status: {}", authenticationResponse.getStatus());
modelAndView.addObject("stateToken", stateToken);
modelAndView.addObject("secQn", secQn);
return modelAndView;
}
use of com.okta.authn.sdk.AuthenticationException in project okta-auth-java by okta.
the class ForgotPasswordController method handleForgotPasswordPost.
@RequestMapping(value = "/forgot-password", method = RequestMethod.POST)
public ModelAndView handleForgotPasswordPost(@RequestParam("email") final String email) {
final ModelAndView modelAndView = new ModelAndView("verify-recovery-token");
AuthenticationResponse authenticationResponse;
try {
authenticationResponse = authenticationClient.recoverPassword(email, FactorType.EMAIL, null, ignoringStateHandler);
} catch (final AuthenticationException e) {
logger.error("Recover Password Error - Status: {}, Code: {}, Message: {}", e.getStatus(), e.getCode(), e.getMessage());
modelAndView.addObject("error", e.getStatus() + ":" + e.getCode() + ":" + e.getMessage());
return modelAndView;
}
logger.info("Recover Password Status: {}", authenticationResponse.getStatus());
return modelAndView;
}
use of com.okta.authn.sdk.AuthenticationException in project OpenUnison by TremoloSecurity.
the class OktaInsert method bind.
@Override
public void bind(BindInterceptorChain chain, DistinguishedName dn, Password pwd, LDAPConstraints constraints) throws LDAPException {
if (!this.users) {
throw new LDAPException("Unsupported", LDAPException.UNWILLING_TO_PERFORM, LDAPException.resultCodeToString(LDAPException.UNWILLING_TO_PERFORM));
}
RDN rdn = (RDN) dn.getDN().getRDNs().get(0);
if (!rdn.getType().equalsIgnoreCase("login")) {
throw new LDAPException("Unsupported", LDAPException.UNWILLING_TO_PERFORM, LDAPException.resultCodeToString(LDAPException.UNWILLING_TO_PERFORM));
}
String userid = rdn.getValue();
userid = userid.replace("\\+", "+");
OktaTarget os = null;
try {
os = (OktaTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.target).getProvider();
} catch (ProvisioningException e1) {
logger.error("Could not retrieve kubernetes target", e1);
throw new LDAPException("Could not connect to kubernetes", LDAPException.OPERATIONS_ERROR, LDAPException.resultCodeToString(LDAPException.OPERATIONS_ERROR));
}
AuthenticationClient client = AuthenticationClients.builder().setOrgUrl(os.getDomain()).build();
String pwdStr = new String(pwd.getValue());
LDAPException ldapRes;
try {
OktaAuthResponse authResp = new OktaAuthResponse(userid);
client.authenticate(userid, pwdStr.toCharArray(), "", authResp);
if (authResp.getResult() != null) {
throw authResp.getResult();
}
} catch (AuthenticationException e) {
if (e.getStatus() == 401) {
throw new LDAPException("Could not authenticate", LDAPException.INVALID_CREDENTIALS, LDAPException.resultCodeToString(LDAPException.INVALID_CREDENTIALS));
} else {
logger.error("Unexpected authenticaiton error", e);
throw new LDAPException("Unexpected authentication error", LDAPException.OPERATIONS_ERROR, LDAPException.resultCodeToString(LDAPException.OPERATIONS_ERROR));
}
}
}
Aggregations