Search in sources :

Example 6 with AuthenticationException

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;
}
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 7 with AuthenticationException

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;
}
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 8 with AuthenticationException

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));
        }
    }
}
Also used : LDAPException(com.novell.ldap.LDAPException) AuthenticationException(com.okta.authn.sdk.AuthenticationException) OktaTarget(com.tremolosecurity.unison.okta.provisioning.OktaTarget) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) AuthenticationClient(com.okta.authn.sdk.client.AuthenticationClient) RDN(com.novell.ldap.util.RDN)

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