Spring security always returns HTTP 403

前端 未结 7 2075
逝去的感伤
逝去的感伤 2020-12-28 17:07

I have configured a custom Filter that grants a spring authority for every URL other than /login :

public class TokenFilter impleme         


        
7条回答
  •  执笔经年
    2020-12-28 17:57

    Pretty old question but just in case someone stumble upon this post, an application had the same problem and it turns out to be an issue with @ControllerAdvice.

    Basically, the setup was like this:

    @ControllerAdvice
    class MainController {
    
    @PreAuthorize("...")
    class AdminController extends MainController {
    

    And for a strange reason, any controller extending from MainController would trigger the @PreAuthorize of the AdminController class even though there were no relationships between this controller and the latter.

    In my case, it was an easy fix as removing the @ControllerAdvice was enough but if you need @ControllerAdvice, you might move the annotation to a class that is never used as a superclass.

提交回复
热议问题