Now, in the previous videos, we looked at adding a filter before and after a specific spring security
filter in this video.
Let's try to explore of adding a filter at the same portion of it, spring security filter so we can
add our custom own filter at the same place, our order of a specified screen security filter.
That doesn't mean it will replace the spring security filter.
And at the same time, we can't guarantee that either of these filters which are positioned at the same
place and it is up to the spring security to decide randomly to execute which filter before and after
which are located at the same position based upon our configurations.
As you can see here, we have, of course, filter with the other one, CSIR, filter the and at the
same time we are trying to inject our own custom filter again, logging filter at the same portion of
basic authentication filter, and we can't guarantee which one will be executer first and which one
will be executed after, since this is very random in nature about the execution of the filter.
It is not recommended to use this until unless you are very confident that it will not create any issues
in your application, regardless of the order of the execution of these filters which are configured
at the same place.
Let's try to explore on the back and called how we can configure a custom filter at the same portion
of basic authentication filter.
For the same, I have created a filter with the name authorities logging and filter which implements
filter and already the method do filter.
So the purpose of this filter is just to create a longer statement saying authentication validation
is in progress.
Once the logger has been printed onto the controller log file, it will hand over to the next filter
inside the chain of the spring security filters creating this filter.
We should go to our project security config and configure this custom logging filter at the same place
of basic authentication filter by using the method and filter.
And as you can see, we can use our filter before our filter after add a filter at any number of times.
And every time we use this method and add a filter, it will create a new place in the filter chain
of the spring security.
So now the question is.
Let's try to start this application and clearing the console.
Now, I will try to go to the UK and login into the application.
How into the credentials and clicking.
Signing the authentication will be success and the user will be navigator to the dashboard page.
Now let's try to go to the back end and see the control, whether our statement is printed or not.
And at the same time, the order of the filters in the console.
You can see in the filter chain authorities logging at filter right now.
It executer just before basic authentication filter, but it executed just after request translation
before filter.
That means the order of these two filters is not guaranteed and they can be executed in the random order.
But this before a filter and after filter will definitely be before and after these two filters.
You can also check the statement that has been printed on the console from our filter, which is authentication.
Validation is in progress.
So with this, we also learned how to create a custom filter and how to configure at the specific location
of the spring security filter.
Now we have a clear understanding on how to create a custom filters and how to configure them inside
the spring security filter chains.
As part of our requirements.
All these custom filters have been implemented by extending the filter interface from the solid package.
But for certain scenarios, Spring Security Framework also provided certain interfaces and classes which
your filter can extend and implement similar to filter interface.
Let's try to exploit such internally provided filter implementations in that next release.
Thank you.
And by.