Skip to content

Commit

Permalink
BE: RBAC: Subject type/value is unintended to be optional (#719)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Zabaluev <[email protected]>
  • Loading branch information
wernerdv and Haarolean authored Jan 16, 2025
1 parent ed49499 commit 1c5242f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/src/main/java/io/kafbat/ui/model/rbac/Role.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,9 +14,11 @@ public class Role {
List<Permission> 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);
}

}
11 changes: 11 additions & 0 deletions api/src/main/java/io/kafbat/ui/model/rbac/Subject.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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");
}
}

0 comments on commit 1c5242f

Please sign in to comment.