Skip to content

With @PreAuthorize, method validation does not work. #10470

Closed
@und3rs

Description

@und3rs

Describe the bug
If I use @PreAuthorize, the validation for @RequestParam does not work.

To Reproduce

//-----------------------------------------------------
    // With PreAuthorize: Validation does NOT work
    //-----------------------------------------------------
    @GetMapping("withPreAuthorize")
    @ResponseStatus(HttpStatus.OK)
    @PreAuthorize("hasRole('USER')")
    suspend fun withPreAuthorize(
        @RequestParam(defaultValue = "100", required = true) @Min(1) @Max(100) limit: Int,
    ): String {
        return "OK"
    }


    //-----------------------------------------------------
    // Without PreAuthorize: Validation works
    //-----------------------------------------------------
    @GetMapping("withoutPreAuthorize")
    @ResponseStatus(HttpStatus.OK)
    suspend fun withoutPreAuthorize(
        @RequestParam(defaultValue = "100", required = true) @Min(1) @Max(100) limit: Int,
    ): String {
        return "OK"
    }

Expected behavior
A clear and concise description of what you expected to happen.
@PreAuthorize should not disturb validator.

Sample
https://github.com/und3rs/springboot-helpme
You can test with '\src\test\kotlin\test.http'.

Metadata

Metadata

Assignees

Labels

in: coreAn issue in spring-security-coretype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions