diff --git a/java/com.sap.sse.security.test/src/com/sap/sse/security/test/PreferenceObjectBasedNotificationSetTest.java b/java/com.sap.sse.security.test/src/com/sap/sse/security/test/PreferenceObjectBasedNotificationSetTest.java index 9706cafb15c..231d4e698c0 100644 --- a/java/com.sap.sse.security.test/src/com/sap/sse/security/test/PreferenceObjectBasedNotificationSetTest.java +++ b/java/com.sap.sse.security.test/src/com/sap/sse/security/test/PreferenceObjectBasedNotificationSetTest.java @@ -3,6 +3,7 @@ package com.sap.sse.security.test; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.function.Consumer; @@ -170,7 +171,7 @@ public class PreferenceObjectBasedNotificationSetTest { @Test public void userMappingTest() throws UserManagementException { - store.createUser(user1, mail); + createUserWithVerifiedEmail(user1, mail); store.registerPreferenceConverter(prefKey, prefConverter); store.setPreferenceObject(user1, prefKey, values1); PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store); @@ -182,9 +183,22 @@ public class PreferenceObjectBasedNotificationSetTest { } @Test - public void userMappingWithTwoUsersTest() throws UserManagementException { + public void userWithNonVerifiedEmailIsSkippedTest() throws UserManagementException { store.createUser(user1, mail); - store.createUser(user2, mail); + store.registerPreferenceConverter(prefKey, prefConverter); + store.setPreferenceObject(user1, prefKey, values1); + PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store); + + UserConsumerMock mock = new UserConsumerMock(); + + notificationSet.forUsersMappedTo(A, mock); + Assert.assertTrue(Util.isEmpty(mock.calls)); + } + + @Test + public void userMappingWithTwoUsersTest() throws UserManagementException { + createUserWithVerifiedEmail(user1, mail); + createUserWithVerifiedEmail(user2, mail); store.registerPreferenceConverter(prefKey, prefConverter); store.setPreferenceObject(user1, prefKey, values1); store.setPreferenceObject(user2, prefKey, values2); @@ -201,7 +215,7 @@ public class PreferenceObjectBasedNotificationSetTest { @Test public void userMappingWithOneExistingAndOneUnknownUserTest() throws UserManagementException { - store.createUser(user1, mail); + createUserWithVerifiedEmail(user1, mail); store.registerPreferenceConverter(prefKey, prefConverter); store.setPreferenceObject(user1, prefKey, values1); store.setPreferenceObject(user2, prefKey, values2); @@ -247,6 +261,11 @@ public class PreferenceObjectBasedNotificationSetTest { return new HashSet<>(Arrays.asList(values)); } + private void createUserWithVerifiedEmail(String username, String email) throws UserManagementException { + store.createUser(username, email); + store.updateUser(new User(username, email, null, null, true, null, null, Collections.emptySet())); + } + private static class PreferenceObjectBasedNotificationSetImpl extends PreferenceObjectBasedNotificationSet, String> { public PreferenceObjectBasedNotificationSetImpl(String key, UserStore store) { diff --git a/java/com.sap.sse.security/src/com/sap/sse/security/PreferenceObjectBasedNotificationSet.java b/java/com.sap.sse.security/src/com/sap/sse/security/PreferenceObjectBasedNotificationSet.java index 4a6d57e2024..44853544437 100644 --- a/java/com.sap.sse.security/src/com/sap/sse/security/PreferenceObjectBasedNotificationSet.java +++ b/java/com.sap.sse.security/src/com/sap/sse/security/PreferenceObjectBasedNotificationSet.java @@ -135,6 +135,7 @@ public abstract class PreferenceObjectBasedNotificationSet implements /** * The given consumer will be called for every user that needs to be notified about the given object. + * Users without a verified email address will be skipped. */ public void forUsersMappedTo(T object, Consumer consumer) { for (String username : getUsersnamesToNotifyFor(object)) { @@ -144,7 +145,11 @@ public abstract class PreferenceObjectBasedNotificationSet implements if (user == null) { logger.log(Level.SEVERE, "Could not get User for name \"" + username + "\""); } else { - consumer.accept(user); + // we can not exclude users without verified email address when calculating the association because this + // state could have changed meanwhile. So this need to be done on the fly. + if(user.isEmailValidated()) { + consumer.accept(user); + } } } }