zzh

zzh

Spring OAuth2 Resource Server Pitfalls in Request Modification

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
image

Secondly, we configured a WebSecurityConfigurerAdapter
image

After running the resource server, the following code segment will be entered
image
The corresponding value of configurers is
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 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.
image
image
Finally, two filterChains are generated, and only the first one is executed (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.