X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fchat%2Fbackend%2Fdomain%2FChatRoom.java;h=30197432448e5fcaf3d956d27670087bc774ec2b;hb=f5bc2f9d05c472ad1b8f55fe193727ea3a84dc4d;hp=35d0c3d42afe5263466c112c2ed42ecb795fa8c8;hpb=aa0efd1151673c5f0f1576c3026f6fdd0dfad691;p=demos%2Fkafka%2Fchat diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java index 35d0c3d4..30197432 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/ChatRoom.java @@ -11,6 +11,8 @@ import reactor.core.publisher.Sinks; import java.time.Clock; import java.time.LocalDateTime; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Slf4j @@ -18,6 +20,7 @@ import java.util.*; @ToString(of = { "id", "name" }) public class ChatRoom { + public final static Pattern VALID_USER = Pattern.compile("^[a-z0-9-]{2,}$"); @Getter private final UUID id; @Getter @@ -48,6 +51,10 @@ public class ChatRoom String user, String text) { + Matcher matcher = VALID_USER.matcher(user); + if (!matcher.matches()) + throw new InvalidUsernameException(user); + Message.MessageKey key = Message.MessageKey.of(user, id); return service .getMessage(key)