Search in sources :

Example 76 with MessagingException

use of javax.mail.MessagingException in project nhin-d by DirectProject.

the class DefaultNHINDAgent_ProcessOutgoingMessage_Test method testMessageIsWrapped_WrapMessageIsNotCalled.

/**
	 * 
	 * @throws Exception
	 */
public void testMessageIsWrapped_WrapMessageIsNotCalled() throws Exception {
    new TestPlan() {

        protected OutgoingMessage createMessage() throws Exception {
            MimeMessage mimeMsg = new SecondaryMimeMessage();
            mimeMsg.setText("");
            Message msg = new Message(mimeMsg) {

                @Override
                public String getContentType() throws MessagingException {
                    return MailStandard.MediaType.WrappedMessage;
                }
            };
            NHINDAddressCollection recipients = new NHINDAddressCollection();
            recipients.add(new NHINDAddress(""));
            NHINDAddress sender = new NHINDAddress("");
            theCreateMessage = new OutgoingMessage(msg, recipients, sender) {

                @Override
                protected void categorizeRecipients(TrustEnforcementStatus minTrustStatus) {
                    categorizeRecipientsCalls++;
                    categorizeRecipients_Internal(minTrustStatus);
                }
            };
            return theCreateMessage;
        }

        protected void doAssertions() throws Exception {
            assertEquals(0, wrapMessageCalls);
        }
    }.perform();
}
Also used : TrustEnforcementStatus(org.nhindirect.stagent.trust.TrustEnforcementStatus) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) BaseTestPlan(org.nhindirect.stagent.utils.BaseTestPlan) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) SecondaryMimeMessage(org.nhindirect.stagent.utils.SecondaryMimeMessage) MessagingException(javax.mail.MessagingException)

Example 77 with MessagingException

use of javax.mail.MessagingException in project nhin-d by DirectProject.

the class SMIMECryptographerImpl method decrypt.

/**
     * Decrypts an entity with the provided certificates' private key.
     * @param encryptedEntity The entity that will be decrypted.
     * @param decryptingCertificate The certificates whose private keys will be used to decrypt the message.
     * @return A MimeEntity containing the decrypted part.
     */
public MimeEntity decrypt(MimeEntity encryptedEntity, Collection<X509CertificateEx> decryptingCertificates) {
    if (decryptingCertificates == null || decryptingCertificates.size() == 0) {
        throw new IllegalArgumentException();
    }
    MimeEntity retEntity = null;
    try {
        if (LOGGER.isDebugEnabled()) {
            final byte[] encryptedContent = encryptedEntity.getContentAsBytes();
            writePreDecrypt(encryptedContent);
        }
        final SMIMEEnveloped m = new SMIMEEnveloped(encryptedEntity);
        if (!this.isAllowedEncryptionAlgorithm(m.getEncryptionAlgOID()))
            throw new NHINDException(MimeError.DisallowedEncryptionAlgorithm, "The encryption algorithm " + m.getEncryptionAlgOID() + " is not allowed");
        for (X509CertificateEx decryptCert : decryptingCertificates) {
            final RecipientId recId = generateRecipientSelector(decryptCert);
            final RecipientInformationStore recipients = m.getRecipientInfos();
            final DirectRecipientInformation recipient = decFactory.createInstance(recipients.get(recId), m);
            if (recipient == null)
                continue;
            final byte[] decryptedPayload = recipient.getDecryptedContent(decryptCert.getPrivateKey());
            if (LOGGER.isDebugEnabled()) {
                writePostDecrypt(decryptedPayload);
            }
            final ByteArrayInputStream inStream = new ByteArrayInputStream(decryptedPayload);
            retEntity = new MimeEntity(inStream);
            break;
        }
    } catch (MessagingException e) {
        throw new MimeException(MimeError.InvalidMimeEntity, e);
    } catch (Exception e) {
        throw new MimeException(MimeError.Unexpected, e);
    }
    if (retEntity == null) {
        throw new NHINDException(MimeError.Unexpected, "None of the the provided decryption certs were found in message's RecipientsInfo set.");
    }
    return retEntity;
}
Also used : RecipientId(org.bouncycastle.cms.RecipientId) MessagingException(javax.mail.MessagingException) DirectRecipientInformation(org.nhindirect.stagent.cryptography.activekeyops.DirectRecipientInformation) SMIMEEnveloped(org.bouncycastle.mail.smime.SMIMEEnveloped) NHINDException(org.nhindirect.stagent.NHINDException) MessagingException(javax.mail.MessagingException) MimeException(org.nhindirect.stagent.mail.MimeException) NHINDException(org.nhindirect.stagent.NHINDException) ParseException(javax.mail.internet.ParseException) IOException(java.io.IOException) SignatureValidationException(org.nhindirect.stagent.SignatureValidationException) X509CertificateEx(org.nhindirect.stagent.cert.X509CertificateEx) ByteArrayInputStream(java.io.ByteArrayInputStream) MimeEntity(org.nhindirect.stagent.mail.MimeEntity) RecipientInformationStore(org.bouncycastle.cms.RecipientInformationStore) MimeException(org.nhindirect.stagent.mail.MimeException)

Example 78 with MessagingException

use of javax.mail.MessagingException in project nhin-d by DirectProject.

the class Notification method getInputStream.

/**
	 * Gets an input stream of this notification that can be serialized.
	 * @return An input stream of this notification
	 */
public InputStream getInputStream() {
    if (report == null)
        updateReport();
    ByteArrayOutputStream oStream = null;
    try {
        oStream = new ByteArrayOutputStream();
        report.writeTo(oStream);
        oStream.flush();
    } catch (MessagingException e) {
    } catch (IOException e) {
    }
    return new ByteArrayInputStream(oStream.toByteArray());
}
Also used : MessagingException(javax.mail.MessagingException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 79 with MessagingException

use of javax.mail.MessagingException in project OpenAM by OpenRock.

the class IdentityResourceV2 method sendNotification.

/**
     * Sends email notification to end user
     * @param to Resource receiving notification
     * @param subject Notification subject
     * @param message Notification Message
     * @param confirmationLink Confirmation Link to be sent
     * @throws Exception when message cannot be sent
     */
private void sendNotification(String to, String subject, String message, String realm, String confirmationLink) throws ResourceException {
    try {
        mailmgr = new ServiceConfigManager(RestUtils.getToken(), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
        mailscm = mailmgr.getOrganizationConfig(realm, null);
        mailattrs = mailscm.getAttributes();
    } catch (SMSException smse) {
        if (debug.errorEnabled()) {
            debug.error("{} :: Cannot create service {}", SEND_NOTIF_TAG, MailServerImpl.SERVICE_NAME, smse);
        }
        throw new InternalServerErrorException("Cannot create the service: " + MailServerImpl.SERVICE_NAME, smse);
    } catch (SSOException ssoe) {
        if (debug.errorEnabled()) {
            debug.error("{} :: Invalid SSOToken ", SEND_NOTIF_TAG, ssoe);
        }
        throw new InternalServerErrorException("Cannot create the service: " + MailServerImpl.SERVICE_NAME, ssoe);
    }
    if (mailattrs == null || mailattrs.isEmpty()) {
        if (debug.errorEnabled()) {
            debug.error("{} :: no attrs set {}", SEND_NOTIF_TAG, mailattrs);
        }
        throw new NotFoundException("No service Config Manager found for realm " + realm);
    }
    // Get MailServer Implementation class
    String attr = mailattrs.get(MAIL_IMPL_CLASS).iterator().next();
    MailServer mailServer;
    try {
        mailServer = mailServerLoader.load(attr, realm);
    } catch (IllegalStateException e) {
        debug.error("{} :: Failed to load mail server implementation: {}", SEND_NOTIF_TAG, attr, e);
        throw new InternalServerErrorException("Failed to load mail server implementation: " + attr, e);
    }
    try {
        // Check if subject has not  been included
        if (StringUtils.isBlank(subject)) {
            // Use default email service subject
            subject = mailattrs.get(MAIL_SUBJECT).iterator().next();
        }
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("{} no subject found ", SEND_NOTIF_TAG, e);
        }
        subject = "";
    }
    try {
        // Check if Custom Message has been included
        if (StringUtils.isBlank(message)) {
            // Use default email service message
            message = mailattrs.get(MAIL_MESSAGE).iterator().next();
        }
        message = message + System.getProperty("line.separator") + confirmationLink;
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("{} no message found", SEND_NOTIF_TAG, e);
        }
        message = confirmationLink;
    }
    // Send the emails via the implementation class
    try {
        mailServer.sendEmail(to, subject, message);
    } catch (MessagingException e) {
        if (debug.errorEnabled()) {
            debug.error("{} Failed to send mail", SEND_NOTIF_TAG, e);
        }
        throw new InternalServerErrorException("Failed to send mail", e);
    }
}
Also used : MailServer(org.forgerock.openam.services.email.MailServer) SMSException(com.sun.identity.sm.SMSException) MessagingException(javax.mail.MessagingException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) MessagingException(javax.mail.MessagingException) ConflictException(org.forgerock.json.resource.ConflictException) PermanentException(org.forgerock.json.resource.PermanentException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ForbiddenException(org.forgerock.json.resource.ForbiddenException) DeleteFailedException(org.forgerock.openam.cts.exceptions.DeleteFailedException) SSOException(com.iplanet.sso.SSOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NotFoundException(org.forgerock.json.resource.NotFoundException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) BadRequestException(org.forgerock.json.resource.BadRequestException) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) ResourceException(org.forgerock.json.resource.ResourceException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 80 with MessagingException

use of javax.mail.MessagingException in project OpenAM by OpenRock.

the class IdentityResourceV1 method sendNotification.

/**
     * Sends email notification to end user
     * @param to Resource receiving notification
     * @param subject Notification subject
     * @param message Notification Message
     * @param confirmationLink Confirmation Link to be sent
     * @throws Exception when message cannot be sent
     */
private void sendNotification(String to, String subject, String message, String realm, String confirmationLink) throws ResourceException {
    try {
        mailmgr = new ServiceConfigManager(RestUtils.getToken(), MailServerImpl.SERVICE_NAME, MailServerImpl.SERVICE_VERSION);
        mailscm = mailmgr.getOrganizationConfig(realm, null);
        mailattrs = mailscm.getAttributes();
    } catch (SMSException smse) {
        if (debug.errorEnabled()) {
            debug.error("{} :: Cannot create service {}", SEND_NOTIF_TAG, MailServerImpl.SERVICE_NAME, smse);
        }
        throw new InternalServerErrorException("Cannot create the service: " + MailServerImpl.SERVICE_NAME, smse);
    } catch (SSOException ssoe) {
        if (debug.errorEnabled()) {
            debug.error("{} :: Invalid SSOToken ", SEND_NOTIF_TAG, ssoe);
        }
        throw new InternalServerErrorException("Cannot create the service: " + MailServerImpl.SERVICE_NAME, ssoe);
    }
    if (mailattrs == null || mailattrs.isEmpty()) {
        if (debug.errorEnabled()) {
            debug.error("{} :: no attrs set {}", SEND_NOTIF_TAG, mailattrs);
        }
        throw new NotFoundException("No service Config Manager found for realm " + realm);
    }
    // Get MailServer Implementation class
    String attr = mailattrs.get(MAIL_IMPL_CLASS).iterator().next();
    MailServer mailServer;
    try {
        mailServer = mailServerLoader.load(attr, realm);
    } catch (IllegalStateException e) {
        debug.error("{} :: Failed to load mail server implementation: {}", SEND_NOTIF_TAG, attr, e);
        throw new InternalServerErrorException("Failed to load mail server implementation: " + attr, e);
    }
    try {
        // Check if subject has not  been included
        if (StringUtils.isBlank(subject)) {
            // Use default email service subject
            subject = mailattrs.get(MAIL_SUBJECT).iterator().next();
        }
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("{} no subject found ", SEND_NOTIF_TAG, e);
        }
        subject = "";
    }
    try {
        // Check if Custom Message has been included
        if (StringUtils.isBlank(message)) {
            // Use default email service message
            message = mailattrs.get(MAIL_MESSAGE).iterator().next();
        }
        message = message + System.getProperty("line.separator") + confirmationLink;
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("{} no message found", SEND_NOTIF_TAG, e);
        }
        message = confirmationLink;
    }
    // Send the emails via the implementation class
    try {
        mailServer.sendEmail(to, subject, message);
    } catch (MessagingException e) {
        if (debug.errorEnabled()) {
            debug.error("{} Failed to send mail", SEND_NOTIF_TAG, e);
        }
        throw new InternalServerErrorException("Failed to send mail", e);
    }
}
Also used : MailServer(org.forgerock.openam.services.email.MailServer) SMSException(com.sun.identity.sm.SMSException) MessagingException(javax.mail.MessagingException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) DeleteFailedException(org.forgerock.openam.cts.exceptions.DeleteFailedException) SSOException(com.iplanet.sso.SSOException) NotFoundException(org.forgerock.json.resource.NotFoundException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) BadRequestException(org.forgerock.json.resource.BadRequestException) MessagingException(javax.mail.MessagingException) ConflictException(org.forgerock.json.resource.ConflictException) PermanentException(org.forgerock.json.resource.PermanentException) ForbiddenException(org.forgerock.json.resource.ForbiddenException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) IdRepoException(com.sun.identity.idm.IdRepoException) SMSException(com.sun.identity.sm.SMSException) ResourceException(org.forgerock.json.resource.ResourceException) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Aggregations

MessagingException (javax.mail.MessagingException)343 MimeMessage (javax.mail.internet.MimeMessage)135 IOException (java.io.IOException)126 InternetAddress (javax.mail.internet.InternetAddress)70 MimeMultipart (javax.mail.internet.MimeMultipart)64 MimeBodyPart (javax.mail.internet.MimeBodyPart)63 Message (javax.mail.Message)49 Properties (java.util.Properties)45 Session (javax.mail.Session)45 InputStream (java.io.InputStream)43 Date (java.util.Date)34 Address (javax.mail.Address)33 PackageException (com.axway.ats.action.objects.model.PackageException)32 ArrayList (java.util.ArrayList)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PublicAtsApi (com.axway.ats.common.PublicAtsApi)31 ServiceException (com.zimbra.common.service.ServiceException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)26 DataHandler (javax.activation.DataHandler)25 UnsupportedEncodingException (java.io.UnsupportedEncodingException)24