1
00:00:00,210 --> 00:00:07,470
Now, in the previous videos, we looked at adding a filter before and after a specific spring security

2
00:00:07,470 --> 00:00:08,640
filter in this video.

3
00:00:08,680 --> 00:00:15,180
Let's try to explore of adding a filter at the same portion of it, spring security filter so we can

4
00:00:15,180 --> 00:00:22,240
add our custom own filter at the same place, our order of a specified screen security filter.

5
00:00:22,380 --> 00:00:26,960
That doesn't mean it will replace the spring security filter.

6
00:00:26,970 --> 00:00:34,500
And at the same time, we can't guarantee that either of these filters which are positioned at the same

7
00:00:34,500 --> 00:00:42,750
place and it is up to the spring security to decide randomly to execute which filter before and after

8
00:00:42,750 --> 00:00:47,490
which are located at the same position based upon our configurations.

9
00:00:47,670 --> 00:00:53,220
As you can see here, we have, of course, filter with the other one, CSIR, filter the and at the

10
00:00:53,220 --> 00:01:00,420
same time we are trying to inject our own custom filter again, logging filter at the same portion of

11
00:01:00,420 --> 00:01:07,530
basic authentication filter, and we can't guarantee which one will be executer first and which one

12
00:01:07,530 --> 00:01:13,440
will be executed after, since this is very random in nature about the execution of the filter.

13
00:01:13,680 --> 00:01:20,490
It is not recommended to use this until unless you are very confident that it will not create any issues

14
00:01:20,730 --> 00:01:27,600
in your application, regardless of the order of the execution of these filters which are configured

15
00:01:27,600 --> 00:01:29,050
at the same place.

16
00:01:29,220 --> 00:01:35,760
Let's try to explore on the back and called how we can configure a custom filter at the same portion

17
00:01:35,760 --> 00:01:37,620
of basic authentication filter.

18
00:01:37,740 --> 00:01:43,860
For the same, I have created a filter with the name authorities logging and filter which implements

19
00:01:43,860 --> 00:01:46,410
filter and already the method do filter.

20
00:01:46,500 --> 00:01:53,310
So the purpose of this filter is just to create a longer statement saying authentication validation

21
00:01:53,310 --> 00:01:54,480
is in progress.

22
00:01:54,750 --> 00:02:01,560
Once the logger has been printed onto the controller log file, it will hand over to the next filter

23
00:02:01,560 --> 00:02:06,410
inside the chain of the spring security filters creating this filter.

24
00:02:06,630 --> 00:02:14,430
We should go to our project security config and configure this custom logging filter at the same place

25
00:02:14,430 --> 00:02:19,410
of basic authentication filter by using the method and filter.

26
00:02:19,620 --> 00:02:27,630
And as you can see, we can use our filter before our filter after add a filter at any number of times.

27
00:02:27,750 --> 00:02:34,050
And every time we use this method and add a filter, it will create a new place in the filter chain

28
00:02:34,050 --> 00:02:35,290
of the spring security.

29
00:02:35,490 --> 00:02:36,490
So now the question is.

30
00:02:36,990 --> 00:02:40,080
Let's try to start this application and clearing the console.

31
00:02:40,080 --> 00:02:44,190
Now, I will try to go to the UK and login into the application.

32
00:02:44,530 --> 00:02:46,560
How into the credentials and clicking.

33
00:02:46,560 --> 00:02:52,410
Signing the authentication will be success and the user will be navigator to the dashboard page.

34
00:02:52,560 --> 00:02:58,710
Now let's try to go to the back end and see the control, whether our statement is printed or not.

35
00:02:58,830 --> 00:03:02,610
And at the same time, the order of the filters in the console.

36
00:03:02,700 --> 00:03:07,910
You can see in the filter chain authorities logging at filter right now.

37
00:03:07,920 --> 00:03:16,530
It executer just before basic authentication filter, but it executed just after request translation

38
00:03:16,530 --> 00:03:17,350
before filter.

39
00:03:17,700 --> 00:03:25,490
That means the order of these two filters is not guaranteed and they can be executed in the random order.

40
00:03:25,680 --> 00:03:32,700
But this before a filter and after filter will definitely be before and after these two filters.

41
00:03:32,730 --> 00:03:39,510
You can also check the statement that has been printed on the console from our filter, which is authentication.

42
00:03:39,510 --> 00:03:41,120
Validation is in progress.

43
00:03:41,460 --> 00:03:49,140
So with this, we also learned how to create a custom filter and how to configure at the specific location

44
00:03:49,140 --> 00:03:51,120
of the spring security filter.

45
00:03:51,330 --> 00:03:58,110
Now we have a clear understanding on how to create a custom filters and how to configure them inside

46
00:03:58,110 --> 00:04:00,210
the spring security filter chains.

47
00:04:00,270 --> 00:04:01,910
As part of our requirements.

48
00:04:02,100 --> 00:04:09,000
All these custom filters have been implemented by extending the filter interface from the solid package.

49
00:04:09,180 --> 00:04:17,640
But for certain scenarios, Spring Security Framework also provided certain interfaces and classes which

50
00:04:17,640 --> 00:04:22,370
your filter can extend and implement similar to filter interface.

51
00:04:22,530 --> 00:04:29,160
Let's try to exploit such internally provided filter implementations in that next release.

52
00:04:29,250 --> 00:04:29,790
Thank you.

53
00:04:29,790 --> 00:04:30,240
And by.

