Skip to content

Commit 1c5242f

Browse files
wernerdvHaarolean
andauthored
BE: RBAC: Subject type/value is unintended to be optional (#719)
Co-authored-by: Roman Zabaluev <gpg@haarolean.dev>
1 parent ed49499 commit 1c5242f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

api/src/main/java/io/kafbat/ui/model/rbac/Role.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.kafbat.ui.model.rbac;
22

3-
import com.google.common.base.Preconditions;
3+
import static com.google.common.base.Preconditions.checkArgument;
4+
45
import java.util.List;
56
import lombok.Data;
67

@@ -13,9 +14,11 @@ public class Role {
1314
List<Permission> permissions;
1415

1516
public void validate() {
16-
Preconditions.checkArgument(!clusters.isEmpty(), "Role clusters cannot be empty");
17+
checkArgument(!clusters.isEmpty(), "Role clusters cannot be empty");
18+
checkArgument(!subjects.isEmpty(), "Role subjects cannot be empty");
1719
permissions.forEach(Permission::transform);
1820
permissions.forEach(Permission::validate);
21+
subjects.forEach(Subject::validate);
1922
}
2023

2124
}

api/src/main/java/io/kafbat/ui/model/rbac/Subject.java

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.kafbat.ui.model.rbac;
22

3+
import static com.google.common.base.Preconditions.checkArgument;
4+
import static com.google.common.base.Preconditions.checkNotNull;
5+
36
import io.kafbat.ui.model.rbac.provider.Provider;
47
import lombok.Getter;
58

@@ -21,4 +24,12 @@ public void setType(String type) {
2124
public void setValue(String value) {
2225
this.value = value;
2326
}
27+
28+
public void validate() {
29+
checkNotNull(type, "Subject type cannot be null");
30+
checkNotNull(value, "Subject value cannot be null");
31+
32+
checkArgument(!type.isEmpty(), "Subject type cannot be empty");
33+
checkArgument(!value.isEmpty(), "Subject value cannot be empty");
34+
}
2435
}

0 commit comments

Comments
 (0)