zzh

zzh

Pitfalls encountered when modifying the request in Spring OAuth2 resource server

Goal:#

I want to modify the request sent by the frontend in the filter, so I initially inherited a WebSecurityConfigurerAdapter and overrode the configure method to add a custom filter. However, I could never enter this custom filter.

Analysis:#

First, we configured a resource server
image

Secondly, we configured a WebSecurityConfigurerAdapter
image

After running the resource server, the following code segment will be entered
image
The value of configurers corresponds to
image
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
image
It can be seen that a new HttpSecurity object is created here, and filters are added to the corresponding HttpSecurity object in the subsequent steps. From here, it can be known that the filters added by the two configurations do not affect each other.
image
image
Finally, two filterChains are generated, and only the first one is executed in the end (because both match anyRequest, so the first one is executed first?)
image

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.