Commit 09889565 by Jason Song

protect notification controller when the input format is invalid

parent 0447fca3
...@@ -8,8 +8,10 @@ import com.dianping.cat.Cat; ...@@ -8,8 +8,10 @@ import com.dianping.cat.Cat;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -22,10 +24,16 @@ public class ReleaseMessageService { ...@@ -22,10 +24,16 @@ public class ReleaseMessageService {
private ReleaseMessageRepository releaseMessageRepository; private ReleaseMessageRepository releaseMessageRepository;
public ReleaseMessage findLatestReleaseMessageForMessages(Collection<String> messages) { public ReleaseMessage findLatestReleaseMessageForMessages(Collection<String> messages) {
if (CollectionUtils.isEmpty(messages)) {
return null;
}
return releaseMessageRepository.findTopByMessageInOrderByIdDesc(messages); return releaseMessageRepository.findTopByMessageInOrderByIdDesc(messages);
} }
public List<ReleaseMessage> findLatestReleaseMessagesGroupByMessages(Collection<String> messages) { public List<ReleaseMessage> findLatestReleaseMessagesGroupByMessages(Collection<String> messages) {
if (CollectionUtils.isEmpty(messages)) {
return Collections.EMPTY_LIST;
}
List<Object[]> result = List<Object[]> result =
releaseMessageRepository.findLatestReleaseMessagesGroupByMessages(messages); releaseMessageRepository.findLatestReleaseMessagesGroupByMessages(messages);
List<ReleaseMessage> releaseMessages = Lists.newArrayList(); List<ReleaseMessage> releaseMessages = Lists.newArrayList();
......
...@@ -108,6 +108,10 @@ public class NotificationControllerV2 implements ReleaseMessageListener { ...@@ -108,6 +108,10 @@ public class NotificationControllerV2 implements ReleaseMessageListener {
clientSideNotifications.put(namespace, notification.getNotificationId()); clientSideNotifications.put(namespace, notification.getNotificationId());
} }
if (CollectionUtils.isEmpty(namespaces)) {
throw new BadRequestException("Invalid format of notifications: " + notificationsAsString);
}
Multimap<String, String> watchedKeysMap = Multimap<String, String> watchedKeysMap =
watchKeysUtil.assembleAllWatchKeys(appId, cluster, namespaces, dataCenter); watchKeysUtil.assembleAllWatchKeys(appId, cluster, namespaces, dataCenter);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment