Just like we created one CustomFilter, we can create more and use them. We can specify before which default filter it needs to be called. This is called filter chaining. If we want to place 2 filters before BasicAuthenticationFilter but CustomFilter1 needs to be called before CustomFIlter2 then we can specify sequence while registering Filters.

Steps for filter chaining

Lets suppose we want 2 Filters CustomFilter and CusotmLogFilter to be placed before BasicAuthenticationFilter and CustomLogFilter needs to be called before CustomFilter. Let’s use the jwt authentication code we created in the previous sec and modify it to have 2 filters.

spring security filter chaining
spring security filter chaining

Lets Test:

spring security filter chaining logs

Leave a Reply

Your email address will not be published. Required fields are marked *