diff --git a/api/src/main/java/io/kafbat/ui/model/rbac/Role.java b/api/src/main/java/io/kafbat/ui/model/rbac/Role.java index db97d7649..e01392cc6 100644 --- a/api/src/main/java/io/kafbat/ui/model/rbac/Role.java +++ b/api/src/main/java/io/kafbat/ui/model/rbac/Role.java @@ -1,6 +1,7 @@ package io.kafbat.ui.model.rbac; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import java.util.List; import lombok.Data; @@ -13,9 +14,11 @@ public class Role { List permissions; public void validate() { - Preconditions.checkArgument(!clusters.isEmpty(), "Role clusters cannot be empty"); + checkArgument(!clusters.isEmpty(), "Role clusters cannot be empty"); + checkArgument(!subjects.isEmpty(), "Role subjects cannot be empty"); permissions.forEach(Permission::transform); permissions.forEach(Permission::validate); + subjects.forEach(Subject::validate); } } diff --git a/api/src/main/java/io/kafbat/ui/model/rbac/Subject.java b/api/src/main/java/io/kafbat/ui/model/rbac/Subject.java index a71cebea3..d653c1d0b 100644 --- a/api/src/main/java/io/kafbat/ui/model/rbac/Subject.java +++ b/api/src/main/java/io/kafbat/ui/model/rbac/Subject.java @@ -1,5 +1,8 @@ package io.kafbat.ui.model.rbac; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import io.kafbat.ui.model.rbac.provider.Provider; import lombok.Getter; @@ -21,4 +24,12 @@ public void setType(String type) { public void setValue(String value) { this.value = value; } + + public void validate() { + checkNotNull(type, "Subject type cannot be null"); + checkNotNull(value, "Subject value cannot be null"); + + checkArgument(!type.isEmpty(), "Subject type cannot be empty"); + checkArgument(!value.isEmpty(), "Subject value cannot be empty"); + } }