Repository: incubator-unomi Updated Branches: refs/heads/master e16a0bc30 -> cc8c14d10
UNOMI-127 Send an event when a profile is anonymized This commit contains the following changes: - Improved privacy service Javadoc (not yet complete) - Add the possibility to pass a scope to the anonymizeProfile and anonymousBrowsing REST endpoints - Added a "anonymizeProfile" event generated by the anonymizeProfile implementation. Signed-off-by: Serge Huber <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/cc8c14d1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/cc8c14d1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/cc8c14d1 Branch: refs/heads/master Commit: cc8c14d10c8743aaca4b8acad2f79911c32d0252 Parents: e16a0bc Author: Serge Huber <[email protected]> Authored: Tue Oct 3 13:26:50 2017 +0200 Committer: Serge Huber <[email protected]> Committed: Tue Oct 3 13:26:50 2017 +0200 ---------------------------------------------------------------------- .../unomi/api/services/PrivacyService.java | 100 ++++++++++++++++++- .../unomi/lists/actions/AddToListsAction.java | 2 +- .../privacy/rest/PrivacyServiceEndPoint.java | 13 ++- .../privacy/internal/PrivacyServiceImpl.java | 18 ++-- .../actions/MergeProfilesOnPropertyAction.java | 2 +- 5 files changed, 116 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cc8c14d1/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java b/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java index 4dd9c64..bbcc78b 100644 --- a/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java +++ b/api/src/main/java/org/apache/unomi/api/services/PrivacyService.java @@ -27,34 +27,126 @@ import java.util.List; */ public interface PrivacyService { + /** + * Retrieves the server information, including the name and version of the server, the event types + * if recognizes as well as the capabilities supported by the system. + * @return + */ ServerInfo getServerInfo(); + /** + * Deletes the current profile (but has no effect on sessions and events). This will delete the + * persisted profile and replace it with a new empty one with the same profileId. + * @param profileId the identifier of the profile to delete and replace + * @return true if the deletion was successful + */ Boolean deleteProfile(String profileId); - Boolean anonymizeProfile(String profileId); - + /** + * This method will "anonymize" a profile by removing from the associated profile all the properties + * that have been defined as "denied properties". + * @param profileId the identifier of the profile that needs to be anonymized. + * @param scope The scope will be used to send events, once for the anonymizeProfile event, the other for the profileUpdated event + * @return true if the profile had some properties purged, false otherwise + */ + Boolean anonymizeProfile(String profileId, String scope); + + /** + * This method will anonymize browsing data by creating an anonymous profile for the current profile, + * and then re-associating all the profile's sessions and events with the new anonymous profile + * todo this method does not anonymize any session or event properties that may contain profile + * data (such as the login event) + * @param profileId the identifier of the profile on which to perform the anonymizations of the browsing + * data + * @return true if the operation was successful, false otherwise + */ Boolean anonymizeBrowsingData(String profileId); + /** + * This method will perform two operations, first it will call the anonymizeBrowsingData method on the + * specified profile, and then it will delete the profile from the persistence service. + * @param profileId the identifier of the profile + * @return true if the operation was successful, false otherwise + */ Boolean deleteProfileData(String profileId); - Boolean setRequireAnonymousBrowsing(String profileId, boolean anonymous); - + /** + * Controls the activation/deactivation of anonymous browsing. This method will simply set a system + * property called requireAnonymousProfile that will be then use to know if we should associate + * browsing data with the main profile or the associated anonymous profile. + * Note that changing this setting will also reset the goals and pastEvents system properties for the + * profile. + * @param profileId the identifier of the profile on which to set the anonymous browsing property flag + * @param anonymous the value of the anonymous browsing flag. + * @param scope a scope used to send a profileUpdated event internally + * @return true if successful, false otherwise + */ + Boolean setRequireAnonymousBrowsing(String profileId, boolean anonymous, String scope); + + /** + * Tests if the anonymous browsing flag is set of the specified profile. + * @param profileId the identifier of the profile on which we want to retrieve the anonymous browsing flag + * @return true if successful, false otherwise + */ Boolean isRequireAnonymousBrowsing(String profileId); + /** + * Build a new anonymous profile (but doesn't persist it in the persistence service). This will also + * copy the profile properties from the passed profile that are not listed as denied properties. + * @param profile the profile for which to create the anonymous profile + * @return a newly created (but not persisted) profile for the passed profile. + */ Profile getAnonymousProfile(Profile profile); + /** + * Retrieve the list of events that the profile has deactivated. For each profile a visitor may indicate + * that he doesn't want some events to be collected. This method retrieves this list from the specified + * profile + * @param profileId the identifier for the profile for which we want to retrieve the list of forbidden + * event types + * @return a list of event types + */ List<String> getFilteredEventTypes(String profileId); + /** + * Set the list of filtered event types for a profile. This is the list of event types that the visitor + * has specified he does not want the server to collect. + * @param profileId the identifier of the profile on which to filter the events + * @param eventTypes a list of event types that will be filter for the profile + * @return true if successfull, false otherwise. + */ Boolean setFilteredEventTypes(String profileId, List<String> eventTypes); + /** + * Gets the list of denied + * @param profileId + * @return + */ List<String> getDeniedProperties(String profileId); Boolean setDeniedProperties(String profileId, List<String> propertyNames); + /** + * @deprecated + * @param profileId + * @return + */ List<String> getDeniedPropertyDistribution(String profileId); + /** + * @deprecated + * @param profileId + * @param propertyNames + * @return + */ Boolean setDeniedPropertyDistribution(String profileId, List<String> propertyNames); + /** + * Removes a property from the specified profile. This change is persisted. + * @param profileId the identifier of the profile + * @param propertyName the name of the property to remove + * @return true if sucessfull, false otherwise + */ Boolean removeProperty(String profileId, String propertyName); } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cc8c14d1/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java ---------------------------------------------------------------------- diff --git a/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java b/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java index 3ec1407..5dcaaa0 100644 --- a/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java +++ b/extensions/lists-extension/actions/src/main/java/org/apache/unomi/lists/actions/AddToListsAction.java @@ -48,7 +48,7 @@ public class AddToListsAction implements ActionExecutor { Profile profile = event.getProfile(); profile.getSystemProperties().put("lists", listIdentifiers); - Event profileUpdated = new Event("profileUpdated", null, profile, null, null, profile, new Date()); + Event profileUpdated = new Event("profileUpdated", null, profile, event.getScope(), null, profile, new Date()); profileUpdated.setPersistent(false); eventService.send(profileUpdated); profileService.save(profile); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cc8c14d1/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java ---------------------------------------------------------------------- diff --git a/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java b/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java index 154f443..3fe1855 100644 --- a/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java +++ b/extensions/privacy-extension/rest/src/main/java/org/apache/unomi/privacy/rest/PrivacyServiceEndPoint.java @@ -25,7 +25,6 @@ import javax.jws.WebMethod; import javax.jws.WebService; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.NewCookie; import javax.ws.rs.core.Response; import java.util.List; @@ -66,8 +65,8 @@ public class PrivacyServiceEndPoint { @POST @Path("/profiles/{profileId}/anonymize") - public void anonymizeProfile(@PathParam("profileId") String profileId) { - privacyService.anonymizeProfile(profileId); + public void anonymizeProfile(@PathParam("profileId") String profileId, @QueryParam("scope") String scope) { + privacyService.anonymizeProfile(profileId, scope); } @GET @@ -78,18 +77,18 @@ public class PrivacyServiceEndPoint { @POST @Path("/profiles/{profileId}/anonymousBrowsing") - public Response activateAnonymousBrowsing(@PathParam("profileId") String profileId, @QueryParam("anonymizePastBrowsing") @DefaultValue("false") boolean past) { + public Response activateAnonymousBrowsing(@PathParam("profileId") String profileId, @QueryParam("anonymizePastBrowsing") @DefaultValue("false") boolean past, @QueryParam("scope") String scope) { if (past) { privacyService.anonymizeBrowsingData(profileId); } - Boolean r = privacyService.setRequireAnonymousBrowsing(profileId, true); + Boolean r = privacyService.setRequireAnonymousBrowsing(profileId, true, scope); return r ? Response.ok().build() : Response.serverError().build(); } @DELETE @Path("/profiles/{profileId}/anonymousBrowsing") - public Response deactivateAnonymousBrowsing(@PathParam("profileId") String profileId) { - Boolean r = privacyService.setRequireAnonymousBrowsing(profileId, false); + public Response deactivateAnonymousBrowsing(@PathParam("profileId") String profileId, @QueryParam("scope") String scope) { + Boolean r = privacyService.setRequireAnonymousBrowsing(profileId, false, scope); return r ? Response.ok().build() : Response.serverError().build(); } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cc8c14d1/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java ---------------------------------------------------------------------- diff --git a/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java b/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java index f272110..2686848 100644 --- a/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java +++ b/extensions/privacy-extension/services/src/main/java/org/apache/unomi/privacy/internal/PrivacyServiceImpl.java @@ -96,16 +96,22 @@ public class PrivacyServiceImpl implements PrivacyService { } @Override - public Boolean anonymizeProfile(String profileId) { + public Boolean anonymizeProfile(String profileId, String scope) { Profile profile = profileService.load(profileId); if (profile == null) { return false; } + + // first we send out the anonymize profile event to make sure other systems can still use external identifiers to lookup the profile and anonymize it. + Event anonymizeProfileEvent = new Event("anonymizeProfile", null, profile, scope, null, profile, new Date()); + anonymizeProfileEvent.setPersistent(true); + eventService.send(anonymizeProfileEvent); + boolean res = profile.getProperties().keySet().removeAll(getDeniedProperties(profile.getItemId())); - Event profileUpdated = new Event("profileUpdated", null, profile, null, null, profile, new Date()); - profileUpdated.setPersistent(false); - eventService.send(profileUpdated); + Event profileUpdatedEvent = new Event("profileUpdated", null, profile, scope, null, profile, new Date()); + profileUpdatedEvent.setPersistent(false); + eventService.send(profileUpdatedEvent); profileService.save(profile); @@ -144,7 +150,7 @@ public class PrivacyServiceImpl implements PrivacyService { } @Override - public Boolean setRequireAnonymousBrowsing(String profileId, boolean anonymous) { + public Boolean setRequireAnonymousBrowsing(String profileId, boolean anonymous, String scope) { Profile profile = profileService.load(profileId); if (profile == null) { return false; @@ -154,7 +160,7 @@ public class PrivacyServiceImpl implements PrivacyService { profile.getSystemProperties().remove("goals"); profile.getSystemProperties().remove("pastEvents"); } - Event profileUpdated = new Event("profileUpdated", null, profile, null, null, profile, new Date()); + Event profileUpdated = new Event("profileUpdated", null, profile, scope, null, profile, new Date()); profileUpdated.setPersistent(false); eventService.send(profileUpdated); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cc8c14d1/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java ---------------------------------------------------------------------- diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java index 9d86f57..9fc1032 100644 --- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java +++ b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/MergeProfilesOnPropertyAction.java @@ -199,7 +199,7 @@ public class MergeProfilesOnPropertyAction implements ActionExecutor { currentSession.setProfile(masterProfile); if (privacyService.isRequireAnonymousBrowsing(profileId)) { - privacyService.setRequireAnonymousBrowsing(masterProfileId, true); + privacyService.setRequireAnonymousBrowsing(masterProfileId, true, event.getScope()); } final Boolean anonymousBrowsing = privacyService.isRequireAnonymousBrowsing(masterProfileId); if (anonymousBrowsing) {
