Fixes #3791 - Add @Valid annotation to validate parameters in API Resource methods (#3792)

This commit is contained in:
Suresh Srinivas 2022-03-31 16:22:37 -07:00 committed by GitHub
parent aa81ceab1a
commit 42f91b0699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View File

@ -24,6 +24,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.validation.Valid;
import javax.validation.constraints.Max; import javax.validation.constraints.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -127,7 +128,7 @@ public class BotsResource extends EntityResource<Bots, BotsRepository> {
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Bots.class))), content = @Content(mediaType = "application/json", schema = @Schema(implementation = Bots.class))),
@ApiResponse(responseCode = "400", description = "Bad request") @ApiResponse(responseCode = "400", description = "Bad request")
}) })
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext, Bots bot) public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext, @Valid Bots bot)
throws IOException { throws IOException {
bot.withId(UUID.randomUUID()) bot.withId(UUID.randomUUID())
.withUpdatedBy(securityContext.getUserPrincipal().getName()) .withUpdatedBy(securityContext.getUserPrincipal().getName())

View File

@ -395,7 +395,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id,
TableJoins joins) @Valid TableJoins joins)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
Table table = dao.addJoins(UUID.fromString(id), joins); Table table = dao.addJoins(UUID.fromString(id), joins);
@ -409,7 +409,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id,
TableData tableData) @Valid TableData tableData)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
Table table = dao.addSampleData(UUID.fromString(id), tableData); Table table = dao.addSampleData(UUID.fromString(id), tableData);
@ -423,7 +423,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id,
TableProfile tableProfile) @Valid TableProfile tableProfile)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
Table table = dao.addTableProfileData(UUID.fromString(id), tableProfile); Table table = dao.addTableProfileData(UUID.fromString(id), tableProfile);
@ -457,7 +457,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id,
SQLQuery sqlQuery) @Valid SQLQuery sqlQuery)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
Table table = dao.addQuery(UUID.fromString(id), sqlQuery); Table table = dao.addQuery(UUID.fromString(id), sqlQuery);
@ -474,7 +474,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id,
DataModel dataModel) @Valid DataModel dataModel)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
Table table = dao.addDataModel(UUID.fromString(id), dataModel); Table table = dao.addDataModel(UUID.fromString(id), dataModel);
@ -488,7 +488,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id,
CreateTableTest createTableTest) @Valid CreateTableTest createTableTest)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
TableTest tableTest = getTableTest(securityContext, createTableTest); TableTest tableTest = getTableTest(securityContext, createTableTest);
@ -518,7 +518,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id,
CreateColumnTest createColumnTest) @Valid CreateColumnTest createColumnTest)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
ColumnTest columnTest = getColumnTest(securityContext, createColumnTest); ColumnTest columnTest = getColumnTest(securityContext, createColumnTest);
@ -533,7 +533,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the table", schema = @Schema(type = "string")) @PathParam("id") String id,
CreateCustomMetric createCustomMetric) @Valid CreateCustomMetric createCustomMetric)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
CustomMetric customMetric = getCustomMetric(securityContext, createCustomMetric); CustomMetric customMetric = getCustomMetric(securityContext, createCustomMetric);

View File

@ -344,7 +344,7 @@ public class PipelineResource extends EntityResource<Pipeline, PipelineRepositor
@Context UriInfo uriInfo, @Context UriInfo uriInfo,
@Context SecurityContext securityContext, @Context SecurityContext securityContext,
@Parameter(description = "Id of the pipeline", schema = @Schema(type = "string")) @PathParam("id") String id, @Parameter(description = "Id of the pipeline", schema = @Schema(type = "string")) @PathParam("id") String id,
PipelineStatus pipelineStatus) @Valid PipelineStatus pipelineStatus)
throws IOException { throws IOException {
SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT); SecurityUtil.authorizeAdmin(authorizer, securityContext, ADMIN | BOT);
Pipeline pipeline = dao.addPipelineStatus(UUID.fromString(id), pipelineStatus); Pipeline pipeline = dao.addPipelineStatus(UUID.fromString(id), pipelineStatus);