Skip to content

Commit f4459a7

Browse files
committed
Fix missing RBAC cluster check
1 parent fcb007c commit f4459a7

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

api/src/main/java/io/kafbat/ui/service/rbac/AccessControlService.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.function.Predicate;
2828
import java.util.stream.Collectors;
2929
import javax.annotation.Nullable;
30+
import lombok.Getter;
3031
import lombok.RequiredArgsConstructor;
3132
import lombok.extern.slf4j.Slf4j;
3233
import org.apache.commons.collections.CollectionUtils;
@@ -54,7 +55,9 @@ public class AccessControlService {
5455
private final RoleBasedAccessControlProperties properties;
5556
private final Environment environment;
5657

58+
@Getter
5759
private boolean rbacEnabled = false;
60+
@Getter
5861
private Set<ProviderAuthorityExtractor> oauthExtractors = Collections.emptySet();
5962

6063
@PostConstruct
@@ -107,12 +110,14 @@ private boolean isAccessible(AuthenticatedUser user, AccessContext context) {
107110
if (context.cluster() != null && !isClusterAccessible(context.cluster(), user)) {
108111
return false;
109112
}
110-
return context.isAccessible(getUserPermissions(user));
113+
return context.isAccessible(getUserPermissions(user, context.cluster()));
111114
}
112115

113-
private List<Permission> getUserPermissions(AuthenticatedUser user) {
114-
return properties.getRoles().stream()
116+
private List<Permission> getUserPermissions(AuthenticatedUser user, String clusterName) {
117+
return properties.getRoles()
118+
.stream()
115119
.filter(filterRole(user))
120+
.filter(role -> role.getClusters().stream().anyMatch(clusterName::equalsIgnoreCase))
116121
.flatMap(role -> role.getPermissions().stream())
117122
.toList();
118123
}
@@ -188,10 +193,6 @@ public Mono<Boolean> isConnectAccessible(String connectName, String clusterName)
188193
);
189194
}
190195

191-
public Set<ProviderAuthorityExtractor> getOauthExtractors() {
192-
return oauthExtractors;
193-
}
194-
195196
public List<Role> getRoles() {
196197
if (!rbacEnabled) {
197198
return Collections.emptyList();
@@ -203,7 +204,4 @@ private Predicate<Role> filterRole(AuthenticatedUser user) {
203204
return role -> user.groups().contains(role.getName());
204205
}
205206

206-
public boolean isRbacEnabled() {
207-
return rbacEnabled;
208-
}
209207
}

0 commit comments

Comments
 (0)