Skip to content

Commit fdd9ad9

Browse files
authored
BE: RBAC: Add missing RBAC action, fix possible exceptions on unknown actions (#3810)
1 parent 1c35ded commit fdd9ad9

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

kafka-ui-api/src/main/java/com/provectus/kafka/ui/controller/AccessController.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
import java.util.Collection;
1313
import java.util.Collections;
1414
import java.util.List;
15+
import java.util.Objects;
1516
import java.util.stream.Collectors;
17+
import javax.annotation.Nullable;
1618
import lombok.RequiredArgsConstructor;
19+
import lombok.extern.slf4j.Slf4j;
1720
import org.springframework.http.ResponseEntity;
1821
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
1922
import org.springframework.security.core.context.SecurityContext;
@@ -23,15 +26,12 @@
2326

2427
@RestController
2528
@RequiredArgsConstructor
29+
@Slf4j
2630
public class AccessController implements AuthorizationApi {
2731

2832
private final AccessControlService accessControlService;
2933

3034
public Mono<ResponseEntity<AuthenticationInfoDTO>> getUserAuthInfo(ServerWebExchange exchange) {
31-
AuthenticationInfoDTO dto = new AuthenticationInfoDTO();
32-
dto.setRbacEnabled(accessControlService.isRbacEnabled());
33-
UserInfoDTO userInfo = new UserInfoDTO();
34-
3535
Mono<List<UserPermissionDTO>> permissions = accessControlService.getUser()
3636
.map(user -> accessControlService.getRoles()
3737
.stream()
@@ -49,13 +49,11 @@ public Mono<ResponseEntity<AuthenticationInfoDTO>> getUserAuthInfo(ServerWebExch
4949
return userName
5050
.zipWith(permissions)
5151
.map(data -> {
52-
userInfo.setUsername(data.getT1());
53-
userInfo.setPermissions(data.getT2());
54-
55-
dto.setUserInfo(userInfo);
52+
var dto = new AuthenticationInfoDTO(accessControlService.isRbacEnabled());
53+
dto.setUserInfo(new UserInfoDTO(data.getT1(), data.getT2()));
5654
return dto;
5755
})
58-
.switchIfEmpty(Mono.just(dto))
56+
.switchIfEmpty(Mono.just(new AuthenticationInfoDTO(accessControlService.isRbacEnabled())))
5957
.map(ResponseEntity::ok);
6058
}
6159

@@ -70,11 +68,22 @@ private List<UserPermissionDTO> mapPermissions(List<Permission> permissions, Lis
7068
dto.setActions(permission.getActions()
7169
.stream()
7270
.map(String::toUpperCase)
73-
.map(ActionDTO::valueOf)
71+
.map(this::mapAction)
72+
.filter(Objects::nonNull)
7473
.collect(Collectors.toList()));
7574
return dto;
7675
})
7776
.collect(Collectors.toList());
7877
}
7978

79+
@Nullable
80+
private ActionDTO mapAction(String name) {
81+
try {
82+
return ActionDTO.fromValue(name);
83+
} catch (IllegalArgumentException e) {
84+
log.warn("Unknown Action [{}], skipping", name);
85+
return null;
86+
}
87+
}
88+
8089
}

kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3452,6 +3452,7 @@ components:
34523452
- MESSAGES_READ
34533453
- MESSAGES_PRODUCE
34543454
- MESSAGES_DELETE
3455+
- RESTART
34553456

34563457
ResourceType:
34573458
type: string

0 commit comments

Comments
 (0)