-
-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XWIKI-20371: Consider mail obfuscation settings in the Solr indexer
* Introduce a new event GeneralMailConfigurationUpdatedEvent to notify the indexer when the mail configuration changed. * Don't index emails when obfuscation is enabled. * Add a test for the object property metadata extractor. * Add a migration to clear the index. * Make sure that indexing is executed with the indexed document in context.
- Loading branch information
Showing
17 changed files
with
995 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...-platform-mail-api/src/main/java/org/xwiki/mail/GeneralMailConfigurationUpdatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.mail; | ||
|
||
import java.util.Objects; | ||
|
||
import org.apache.commons.lang3.builder.EqualsBuilder; | ||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
import org.xwiki.observation.event.Event; | ||
import org.xwiki.stability.Unstable; | ||
|
||
/** | ||
* An event triggered after the general mail configuration has been changed. | ||
* <p> | ||
* The event also sends the following parameters: | ||
* </p> | ||
* <ul> | ||
* <li>source: the wiki id (as string) where the configuration has been changed, or {@code null} if the change was on | ||
* the main wiki and thus affects all wikis.</li> | ||
* <li>data: {@code null}</li> | ||
* </ul> | ||
* <p>This event is intentionally not serializable as it will be triggered on every node of the cluster separately.</p> | ||
* | ||
* @since 14.10.15 | ||
* @since 15.5.2 | ||
* @since 15.7RC1 | ||
* @version $Id$ | ||
*/ | ||
@Unstable | ||
public class GeneralMailConfigurationUpdatedEvent implements Event | ||
{ | ||
private String wikiId; | ||
|
||
/** | ||
* Default constructor, used to get notified about a mail configuration change in any wiki or to trigger an event | ||
* for a configuration change on the main wiki. | ||
*/ | ||
public GeneralMailConfigurationUpdatedEvent() | ||
{ | ||
} | ||
|
||
/** | ||
* An event for changes that affect the passed wiki id. Used to get notified about a change that affects the | ||
* specified wiki or to trigger an event on a subwiki. | ||
* | ||
* @param wikiId the id of the wiki where the configuration has been changed | ||
*/ | ||
public GeneralMailConfigurationUpdatedEvent(String wikiId) | ||
{ | ||
this.wikiId = wikiId; | ||
} | ||
|
||
@Override | ||
public boolean matches(Object otherEvent) | ||
{ | ||
if (otherEvent == this) { | ||
return true; | ||
} | ||
|
||
boolean isMatching = false; | ||
|
||
if (this.getClass().isAssignableFrom(otherEvent.getClass())) { | ||
GeneralMailConfigurationUpdatedEvent other = (GeneralMailConfigurationUpdatedEvent) otherEvent; | ||
isMatching = this.wikiId == null || other.wikiId == null || Objects.equals(this.wikiId, other.wikiId); | ||
} | ||
|
||
return isMatching; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) | ||
{ | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
GeneralMailConfigurationUpdatedEvent that = (GeneralMailConfigurationUpdatedEvent) o; | ||
|
||
return new EqualsBuilder().append(this.wikiId, that.wikiId).isEquals(); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return new HashCodeBuilder(17, 37).append(this.wikiId).toHashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
.../org/xwiki/mail/internal/configuration/GeneralMailConfigurationUpdatedEventGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.xwiki.mail.internal.configuration; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import javax.inject.Provider; | ||
import javax.inject.Singleton; | ||
|
||
import org.xwiki.component.annotation.Component; | ||
import org.xwiki.configuration.ConfigurationSource; | ||
import org.xwiki.mail.GeneralMailConfigurationUpdatedEvent; | ||
import org.xwiki.model.reference.EntityReferenceSerializer; | ||
import org.xwiki.model.reference.LocalDocumentReference; | ||
import org.xwiki.model.reference.RegexEntityReference; | ||
import org.xwiki.observation.EventListener; | ||
import org.xwiki.observation.ObservationManager; | ||
import org.xwiki.observation.event.Event; | ||
|
||
import com.xpn.xwiki.XWikiContext; | ||
import com.xpn.xwiki.doc.XWikiDocument; | ||
import com.xpn.xwiki.internal.event.XObjectAddedEvent; | ||
import com.xpn.xwiki.internal.event.XObjectDeletedEvent; | ||
import com.xpn.xwiki.internal.event.XObjectUpdatedEvent; | ||
import com.xpn.xwiki.objects.BaseObjectReference; | ||
|
||
/** | ||
* Event generator for {@link GeneralMailConfigurationUpdatedEvent}. | ||
* | ||
* @since 14.10.15 | ||
* @since 15.5.2 | ||
* @since 15.7RC1 | ||
* @version $Id$ | ||
*/ | ||
@Component | ||
@Named(GeneralMailConfigurationUpdatedEventGenerator.NAME) | ||
@Singleton | ||
public class GeneralMailConfigurationUpdatedEventGenerator implements EventListener | ||
{ | ||
static final String NAME = "generalmailconfigurationchangedeventgenerator"; | ||
|
||
@Inject | ||
protected EntityReferenceSerializer<String> referenceSerializer; | ||
|
||
@Inject | ||
private Provider<ObservationManager> observationManagerProvider; | ||
|
||
@Inject | ||
private Provider<XWikiContext> contextProvider; | ||
|
||
@Inject | ||
@Named("mailgeneral") | ||
private ConfigurationSource currentWikiMailConfigSource; | ||
|
||
@Inject | ||
@Named("mailgeneralmainwiki") | ||
private ConfigurationSource mainWikiMailConfigSource; | ||
|
||
@Override | ||
public String getName() | ||
{ | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public List<Event> getEvents() | ||
{ | ||
String serializedClassReference = this.referenceSerializer.serialize( | ||
AbstractGeneralMailConfigClassDocumentConfigurationSource.GENERAL_MAILCONFIGCLASS_REFERENCE); | ||
RegexEntityReference filter = BaseObjectReference.any(serializedClassReference); | ||
|
||
return List.of(new XObjectAddedEvent(filter), new XObjectDeletedEvent(filter), new XObjectUpdatedEvent(filter)); | ||
} | ||
|
||
@Override | ||
public void onEvent(Event event, Object source, Object data) | ||
{ | ||
ObservationManager observationManager = this.observationManagerProvider.get(); | ||
|
||
if (source instanceof XWikiDocument) { | ||
XWikiDocument document = (XWikiDocument) source; | ||
|
||
// Test that the document is really a mail configuration document. | ||
LocalDocumentReference localDocumentReference = new LocalDocumentReference(document.getDocumentReference()); | ||
if (!AbstractMailConfigClassDocumentConfigurationSource.MAILCONFIG_REFERENCE | ||
.equals(localDocumentReference)) | ||
{ | ||
return; | ||
} | ||
|
||
// Clear the cache of the current wiki mail config source to ensure that any listener of the new events will | ||
// see the new configuration value regardless of which listener is called first. | ||
clearCache(this.currentWikiMailConfigSource); | ||
|
||
// Get the wiki id from the document reference. If it is the main wiki, notify without wiki, otherwise | ||
// notify with the wiki id. | ||
String wikiId = document.getDocumentReference().getWikiReference().getName(); | ||
if (this.contextProvider.get().isMainWiki(wikiId)) { | ||
// Clear the cache of the main wiki mail config source to ensure that any listener of the events will | ||
// see the new configuration value regardless of which listener is called first. | ||
clearCache(this.mainWikiMailConfigSource); | ||
observationManager.notify(new GeneralMailConfigurationUpdatedEvent(), null); | ||
} else { | ||
observationManager.notify(new GeneralMailConfigurationUpdatedEvent(wikiId), wikiId); | ||
} | ||
} | ||
} | ||
|
||
private void clearCache(ConfigurationSource mainWikiMailConfigSource) | ||
{ | ||
if (mainWikiMailConfigSource instanceof AbstractGeneralMailConfigClassDocumentConfigurationSource) { | ||
((AbstractGeneralMailConfigClassDocumentConfigurationSource) mainWikiMailConfigSource).clearCache(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.