Class ActivitiesUnsubscribeService
java.lang.Object
fr.becpg.repo.activity.unsubscribe.ActivitiesUnsubscribeService
@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 Summary
FieldsModifier and TypeFieldDescriptionprivate org.alfresco.service.cmr.attributes.AttributeServiceprivate byte[](package private) static final StringRepository attribute holding the Base64 secret key of the instance.private static final intprivate static final org.apache.commons.logging.Logprivate org.alfresco.service.cmr.repository.NodeServiceprivate org.alfresco.service.cmr.security.PersonServiceprivate static final SecureRandomprivate org.alfresco.repo.admin.SysAdminParamsprivate org.alfresco.repo.tenant.TenantAdminServiceprivate org.alfresco.service.transaction.TransactionService(package private) static final StringPath 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. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBuilds the unsubscribe URL of a user.private UnsubscribeTokenCodeccodec(byte[] key) private byte[]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.private voiddisableActivityEmails(String userName) private Optional<byte[]> private StringtenantDomainOf(String userName) voidunsubscribe(String token) Disables the activity emails of the user designated by the token.
-
Field Details
-
logger
private static final org.apache.commons.logging.Log logger -
KEY_ATTRIBUTE
Repository attribute holding the Base64 secret key of the instance.- See Also:
-
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
-
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
Builds the unsubscribe URL of a user. -
unsubscribe
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
-
tenantDomainOf
-
codec
-
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.
-