Written by
  • email
  • twitter
  • linkedin
  • linkedin

Apache Syncope can be instructed to send out notification e-mails when certain events occur.

In this post, we provide two examples to send notification: one while creating a new user (predefined event), and the other while executing a custom task.

Notification for predefined events

First, we need to create a new template, from Configuration -> Notifications, choose the Templates tab and click on add button
notification1

After creating the new template, you can customize this template for plain-text and HTML e-mails
notification2  notification3

Then, from Notifications tab, add a new notification as follows:
notification4  notification5  notification6

Notification for non-predefined events

Custom events can be used to trigger notifications from non-predefined joint points.
Here, we are going to define a simple custom task, the logic behind it is just to find a specific user and send a notification.
To create a new custom task, the implementation can be done either by Java or Groovy; in the case of Java, it is required to add a new class as the example below:

public class NewSchedTask extends AbstractSchedTaskJobDelegate {
    @Autowired
    private UserDataBinder userDataBinder;

    @Autowired
    private UserDAO userDAO;

    @Override
    protected String doExecute(boolean bln) throws JobExecutionException {
        final User user = userDAO.findByUsername("newUser");
        final UserTO userTO = userDataBinder.getUserTO(user, false);
        LOG.info("Send notification after excuting New Task");
        notificationManager.createTasks(AuditElements.EventCategoryType.CUSTOM,
                null,
                null,
                "excuteNewTask",
                AuditElements.Result.SUCCESS,
                userTO,
                null,
                (Object) null);
        return "SUCCESS";
    }
}

Then from Configuration -> Implementations, TASKJOB_DELEGATE tab, click on add button, then choose:

  1. Java, and in this case, choose the class that you implemented before  notification7
  2. Groovy, add the implementation of the class  notification8

Now follow the same steps as before to create the template, and then add a new notification taking into consideration the following different configuration:
notification9  notification10

NOTE: e-mail configuration is needed in order to fully complete the two examples before and effectively deliver the notification  e-mails.

6 VOTIGoodGood
Ti è stato utile questo articolo?
From Tirasa's Blog
The place where we share what we do, learn and discover day by day.
Go to blog >