C96
C96

Reputation: 529

Enable global method security leads to 404

When I enable Global Method Security, I get 404/NotFound when I call my endpoint that belongs to a class annotated with @Preauthorized

This is my configuration:

@Configuration @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
class MethodSecurityConfig : GlobalMethodSecurityConfiguration()

And this is the controller:

@RestController
@RequestMapping(Endpoints.BABBLE.ROOT)
@PreAuthorize("@authenticator.checkIfThunderkickAdmin()")
class BabbleRequestController() {

    @PostMapping(Endpoints.BABBLE.APPEND)
    public fun balances(@RequestBody requestData: AppendRequestData, @RequestHeader(HttpHeaders.AUTHORIZATION)  authHeader : String): ResponseEntity<String> {
    ...

Upvotes: 0

Views: 282

Answers (1)

Andrei Kovrov
Andrei Kovrov

Reputation: 2440

I guess you got 404 because you have @PreAuthorize and missing proxyTargetClass = true for @EnableGlobalMethodSecurity annotation. Spring loses your controller because it's a JDK proxy instead of CGLIB and doesn't have @RestController anymore.

Try to replace it with:


@Configuration @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true, proxyTargetClass = true)
class MethodSecurityConfig : GlobalMethodSecurityConfiguration()

Upvotes: 3

Related Questions