Search in sources :

Example 26 with AuthLoginException

use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.

the class AuthenticatorOATH method getAuthenticatorAppRegistrationUri.

private String getAuthenticatorAppRegistrationUri(OathDeviceSettings settings, AMIdentity id) throws AuthLoginException, IOException {
    //check settings aren't null
    if (settings == null) {
        debug.error("OATH.checkOTP() : Invalid settings discovered.");
        throw new AuthLoginException(amAuthOATH, "authFailed", null);
    }
    final AuthenticatorAppRegistrationURIBuilder builder = new AuthenticatorAppRegistrationURIBuilder(id, settings.getSharedSecret(), passLen, issuerName);
    int algorithm = this.algorithm;
    try {
        if (algorithm == HOTP) {
            int counter = settings.getCounter();
            return builder.getAuthenticatorAppRegistrationUriForHOTP(counter);
        } else if (algorithm == TOTP) {
            return builder.getAuthenticatorAppRegistrationUriForTOTP(totpTimeStep);
        } else {
            debug.error("OATH .checkOTP() : No OTP algorithm selected");
            throw new AuthLoginException(amAuthOATH, "authFailed", null);
        }
    } catch (DecoderException de) {
        debug.error("OATH .getCreateQRDomElementJS() : Could not decode secret key from hex to plain text", de);
        throw new AuthLoginException(amAuthOATH, "authFailed", null);
    }
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException)

Example 27 with AuthLoginException

use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.

the class AuthenticatorOATH method createQRCodeCallback.

/**
    * There is a hack here to reverse a hack in RESTLoginView.js. Implementing the code properly in RESTLoginView.js so
    * as to remove this hack will take too long at present, and stands in the way of completion of this module's
    * QR code additions. I have opted to simply reverse the hack in this singular case.
    *
    * In the below code returning the ScriptTextOutputCallback, the String used in its construction is
    * defined as follows:
     *
    * createQRDomElementJS
    *           Adds the DOM element, in this case a div, in which the QR code will appear.
    * QRCodeGenerationUtilityFunctions.
    *   getQRCodeGenerationJavascriptForAuthenticatorAppRegistration(authenticatorAppRegistrationUri)
    *           Adds a specific call to the Javascript library code, sending the app registration url as the
    *           text to encode as a QR code. This QR code will then appear in the previously defined DOM
    *           element (which must have an id of 'qr').
    * hideButtonHack
    *           A hack to reverse a hack in RESTLoginView.js. See more detailed comment above.*
    */
private Callback createQRCodeCallback(OathDeviceSettings settings, AMIdentity id, int callbackIndex) throws AuthLoginException {
    try {
        final String authenticatorAppRegistrationUri = getAuthenticatorAppRegistrationUri(settings, id);
        final String callback = "callback_" + callbackIndex;
        return new ScriptTextOutputCallback(GenerationUtils.getQRCodeGenerationJavascriptForAuthenticatorAppRegistration(callback, authenticatorAppRegistrationUri));
    } catch (IOException e) {
        throw new AuthLoginException(amAuthOATH, "authFailed", null);
    }
}
Also used : AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) IOException(java.io.IOException)

Example 28 with AuthLoginException

use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.

the class HOTPService method sendHOTP.

/**
     * Sends the otp code to the users telephone number and/or email address, based on the authentication module's
     * configuration settings.
     *
     * @param otpCode The OTP code to send.
     * @param subject The subject of the message.
     * @param message The body of the message.
     * @throws AuthLoginException If there is a problem sending the OTP code.
     */
private void sendHOTP(String otpCode, String subject, String message) throws AuthLoginException {
    Exception cause = null;
    try {
        AMIdentity identity = getIdentity();
        if (identity == null) {
            throw new AuthLoginException("HOTP.sendSMS() : Unable to send OTP code " + "because of error searching identities with username : " + userName);
        }
        String phone = getTelephoneNumber(identity);
        String mail = getEmailAddress(identity);
        boolean delivered = false;
        if (phone != null || mail != null) {
            String from = CollectionHelper.getMapAttr(currentConfig, fromAddressAttributeName);
            SMSGateway gateway = Class.forName(gatewaySMSImplClass).asSubclass(SMSGateway.class).newInstance();
            if (codeDelivery.equals("SMS and E-mail")) {
                try {
                    if (phone != null) {
                        gateway.sendSMSMessage(from, phone, subject, message, otpCode, currentConfig);
                        delivered = true;
                    }
                } catch (AuthLoginException ale) {
                    DEBUG.error("Error while sending HOTP code to user via SMS", ale);
                    cause = ale;
                }
                try {
                    if (mail != null) {
                        gateway.sendEmail(from, mail, subject, message, otpCode, currentConfig);
                        delivered = true;
                    }
                } catch (AuthLoginException ale) {
                    DEBUG.error("Error while sending HOTP code to user via e-mail", ale);
                    cause = ale;
                }
                if (!delivered && cause != null) {
                    throw cause;
                }
            } else if (codeDelivery.equals("SMS")) {
                gateway.sendSMSMessage(from, phone, subject, message, otpCode, currentConfig);
            } else if (codeDelivery.equals("E-mail")) {
                gateway.sendEmail(from, mail, subject, message, otpCode, currentConfig);
            }
        } else {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("HOTP.sendSMS() : IdRepo: no phone or email found with username : " + userName);
            }
            throw new AuthLoginException("HOTP.sendSMS() : Unable to send OTP code " + "because no phone or e-mail found for user: " + userName);
        }
    } catch (ClassNotFoundException ee) {
        DEBUG.error("HOTP.sendSMS() : " + "class not found SMSGateway class", ee);
        cause = ee;
    } catch (InstantiationException ie) {
        DEBUG.error("HOTP.sendSMS() : " + "can not instantiate SMSGateway class", ie);
        cause = ie;
    } catch (IdRepoException e) {
        DEBUG.error("HOTP.sendSMS() : error searching Identities with username : " + userName, e);
        cause = e;
    } catch (AuthLoginException e) {
        throw e;
    } catch (Exception e) {
        DEBUG.error("HOTP.sendSMS() : HOTP module exception : ", e);
        cause = e;
    }
    if (cause != null) {
        throw new AuthLoginException("HOTP.sendSMS() : Unable to send OTP code", cause);
    }
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) IdRepoException(com.sun.identity.idm.IdRepoException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) IdRepoException(com.sun.identity.idm.IdRepoException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SSOException(com.iplanet.sso.SSOException) InvalidKeyException(java.security.InvalidKeyException)

Example 29 with AuthLoginException

use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.

the class DefaultSMSGatewayImpl method sendSMSMessage.

/**
     * {@inheritDoc}
     */
public void sendSMSMessage(String from, String to, String subject, String message, String code, Map options) throws AuthLoginException {
    if (to == null) {
        return;
    }
    try {
        setOptions(options);
        String msg = message + code;
        String[] tos = new String[1];
        // <phone@provider_address). For exampe : 4080989109@txt.att.net
        if (to.indexOf("@") == -1) {
            to = to + "@txt.att.net";
        }
        tos[0] = to;
        AMSendMail sendMail = new AMSendMail();
        if (smtpHostName == null || smtpHostPort == null) {
            sendMail.postMail(tos, subject, msg, from);
        } else {
            sendMail.postMail(tos, subject, msg, from, "UTF-8", smtpHostName, smtpHostPort, smtpUserName, smtpUserPassword, sslEnabled);
        }
        if (debug.messageEnabled()) {
            debug.message("DefaultSMSGatewayImpl.sendSMSMessage() : " + "HOTP sent to : " + to + ".");
        }
    } catch (Exception e) {
        debug.error("DefaultSMSGatewayImpl.sendSMSMessage() : " + "Exception in sending HOTP code : ", e);
        throw new AuthLoginException("Failed to send OTP code to " + to, e);
    }
}
Also used : AMSendMail(com.iplanet.am.util.AMSendMail) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException)

Example 30 with AuthLoginException

use of com.sun.identity.authentication.spi.AuthLoginException in project OpenAM by OpenRock.

the class HOTPService method sendHOTP.

/**
     * Sends a otp code to the users telephone number and/or email address, based on the authentication module's
     * configuration settings.
     *
     * @throws AuthLoginException If there is a problem sending the OTP code.
     */
public void sendHOTP() throws AuthLoginException {
    try {
        sentHOTPCode = HOTPAlgorithm.generateOTP(getSharedSecret(), getMovingFactor(), codeLength, false, 16);
    } catch (NoSuchAlgorithmException e) {
        DEBUG.error("HOTP.sendHOTPCode() : " + "no such algorithm", e);
        throw new AuthLoginException("amAuth", "noSuchAlgorithm", null);
    } catch (InvalidKeyException e) {
        DEBUG.error("HOTP.sendHOTPCode() : " + "invalid key", e);
        throw new AuthLoginException("amAuth", "invalidKey", null);
    }
    sendHOTP(sentHOTPCode, messageSubject, messageContent);
    sentHOTPCodeTime = System.currentTimeMillis();
}
Also used : AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)118 SSOException (com.iplanet.sso.SSOException)39 Callback (javax.security.auth.callback.Callback)29 IdRepoException (com.sun.identity.idm.IdRepoException)27 InvalidPasswordException (com.sun.identity.authentication.spi.InvalidPasswordException)25 NameCallback (javax.security.auth.callback.NameCallback)24 PasswordCallback (javax.security.auth.callback.PasswordCallback)23 IOException (java.io.IOException)20 Set (java.util.Set)18 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 SSOToken (com.iplanet.sso.SSOToken)14 HashMap (java.util.HashMap)14 AuthContext (com.sun.identity.authentication.AuthContext)13 Map (java.util.Map)12 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)12 Test (org.testng.annotations.Test)12 HashSet (java.util.HashSet)9 LoginException (javax.security.auth.login.LoginException)8 SSOTokenManager (com.iplanet.sso.SSOTokenManager)7 AuthException (com.sun.identity.authentication.service.AuthException)7