Limit/validate string lengths for various identifiers to prevent DoS from large objects

Change-Id: Ib7c34ddf8bd161efdf8d00a50f3378f9b7366188
diff --git a/core/api/src/main/java/org/onosproject/net/domain/DomainId.java b/core/api/src/main/java/org/onosproject/net/domain/DomainId.java
index 6c67009..ef5e94f 100644
--- a/core/api/src/main/java/org/onosproject/net/domain/DomainId.java
+++ b/core/api/src/main/java/org/onosproject/net/domain/DomainId.java
@@ -18,11 +18,16 @@
 
 import org.onlab.util.Identifier;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * Representation of a domain identity.
  */
 public class DomainId extends Identifier<String> {
 
+    private static final int DOMAIN_ID_MAX_LENGTH = 1024;
+
     /**
      * Represents the domain directly managed by ONOS.
      */
@@ -44,6 +49,9 @@
      * @return instance of the class DomainId
      */
     public static DomainId domainId(String identifier) {
+        checkNotNull(identifier, "identifier cannot be null");
+        checkArgument(identifier.length() <= DOMAIN_ID_MAX_LENGTH,
+                "identifier exceeds maximum length " + DOMAIN_ID_MAX_LENGTH);
         return new DomainId(identifier);
     }
 }