Search in sources :

Example 1 with SmsProperties

use of org.apereo.cas.configuration.model.support.sms.SmsProperties 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 2 with SmsProperties

use of org.apereo.cas.configuration.model.support.sms.SmsProperties 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)

Example 3 with SmsProperties

use of org.apereo.cas.configuration.model.support.sms.SmsProperties 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 4 with SmsProperties

use of org.apereo.cas.configuration.model.support.sms.SmsProperties in project cas by apereo.

the class AuthenticationRiskTwilioSmsNotifier method publish.

@Override
public void publish() {
    final SmsProperties sms = casProperties.getAuthn().getAdaptive().getRisk().getResponse().getSms();
    final Principal principal = authentication.getPrincipal();
    if (StringUtils.isBlank(sms.getText()) || StringUtils.isBlank(sms.getFrom()) || !principal.getAttributes().containsKey(sms.getAttributeName())) {
        LOGGER.debug("Could not send sms [{}] because either no phones could be found or sms settings are not configured.", principal.getId());
        return;
    }
    communicationsManager.sms(sms.getFrom(), principal.getAttributes().get(sms.getAttributeName()).toString(), sms.getText());
}
Also used : SmsProperties(org.apereo.cas.configuration.model.support.sms.SmsProperties) Principal(org.apereo.cas.authentication.principal.Principal)

Aggregations

SmsProperties (org.apereo.cas.configuration.model.support.sms.SmsProperties)4 EmailProperties (org.apereo.cas.configuration.model.support.email.EmailProperties)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