|
@@ -13,8 +13,10 @@ import com.provectus.kafka.ui.model.SchemaSubjectsResponseDTO;
|
|
import com.provectus.kafka.ui.model.rbac.AccessContext;
|
|
import com.provectus.kafka.ui.model.rbac.AccessContext;
|
|
import com.provectus.kafka.ui.model.rbac.permission.SchemaAction;
|
|
import com.provectus.kafka.ui.model.rbac.permission.SchemaAction;
|
|
import com.provectus.kafka.ui.service.SchemaRegistryService;
|
|
import com.provectus.kafka.ui.service.SchemaRegistryService;
|
|
|
|
+import com.provectus.kafka.ui.service.audit.AuditService;
|
|
import com.provectus.kafka.ui.service.rbac.AccessControlService;
|
|
import com.provectus.kafka.ui.service.rbac.AccessControlService;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -37,6 +39,7 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
|
|
|
|
private final SchemaRegistryService schemaRegistryService;
|
|
private final SchemaRegistryService schemaRegistryService;
|
|
private final AccessControlService accessControlService;
|
|
private final AccessControlService accessControlService;
|
|
|
|
+ private final AuditService auditService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected KafkaCluster getCluster(String clusterName) {
|
|
protected KafkaCluster getCluster(String clusterName) {
|
|
@@ -51,13 +54,14 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
public Mono<ResponseEntity<CompatibilityCheckResponseDTO>> checkSchemaCompatibility(
|
|
public Mono<ResponseEntity<CompatibilityCheckResponseDTO>> checkSchemaCompatibility(
|
|
String clusterName, String subject, @Valid Mono<NewSchemaSubjectDTO> newSchemaSubjectMono,
|
|
String clusterName, String subject, @Valid Mono<NewSchemaSubjectDTO> newSchemaSubjectMono,
|
|
ServerWebExchange exchange) {
|
|
ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schema(subject)
|
|
.schema(subject)
|
|
.schemaActions(SchemaAction.VIEW)
|
|
.schemaActions(SchemaAction.VIEW)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("checkSchemaCompatibility")
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
newSchemaSubjectMono.flatMap(subjectDTO ->
|
|
newSchemaSubjectMono.flatMap(subjectDTO ->
|
|
schemaRegistryService.checksSchemaCompatibility(
|
|
schemaRegistryService.checksSchemaCompatibility(
|
|
getCluster(clusterName),
|
|
getCluster(clusterName),
|
|
@@ -66,19 +70,20 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
))
|
|
))
|
|
.map(kafkaSrMapper::toDto)
|
|
.map(kafkaSrMapper::toDto)
|
|
.map(ResponseEntity::ok)
|
|
.map(ResponseEntity::ok)
|
|
- );
|
|
|
|
|
|
+ ).doOnEach(sig -> auditService.audit(context, sig));
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Mono<ResponseEntity<SchemaSubjectDTO>> createNewSchema(
|
|
public Mono<ResponseEntity<SchemaSubjectDTO>> createNewSchema(
|
|
String clusterName, @Valid Mono<NewSchemaSubjectDTO> newSchemaSubjectMono,
|
|
String clusterName, @Valid Mono<NewSchemaSubjectDTO> newSchemaSubjectMono,
|
|
ServerWebExchange exchange) {
|
|
ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schemaActions(SchemaAction.CREATE)
|
|
.schemaActions(SchemaAction.CREATE)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("createNewSchema")
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
newSchemaSubjectMono.flatMap(newSubject ->
|
|
newSchemaSubjectMono.flatMap(newSubject ->
|
|
schemaRegistryService.registerNewSchema(
|
|
schemaRegistryService.registerNewSchema(
|
|
getCluster(clusterName),
|
|
getCluster(clusterName),
|
|
@@ -87,20 +92,22 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
)
|
|
)
|
|
).map(kafkaSrMapper::toDto)
|
|
).map(kafkaSrMapper::toDto)
|
|
.map(ResponseEntity::ok)
|
|
.map(ResponseEntity::ok)
|
|
- );
|
|
|
|
|
|
+ ).doOnEach(sig -> auditService.audit(context, sig));
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Mono<ResponseEntity<Void>> deleteLatestSchema(
|
|
public Mono<ResponseEntity<Void>> deleteLatestSchema(
|
|
String clusterName, String subject, ServerWebExchange exchange) {
|
|
String clusterName, String subject, ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schema(subject)
|
|
.schema(subject)
|
|
.schemaActions(SchemaAction.DELETE)
|
|
.schemaActions(SchemaAction.DELETE)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("deleteLatestSchema")
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
schemaRegistryService.deleteLatestSchemaSubject(getCluster(clusterName), subject)
|
|
schemaRegistryService.deleteLatestSchemaSubject(getCluster(clusterName), subject)
|
|
|
|
+ .doOnEach(sig -> auditService.audit(context, sig))
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -108,14 +115,16 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
@Override
|
|
@Override
|
|
public Mono<ResponseEntity<Void>> deleteSchema(
|
|
public Mono<ResponseEntity<Void>> deleteSchema(
|
|
String clusterName, String subject, ServerWebExchange exchange) {
|
|
String clusterName, String subject, ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schema(subject)
|
|
.schema(subject)
|
|
.schemaActions(SchemaAction.DELETE)
|
|
.schemaActions(SchemaAction.DELETE)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("deleteSchema")
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
schemaRegistryService.deleteSchemaSubjectEntirely(getCluster(clusterName), subject)
|
|
schemaRegistryService.deleteSchemaSubjectEntirely(getCluster(clusterName), subject)
|
|
|
|
+ .doOnEach(sig -> auditService.audit(context, sig))
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -123,14 +132,16 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
@Override
|
|
@Override
|
|
public Mono<ResponseEntity<Void>> deleteSchemaByVersion(
|
|
public Mono<ResponseEntity<Void>> deleteSchemaByVersion(
|
|
String clusterName, String subjectName, Integer version, ServerWebExchange exchange) {
|
|
String clusterName, String subjectName, Integer version, ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schema(subjectName)
|
|
.schema(subjectName)
|
|
.schemaActions(SchemaAction.DELETE)
|
|
.schemaActions(SchemaAction.DELETE)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("deleteSchemaByVersion")
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
schemaRegistryService.deleteSchemaSubjectByVersion(getCluster(clusterName), subjectName, version)
|
|
schemaRegistryService.deleteSchemaSubjectByVersion(getCluster(clusterName), subjectName, version)
|
|
|
|
+ .doOnEach(sig -> auditService.audit(context, sig))
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -138,16 +149,20 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
@Override
|
|
@Override
|
|
public Mono<ResponseEntity<Flux<SchemaSubjectDTO>>> getAllVersionsBySubject(
|
|
public Mono<ResponseEntity<Flux<SchemaSubjectDTO>>> getAllVersionsBySubject(
|
|
String clusterName, String subjectName, ServerWebExchange exchange) {
|
|
String clusterName, String subjectName, ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schema(subjectName)
|
|
.schema(subjectName)
|
|
.schemaActions(SchemaAction.VIEW)
|
|
.schemaActions(SchemaAction.VIEW)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("getAllVersionsBySubject")
|
|
|
|
+ .build();
|
|
|
|
|
|
Flux<SchemaSubjectDTO> schemas =
|
|
Flux<SchemaSubjectDTO> schemas =
|
|
schemaRegistryService.getAllVersionsBySubject(getCluster(clusterName), subjectName)
|
|
schemaRegistryService.getAllVersionsBySubject(getCluster(clusterName), subjectName)
|
|
.map(kafkaSrMapper::toDto);
|
|
.map(kafkaSrMapper::toDto);
|
|
- return validateAccess.thenReturn(ResponseEntity.ok(schemas));
|
|
|
|
|
|
+
|
|
|
|
+ return accessControlService.validateAccess(context)
|
|
|
|
+ .thenReturn(ResponseEntity.ok(schemas))
|
|
|
|
+ .doOnEach(sig -> auditService.audit(context, sig));
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -163,34 +178,37 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
public Mono<ResponseEntity<SchemaSubjectDTO>> getLatestSchema(String clusterName,
|
|
public Mono<ResponseEntity<SchemaSubjectDTO>> getLatestSchema(String clusterName,
|
|
String subject,
|
|
String subject,
|
|
ServerWebExchange exchange) {
|
|
ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schema(subject)
|
|
.schema(subject)
|
|
.schemaActions(SchemaAction.VIEW)
|
|
.schemaActions(SchemaAction.VIEW)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("getLatestSchema")
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
schemaRegistryService.getLatestSchemaVersionBySubject(getCluster(clusterName), subject)
|
|
schemaRegistryService.getLatestSchemaVersionBySubject(getCluster(clusterName), subject)
|
|
.map(kafkaSrMapper::toDto)
|
|
.map(kafkaSrMapper::toDto)
|
|
.map(ResponseEntity::ok)
|
|
.map(ResponseEntity::ok)
|
|
- );
|
|
|
|
|
|
+ ).doOnEach(sig -> auditService.audit(context, sig));
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Mono<ResponseEntity<SchemaSubjectDTO>> getSchemaByVersion(
|
|
public Mono<ResponseEntity<SchemaSubjectDTO>> getSchemaByVersion(
|
|
String clusterName, String subject, Integer version, ServerWebExchange exchange) {
|
|
String clusterName, String subject, Integer version, ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schema(subject)
|
|
.schema(subject)
|
|
.schemaActions(SchemaAction.VIEW)
|
|
.schemaActions(SchemaAction.VIEW)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("getSchemaByVersion")
|
|
|
|
+ .operationParams(Map.of("subject", subject, "version", version))
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
schemaRegistryService.getSchemaSubjectByVersion(
|
|
schemaRegistryService.getSchemaSubjectByVersion(
|
|
getCluster(clusterName), subject, version)
|
|
getCluster(clusterName), subject, version)
|
|
.map(kafkaSrMapper::toDto)
|
|
.map(kafkaSrMapper::toDto)
|
|
.map(ResponseEntity::ok)
|
|
.map(ResponseEntity::ok)
|
|
- );
|
|
|
|
|
|
+ ).doOnEach(sig -> auditService.audit(context, sig));
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -199,6 +217,11 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
@Valid Integer perPage,
|
|
@Valid Integer perPage,
|
|
@Valid String search,
|
|
@Valid String search,
|
|
ServerWebExchange serverWebExchange) {
|
|
ServerWebExchange serverWebExchange) {
|
|
|
|
+ var context = AccessContext.builder()
|
|
|
|
+ .cluster(clusterName)
|
|
|
|
+ .operationName("getSchemas")
|
|
|
|
+ .build();
|
|
|
|
+
|
|
return schemaRegistryService
|
|
return schemaRegistryService
|
|
.getAllSubjectNames(getCluster(clusterName))
|
|
.getAllSubjectNames(getCluster(clusterName))
|
|
.flatMapIterable(l -> l)
|
|
.flatMapIterable(l -> l)
|
|
@@ -220,25 +243,28 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
return schemaRegistryService.getAllLatestVersionSchemas(getCluster(clusterName), subjectsToRender)
|
|
return schemaRegistryService.getAllLatestVersionSchemas(getCluster(clusterName), subjectsToRender)
|
|
.map(subjs -> subjs.stream().map(kafkaSrMapper::toDto).toList())
|
|
.map(subjs -> subjs.stream().map(kafkaSrMapper::toDto).toList())
|
|
.map(subjs -> new SchemaSubjectsResponseDTO().pageCount(totalPages).schemas(subjs));
|
|
.map(subjs -> new SchemaSubjectsResponseDTO().pageCount(totalPages).schemas(subjs));
|
|
- }).map(ResponseEntity::ok);
|
|
|
|
|
|
+ }).map(ResponseEntity::ok)
|
|
|
|
+ .doOnEach(sig -> auditService.audit(context, sig));
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Mono<ResponseEntity<Void>> updateGlobalSchemaCompatibilityLevel(
|
|
public Mono<ResponseEntity<Void>> updateGlobalSchemaCompatibilityLevel(
|
|
String clusterName, @Valid Mono<CompatibilityLevelDTO> compatibilityLevelMono,
|
|
String clusterName, @Valid Mono<CompatibilityLevelDTO> compatibilityLevelMono,
|
|
ServerWebExchange exchange) {
|
|
ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schemaActions(SchemaAction.MODIFY_GLOBAL_COMPATIBILITY)
|
|
.schemaActions(SchemaAction.MODIFY_GLOBAL_COMPATIBILITY)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("updateGlobalSchemaCompatibilityLevel")
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
compatibilityLevelMono
|
|
compatibilityLevelMono
|
|
.flatMap(compatibilityLevelDTO ->
|
|
.flatMap(compatibilityLevelDTO ->
|
|
schemaRegistryService.updateGlobalSchemaCompatibility(
|
|
schemaRegistryService.updateGlobalSchemaCompatibility(
|
|
getCluster(clusterName),
|
|
getCluster(clusterName),
|
|
kafkaSrMapper.fromDto(compatibilityLevelDTO.getCompatibility())
|
|
kafkaSrMapper.fromDto(compatibilityLevelDTO.getCompatibility())
|
|
))
|
|
))
|
|
|
|
+ .doOnEach(sig -> auditService.audit(context, sig))
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -247,12 +273,14 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
public Mono<ResponseEntity<Void>> updateSchemaCompatibilityLevel(
|
|
public Mono<ResponseEntity<Void>> updateSchemaCompatibilityLevel(
|
|
String clusterName, String subject, @Valid Mono<CompatibilityLevelDTO> compatibilityLevelMono,
|
|
String clusterName, String subject, @Valid Mono<CompatibilityLevelDTO> compatibilityLevelMono,
|
|
ServerWebExchange exchange) {
|
|
ServerWebExchange exchange) {
|
|
- Mono<Void> validateAccess = accessControlService.validateAccess(AccessContext.builder()
|
|
|
|
|
|
+ var context = AccessContext.builder()
|
|
.cluster(clusterName)
|
|
.cluster(clusterName)
|
|
.schemaActions(SchemaAction.EDIT)
|
|
.schemaActions(SchemaAction.EDIT)
|
|
- .build());
|
|
|
|
|
|
+ .operationName("updateSchemaCompatibilityLevel")
|
|
|
|
+ .operationParams(Map.of("subject", subject))
|
|
|
|
+ .build();
|
|
|
|
|
|
- return validateAccess.then(
|
|
|
|
|
|
+ return accessControlService.validateAccess(context).then(
|
|
compatibilityLevelMono
|
|
compatibilityLevelMono
|
|
.flatMap(compatibilityLevelDTO ->
|
|
.flatMap(compatibilityLevelDTO ->
|
|
schemaRegistryService.updateSchemaCompatibility(
|
|
schemaRegistryService.updateSchemaCompatibility(
|
|
@@ -260,6 +288,7 @@ public class SchemasController extends AbstractController implements SchemasApi
|
|
subject,
|
|
subject,
|
|
kafkaSrMapper.fromDto(compatibilityLevelDTO.getCompatibility())
|
|
kafkaSrMapper.fromDto(compatibilityLevelDTO.getCompatibility())
|
|
))
|
|
))
|
|
|
|
+ .doOnEach(sig -> auditService.audit(context, sig))
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
.thenReturn(ResponseEntity.ok().build())
|
|
);
|
|
);
|
|
}
|
|
}
|