Handle UserAnonymizationEvent

This article describes how to use the mechanism of throwing an event of the User Anonymization.

First, you need to check a special box on the “Global changes” tab, like it is displayed on the screenshot below.

Then you should develop a special listener, that will be listening to such an event. You can find a small example of how it should be done here in the code example section.

import com.atlassian.event.api.EventListener; import com.atlassian.event.api.EventPublisher; import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Properties; @Slf4j @Component public class UserAnonymizerTestListener implements DisposableBean { @ComponentImport private final EventPublisher eventPublisher; @Autowired public UserAnonymizerTestListener(EventPublisher eventPublisher) { this.eventPublisher = eventPublisher; eventPublisher.register(this); } @Override public void destroy() throws Exception { eventPublisher.unregister(this); } @EventListener public void onUserAnonymizationEvent(Properties event) { String emitter = event.getProperty("emitter"); if (StringUtils.equals(emitter, "USER_ANONYMIZATION_EVENT")) { log.debug("Triggered USER_ANONYMIZATION_EVENT"); log.debug("source username = " + event.getProperty("sourceUsername")); log.debug("source displayName = " + event.getProperty("sourceDisplayName")); log.debug("source key = " + event.getProperty("sourceKey")); log.debug("source email = " + event.getProperty("sourceEmail")); log.debug("target username = " + event.getProperty("targetUsername")); log.debug("target displayName = " + event.getProperty("targetDisplayName")); log.debug("target key = " + event.getProperty("targetKey")); log.debug("target email = " + event.getProperty("targetEmail")); } } }

In this example, all fields just will be pushed of the event to the atlassian-confluence.log, if you will specify debug level for a listener class.

In order to do something special, you need to specify your code in the onUserAnonymizationEvent method. Make sure, that the name of the method can be different, but parameters should be exactly the same. It is very important, that you will have java.util.Properties class there.