Goal:#
I want to modify the request sent by the frontend in the filter, so I initially inherited a WebSecurityConfigurerAdapter and overridden the configure method to add a custom filter. However, I could never enter this custom filter.
Analysis:#
First, we configured a resource server
Secondly, we configured a WebSecurityConfigurerAdapter
After running the resource server, the following code segment will be entered
The corresponding value of configurers is
It can be seen that configurers will contain two values, which respectively call the configuration of the resource server and the custom WebSecurityConfigurerAdapter configuration. Then, both will enter the WebSecurityConfigurerAdapter class and execute the following code segment
It can be seen that a new HttpSecurity object is created here, and a filter is added to the corresponding HttpSecurity object in the subsequent code. From here, it can be known that the filters added by the two configurations do not affect each other.
Finally, two filterChains are generated, and only the first one is executed (because both match anyRequest, so the first one is executed first?)