Class ActivitiesUnsubscribeService

java.lang.Object
fr.becpg.repo.activity.unsubscribe.ActivitiesUnsubscribeService
All Implemented Interfaces:
Function<String,String>

@Service("activitiesUnsubscribeService") public class ActivitiesUnsubscribeService extends Object implements Function<String,String>
One-click unsubscribe from the activity emails (RFC 8058).

Gives the email notifier the unsubscribe URL of each recipient, as a Function so that the patched Alfresco notifier needs no beCPG class, and disables the activity emails of the user designated by a valid token.

The secret key of the instance is created on the first email sent, in a transaction of its own, and stored as a repository attribute, so that it survives restarts and is shared by every node of a cluster. Reading a token never creates it: an anonymous request cannot write anything but the activity email setting of the user designated by a valid token.

Thread-safe: the key is cached in a volatile field once read.

Author:
valentin
  • Field Details

    • logger

      private static final org.apache.commons.logging.Log logger
    • KEY_ATTRIBUTE

      static final String KEY_ATTRIBUTE
      Repository attribute holding the Base64 secret key of the instance.
      See Also:
    • UNSUBSCRIBE_PATH

      static final String UNSUBSCRIBE_PATH
      Path of the unsubscribe webscript through the unauthenticated proxy of Share, relative to the Share URL: Share is the URL every user can reach, whereas the repository is often not exposed.
      See Also:
    • KEY_LENGTH

      private static final int KEY_LENGTH
      See Also:
    • RANDOM

      private static final SecureRandom RANDOM
    • attributeService

      @Autowired private org.alfresco.service.cmr.attributes.AttributeService attributeService
    • nodeService

      @Autowired private org.alfresco.service.cmr.repository.NodeService nodeService
    • personService

      @Autowired private org.alfresco.service.cmr.security.PersonService personService
    • sysAdminParams

      @Autowired private org.alfresco.repo.admin.SysAdminParams sysAdminParams
    • tenantAdminService

      @Autowired private org.alfresco.repo.tenant.TenantAdminService tenantAdminService
    • transactionService

      @Autowired private org.alfresco.service.transaction.TransactionService transactionService
    • cachedKey

      private volatile byte[] cachedKey
  • Constructor Details

    • ActivitiesUnsubscribeService

      public ActivitiesUnsubscribeService()
  • Method Details

    • apply

      public String apply(String userName)
      Builds the unsubscribe URL of a user.
      Specified by:
      apply in interface Function<String,String>
      Parameters:
      userName - the recipient of the activity email
      Returns:
      the absolute unsubscribe URL
    • unsubscribe

      public void unsubscribe(String token)
      Disables the activity emails of the user designated by the token. An invalid, expired or unknown token changes nothing and raises nothing, so that the caller cannot tell the cases apart.
      Parameters:
      token - the token of the unsubscribe link
    • disableActivityEmails

      private void disableActivityEmails(String userName)
    • tenantDomainOf

      private String tenantDomainOf(String userName)
    • codec

      private UnsubscribeTokenCodec codec(byte[] key)
    • readStoredKey

      private Optional<byte[]> readStoredKey()
    • createKey

      private byte[] createKey()
      Creates the key of the instance in a transaction of its own, committed before any token is signed with it: a rollback of the caller transaction must not leave emails signed with a key that was never stored.