Search in sources :

Example 1 with EmailProperties

use of org.apereo.cas.configuration.model.support.email.EmailProperties in project cas by apereo.

the class SurrogateAuthenticationEventListener method notify.

private void notify(final Principal principal, final AbstractCasEvent event) {
    final String eventDetails = event.toString();
    if (communicationsManager.isSmsSenderDefined()) {
        final SmsProperties sms = casProperties.getAuthn().getSurrogate().getSms();
        final String text = sms.getText().concat("\n").concat(eventDetails);
        communicationsManager.sms(sms.getFrom(), principal.getAttributes().get(sms.getAttributeName()).toString(), text);
    } else {
        LOGGER.trace("CAS is unable to send surrogate-authentication SMS messages given no settings are defined to account for servers, etc");
    }
    if (communicationsManager.isMailSenderDefined()) {
        final EmailProperties mail = casProperties.getAuthn().getSurrogate().getMail();
        final String emailAttribute = mail.getAttributeName();
        final Object to = principal.getAttributes().get(emailAttribute);
        if (to != null) {
            final String text = mail.getText().concat("\n").concat(eventDetails);
            this.communicationsManager.email(text, mail.getFrom(), mail.getSubject(), to.toString(), mail.getCc(), mail.getBcc());
        } else {
            LOGGER.trace("The principal has no {} attribute, cannot send email notification", emailAttribute);
        }
    } else {
        LOGGER.trace("CAS is unable to send surrogate-authentication email messages given no settings are defined to account for servers, etc");
    }
}
Also used : EmailProperties(org.apereo.cas.configuration.model.support.email.EmailProperties) SmsProperties(org.apereo.cas.configuration.model.support.sms.SmsProperties)

Example 2 with EmailProperties

use of org.apereo.cas.configuration.model.support.email.EmailProperties in project cas by apereo.

the class ElectronicFenceConfiguration method configureContingencyPlan.

private void configureContingencyPlan(final BaseAuthenticationRiskContingencyPlan b) {
    final EmailProperties mail = casProperties.getAuthn().getAdaptive().getRisk().getResponse().getMail();
    if (StringUtils.isNotBlank(mail.getText()) && StringUtils.isNotBlank(mail.getFrom()) && StringUtils.isNotBlank(mail.getSubject())) {
        b.getNotifiers().add(authenticationRiskEmailNotifier());
    }
    final SmsProperties sms = casProperties.getAuthn().getAdaptive().getRisk().getResponse().getSms();
    if (StringUtils.isNotBlank(sms.getText()) && StringUtils.isNotBlank(sms.getFrom())) {
        b.getNotifiers().add(authenticationRiskSmsNotifier());
    }
}
Also used : EmailProperties(org.apereo.cas.configuration.model.support.email.EmailProperties) SmsProperties(org.apereo.cas.configuration.model.support.sms.SmsProperties)

Example 3 with EmailProperties

use of org.apereo.cas.configuration.model.support.email.EmailProperties in project cas by apereo.

the class AuthenticationRiskEmailNotifier method publish.

@Override
public void publish() {
    final EmailProperties mail = casProperties.getAuthn().getAdaptive().getRisk().getResponse().getMail();
    final Principal principal = authentication.getPrincipal();
    if (!principal.getAttributes().containsKey(mail.getAttributeName())) {
        LOGGER.debug("Could not send email [{}] because either no addresses could be found or email settings are not configured.", principal.getId());
        return;
    }
    final String to = principal.getAttributes().get(mail.getAttributeName()).toString();
    this.communicationsManager.email(mail.getText(), mail.getFrom(), mail.getSubject(), to, mail.getCc(), mail.getBcc());
}
Also used : EmailProperties(org.apereo.cas.configuration.model.support.email.EmailProperties) Principal(org.apereo.cas.authentication.principal.Principal)

Example 4 with EmailProperties

use of org.apereo.cas.configuration.model.support.email.EmailProperties in project cas by apereo.

the class RegisteredServicesEventListener method handleRegisteredServiceExpiredEvent.

/**
 * Handle registered service expired event.
 *
 * @param event the event
 */
@EventListener
public void handleRegisteredServiceExpiredEvent(final CasRegisteredServiceExpiredEvent event) {
    final RegisteredService registeredService = event.getRegisteredService();
    final List<RegisteredServiceContact> contacts = registeredService.getContacts();
    final EmailProperties mail = casProperties.getServiceRegistry().getMail();
    final SmsProperties sms = casProperties.getServiceRegistry().getSms();
    final String serviceName = StringUtils.defaultIfBlank(registeredService.getName(), registeredService.getServiceId());
    if (communicationsManager.isMailSenderDefined()) {
        final String message = String.format(mail.getText(), serviceName);
        contacts.stream().filter(c -> StringUtils.isNotBlank(c.getEmail())).forEach(c -> communicationsManager.email(message, mail.getFrom(), mail.getSubject(), c.getEmail(), mail.getCc(), mail.getBcc()));
    }
    if (communicationsManager.isSmsSenderDefined()) {
        final String message = String.format(sms.getText(), serviceName);
        contacts.stream().filter(c -> StringUtils.isNotBlank(c.getPhone())).forEach(c -> communicationsManager.sms(sms.getFrom(), c.getPhone(), message));
    }
    servicesManager.load();
}
Also used : EmailProperties(org.apereo.cas.configuration.model.support.email.EmailProperties) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) CommunicationsManager(org.apereo.cas.util.io.CommunicationsManager) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) CasRegisteredServicesRefreshEvent(org.apereo.cas.support.events.service.CasRegisteredServicesRefreshEvent) SmsProperties(org.apereo.cas.configuration.model.support.sms.SmsProperties) EventListener(org.springframework.context.event.EventListener) EmailProperties(org.apereo.cas.configuration.model.support.email.EmailProperties) AllArgsConstructor(lombok.AllArgsConstructor) CasRegisteredServiceExpiredEvent(org.apereo.cas.support.events.service.CasRegisteredServiceExpiredEvent) StringUtils(org.apache.commons.lang3.StringUtils) SmsProperties(org.apereo.cas.configuration.model.support.sms.SmsProperties) EventListener(org.springframework.context.event.EventListener)

Aggregations

EmailProperties (org.apereo.cas.configuration.model.support.email.EmailProperties)4 SmsProperties (org.apereo.cas.configuration.model.support.sms.SmsProperties)3 List (java.util.List)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Principal (org.apereo.cas.authentication.principal.Principal)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 CasRegisteredServiceExpiredEvent (org.apereo.cas.support.events.service.CasRegisteredServiceExpiredEvent)1 CasRegisteredServicesRefreshEvent (org.apereo.cas.support.events.service.CasRegisteredServicesRefreshEvent)1 CommunicationsManager (org.apereo.cas.util.io.CommunicationsManager)1 EventListener (org.springframework.context.event.EventListener)1