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