Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +15 -0
- 03 - Advance Java/023 Try with multiple catch.mp4 +3 -0
- 03 - Advance Java/025 Exception throw keyword.mp4 +3 -0
- 03 - Advance Java/026 Custom Exception.mp4 +3 -0
- 03 - Advance Java/027 Ducking Exception using throws.mp4 +3 -0
- 03 - Advance Java/028 User Input using BufferedReader and Scanner.mp4 +3 -0
- 03 - Advance Java/029 Try with resources.mp4 +3 -0
- 03 - Advance Java/030 Threads.mp4 +3 -0
- 03 - Advance Java/031 Multiple Threads.mp4 +3 -0
- 03 - Advance Java/032 Thread Priority and Sleep.mp4 +3 -0
- 03 - Advance Java/033 Runnable vs Thread.mp4 +3 -0
- 03 - Advance Java/034 Race Condition.mp4 +3 -0
- 03 - Advance Java/035 Thread states.mp4 +3 -0
- 03 - Advance Java/036 Collection API.mp4 +3 -0
- 03 - Advance Java/038 Set.mp4 +3 -0
- 03 - Advance Java/039 Map.mp4 +3 -0
- 20 - Spring Security/014 Source-Code.url +2 -0
- 20 - Spring Security/015 without lambda_en.srt +508 -0
- 20 - Spring Security/017 Source-Code.url +2 -0
- 20 - Spring Security/017 Working with Multiple Users_en.srt +860 -0
- 20 - Spring Security/018 Source-Code.url +2 -0
- 20 - Spring Security/019 AuthenticationProvider_en.srt +536 -0
- 20 - Spring Security/019 Source-Code.url +2 -0
- 20 - Spring Security/020 Creating a UserDetailsService_en.srt +384 -0
- 20 - Spring Security/020 Source-Code.url +2 -0
- 20 - Spring Security/021 Source-Code.url +2 -0
- 20 - Spring Security/021 User Repository_en.srt +560 -0
- 20 - Spring Security/022 Source-Code.url +2 -0
- 20 - Spring Security/022 UserDetails and UserPrincipal_en.srt +732 -0
- 20 - Spring Security/023 Summary till now_en.srt +336 -0
- 20 - Spring Security/024 What is Bcrypt_en.srt +636 -0
- 20 - Spring Security/025 Source-Code.url +2 -0
- 20 - Spring Security/025 User Registration_en.srt +524 -0
- 20 - Spring Security/026 BCrypt Encoding for User Registration_en.srt +568 -0
- 20 - Spring Security/026 Source-Code.url +2 -0
- 20 - Spring Security/027 Setting Password Encoder_en.srt +312 -0
- 20 - Spring Security/027 Source-Code.url +2 -0
- 20 - Spring Security/external-links.txt +54 -0
- 21 - Securing Job App/001 Plan to secure Job App Project_en.srt +444 -0
- 21 - Securing Job App/001 Source-Code.url +2 -0
- 21 - Securing Job App/002 Cross Origin_en.srt +236 -0
- 21 - Securing Job App/003 Adding Security Configuration_en.srt +336 -0
- 21 - Securing Job App/003 Source-Code.url +2 -0
- 21 - Securing Job App/004 Job App is secure now_en.srt +652 -0
- 21 - Securing Job App/004 Source-Code.url +2 -0
- 21 - Securing Job App/external-links.txt +9 -0
- 22 - JWT (JSON Web Token) and OAuth2/001 Encryption and Decryption_en.srt +808 -0
- 22 - JWT (JSON Web Token) and OAuth2/002 Digital Signature_en.srt +384 -0
- 22 - JWT (JSON Web Token) and OAuth2/003 Why JWT_en.srt +792 -0
- 22 - JWT (JSON Web Token) and OAuth2/004 What is JWT_en.srt +696 -0
.gitattributes
CHANGED
|
@@ -119,3 +119,18 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 119 |
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/021[[:space:]]What[[:space:]]is[[:space:]]Exception.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 120 |
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/022[[:space:]]Exception[[:space:]]Handling[[:space:]]using[[:space:]]try[[:space:]]catch.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 121 |
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/024[[:space:]]Exception[[:space:]]Hierarchy.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/021[[:space:]]What[[:space:]]is[[:space:]]Exception.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 120 |
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/022[[:space:]]Exception[[:space:]]Handling[[:space:]]using[[:space:]]try[[:space:]]catch.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 121 |
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/024[[:space:]]Exception[[:space:]]Hierarchy.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 122 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/026[[:space:]]Custom[[:space:]]Exception.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 123 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/023[[:space:]]Try[[:space:]]with[[:space:]]multiple[[:space:]]catch.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 124 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/025[[:space:]]Exception[[:space:]]throw[[:space:]]keyword.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 125 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/027[[:space:]]Ducking[[:space:]]Exception[[:space:]]using[[:space:]]throws.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 126 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/030[[:space:]]Threads.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 127 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/028[[:space:]]User[[:space:]]Input[[:space:]]using[[:space:]]BufferedReader[[:space:]]and[[:space:]]Scanner.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 128 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/029[[:space:]]Try[[:space:]]with[[:space:]]resources.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 129 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/033[[:space:]]Runnable[[:space:]]vs[[:space:]]Thread.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 130 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/032[[:space:]]Thread[[:space:]]Priority[[:space:]]and[[:space:]]Sleep.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 131 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/031[[:space:]]Multiple[[:space:]]Threads.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 132 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/035[[:space:]]Thread[[:space:]]states.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 133 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/036[[:space:]]Collection[[:space:]]API.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 134 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/034[[:space:]]Race[[:space:]]Condition.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 135 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/038[[:space:]]Set.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 136 |
+
03[[:space:]]-[[:space:]]Advance[[:space:]]Java/039[[:space:]]Map.mp4 filter=lfs diff=lfs merge=lfs -text
|
03 - Advance Java/023 Try with multiple catch.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1f988a6ed0ec641c94c27b4b6252b496c111eea476c39b18d38309631d4148dc
|
| 3 |
+
size 167982266
|
03 - Advance Java/025 Exception throw keyword.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2fb6e52386d60ca774bb779ff2f7d6c822661b049ed490e2a1a908d74368a907
|
| 3 |
+
size 85661874
|
03 - Advance Java/026 Custom Exception.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:360c76766d1d27936c3129d0805bb7d9602c74e98e8c6ac15a2eb6fb70d8a5c4
|
| 3 |
+
size 57640187
|
03 - Advance Java/027 Ducking Exception using throws.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b41a418266b17b878378aae5c107356f66f495f411402d3ab287887ab58a2908
|
| 3 |
+
size 153426306
|
03 - Advance Java/028 User Input using BufferedReader and Scanner.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d9a89d35133823d2aa7e3f0718acab9b2fc4fb7d18014a1419101054682b9004
|
| 3 |
+
size 192332565
|
03 - Advance Java/029 Try with resources.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:916f1b53ebfbf8196b3b1b4019ad984d67d366e9a002e7eff6e5ef8a99cdd6dc
|
| 3 |
+
size 183484229
|
03 - Advance Java/030 Threads.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:547e1e1f623c078c26fff840f6b93263b67031219c1dbaa13b14d6bc321f8d53
|
| 3 |
+
size 98408255
|
03 - Advance Java/031 Multiple Threads.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:146c9d273f172eb2a3e90bacbb4414b9d4afafe150522218caa158c8632e20fd
|
| 3 |
+
size 184310750
|
03 - Advance Java/032 Thread Priority and Sleep.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:777c1df34bd13a9eda84126f9dceb0d025ef7ba0f73680b176d657f91ba4b243
|
| 3 |
+
size 173252287
|
03 - Advance Java/033 Runnable vs Thread.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:024169cd5ed6385f02b7a12458bb3cc1472248e21c856b3a652e07f9e8be24d1
|
| 3 |
+
size 136365684
|
03 - Advance Java/034 Race Condition.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:63673eee1ab38f427338e0eec3392ab330cd608bc1e07799c6912c0ce59b93d2
|
| 3 |
+
size 204923140
|
03 - Advance Java/035 Thread states.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:61f6ded70f9bb617444ed59a714cfacd5626a8e7d3b225854e2933648a7f1715
|
| 3 |
+
size 61505378
|
03 - Advance Java/036 Collection API.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3b4ab013c00446a8e21d822a627d8fe674e1605481a990e48180f65bb593deae
|
| 3 |
+
size 67323726
|
03 - Advance Java/038 Set.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:52618955195ec0401c5e99c35c450c78d31c94cc6246d0c5866743a36766c929
|
| 3 |
+
size 115117359
|
03 - Advance Java/039 Map.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d030d7af0240655a75ca7176f71ac243a6c610503d0f7d158f1c94cb550d8495
|
| 3 |
+
size 161660550
|
20 - Spring Security/014 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.14%20Disabling%20Csrf%20Token/spring-sec-demo
|
20 - Spring Security/015 without lambda_en.srt
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:02,000
|
| 3 |
+
(upbeat music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:02,000 --> 00:00:06,000
|
| 7 |
+
-: So now let's convert this code into imperial style.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:06,000 --> 00:00:08,000
|
| 11 |
+
So I mean normal style.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:08,000 --> 00:00:10,000
|
| 15 |
+
So what I'm going to do is let's comment
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:10,000 --> 00:00:13,000
|
| 19 |
+
this entire section, in fact till here, okay?
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:13,000 --> 00:00:15,000
|
| 23 |
+
And now let's work one by one.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:15,000 --> 00:00:19,000
|
| 27 |
+
So first thing we have to address is http.csrf.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:20,000 --> 00:00:24,000
|
| 31 |
+
Now if you can see, if we talk about CSRF,
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:24,000 --> 00:00:25,000
|
| 35 |
+
it takes a parameter of customizer
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:25,000 --> 00:00:30,000
|
| 39 |
+
and of type CSRF, configure of type HttpSecurity.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:30,000 --> 00:00:32,000
|
| 43 |
+
So basically we have some types there.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:32,000 --> 00:00:35,000
|
| 47 |
+
So customizer takes a type of CsrfConfigurer,
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:35,000 --> 00:00:38,000
|
| 51 |
+
which takes a type of HttpSecurity.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:38,000 --> 00:00:40,000
|
| 55 |
+
So what I'm going to do is we create an object of that
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:40,000 --> 00:00:42,000
|
| 59 |
+
and let's pause it here.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:42,000 --> 00:00:46,000
|
| 63 |
+
So we have to get object of customizer of type
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:46,000 --> 00:00:51,000
|
| 67 |
+
CsrfConfigurerr of type HttpSecurity
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:52,000 --> 00:00:57,000
|
| 71 |
+
and then I will say this is customized CSRF equal to new.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:58,000 --> 00:01:00,000
|
| 75 |
+
And we get the object for the same thing.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:01:00,000 --> 00:01:03,000
|
| 79 |
+
And you can see we got the object.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:01:03,000 --> 00:01:05,000
|
| 83 |
+
But the thing is customize itself is interface, right?
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:01:05,000 --> 00:01:07,000
|
| 87 |
+
So if you want to get the object of it,
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:07,000 --> 00:01:09,000
|
| 91 |
+
we have to use anonymous in a class.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:09,000 --> 00:01:10,000
|
| 95 |
+
That's what I'm doing here.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:10,000 --> 00:01:13,000
|
| 99 |
+
And in this interface we only have one method.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:13,000 --> 00:01:15,000
|
| 103 |
+
If you can see the method name is customize.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:15,000 --> 00:01:18,000
|
| 107 |
+
So what I can do is I can just define that meta customize
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:18,000 --> 00:01:21,000
|
| 111 |
+
and okay, that's the object we have created.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:21,000 --> 00:01:25,000
|
| 115 |
+
So the object name is, or the reference name is custCsrf
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:25,000 --> 00:01:29,000
|
| 119 |
+
and we have to pass that custCsrf here.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:29,000 --> 00:01:31,000
|
| 123 |
+
Okay, so CSRF says you can configure me
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:31,000 --> 00:01:33,000
|
| 127 |
+
by passing the object of this
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:33,000 --> 00:01:36,000
|
| 131 |
+
and this the object type is customizer
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:36,000 --> 00:01:40,000
|
| 135 |
+
with the type CsrfConfigurer HttpSecurity.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:40,000 --> 00:01:42,000
|
| 139 |
+
Now if you're thinking, do we have to remember this?
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:42,000 --> 00:01:44,000
|
| 143 |
+
Not exactly anywhere when you are actually going to build,
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:44,000 --> 00:01:47,000
|
| 147 |
+
we will be using the lambda expression,
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:47,000 --> 00:01:48,000
|
| 151 |
+
not this type of code.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:48,000 --> 00:01:49,000
|
| 155 |
+
I'm just showing you this
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:49,000 --> 00:01:51,000
|
| 159 |
+
so that you can understand what is happening.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:51,000 --> 00:01:53,000
|
| 163 |
+
So in this particular object creation,
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:53,000 --> 00:01:54,000
|
| 167 |
+
we are using a method called customize
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:54,000 --> 00:01:56,000
|
| 171 |
+
because that's the only method you have,
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:56,000 --> 00:01:59,000
|
| 175 |
+
which takes a parameter of CsrfConfigurer,
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:59,000 --> 00:02:02,000
|
| 179 |
+
which we are passing here of type HTTP.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:02:02,000 --> 00:02:04,000
|
| 183 |
+
And in this you can do the configuration.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:02:04,000 --> 00:02:07,000
|
| 187 |
+
So what I will do is instead of saying this big name,
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:02:07,000 --> 00:02:09,000
|
| 191 |
+
I will say configure.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:02:09,000 --> 00:02:12,000
|
| 195 |
+
And then using that object of configure,
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:02:12,000 --> 00:02:13,000
|
| 199 |
+
I can simply say disable.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:02:13,000 --> 00:02:15,000
|
| 203 |
+
Okay, so whatever you want to do
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:15,000 --> 00:02:16,000
|
| 207 |
+
with this configure, you can do that.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:16,000 --> 00:02:19,000
|
| 211 |
+
You can set different properties or settings.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:19,000 --> 00:02:22,000
|
| 215 |
+
I'm just saying disable and the same thing I'm passing here.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:22,000 --> 00:02:25,000
|
| 219 |
+
So this one line of code is actually doing all this.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:25,000 --> 00:02:27,000
|
| 223 |
+
Again, if you are good with lambda, you don't even have
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:27,000 --> 00:02:29,000
|
| 227 |
+
to watch this video, you can skip it.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:29,000 --> 00:02:32,000
|
| 231 |
+
But I'm just trying to make you understand how we got this
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:32,000 --> 00:02:34,000
|
| 235 |
+
because when I saw this for the first time, I was like "hey,
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:34,000 --> 00:02:36,000
|
| 239 |
+
what's happening behind the scene".
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:36,000 --> 00:02:37,000
|
| 243 |
+
And this is what is happening.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:37,000 --> 00:02:41,000
|
| 247 |
+
Okay, next let's talk about the authorized HTTP request.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:41,000 --> 00:02:42,000
|
| 251 |
+
The same thing we can do there.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:42,000 --> 00:02:46,000
|
| 255 |
+
So we have to say HTTP dot authorize HTTP request,
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:46,000 --> 00:02:50,000
|
| 259 |
+
and even this needs object of customizer.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:50,000 --> 00:02:54,000
|
| 263 |
+
So if you go there, you can see this particular method needs
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:54,000 --> 00:02:55,000
|
| 267 |
+
object of customizer
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:55,000 --> 00:02:59,000
|
| 271 |
+
but of type authorized HTTP request configure
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:59,000 --> 00:03:01,000
|
| 275 |
+
of type HttpSecurity, big names, right?
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:03:01,000 --> 00:03:03,000
|
| 279 |
+
And that's why we prefer to go with Lambda there.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:03:03,000 --> 00:03:05,000
|
| 283 |
+
So for this we have to create the object,
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:03:05,000 --> 00:03:10,000
|
| 287 |
+
I will say customizer of type authorized HTTP request,
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:03:10,000 --> 00:03:13,000
|
| 291 |
+
configure of type HttpSecurity.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:03:13,000 --> 00:03:16,000
|
| 295 |
+
And then again you have to say dot the actual object we have
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:03:16,000 --> 00:03:21,000
|
| 299 |
+
create is authorized manager request manager registry.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:03:21,000 --> 00:03:26,000
|
| 303 |
+
And for this we'll create object of cost HTTP
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:03:26,000 --> 00:03:30,000
|
| 307 |
+
equal to new, the same thing.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:03:30,000 --> 00:03:32,000
|
| 311 |
+
And you can see it's very lengthy name, right?
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:03:32,000 --> 00:03:34,000
|
| 315 |
+
And no one want to remember this.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:34,000 --> 00:03:36,000
|
| 319 |
+
So you can see it's such a big name.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:36,000 --> 00:03:38,000
|
| 323 |
+
So you have to get object of customizer with this type
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:38,000 --> 00:03:41,000
|
| 327 |
+
of authorized manager request match registry.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:41,000 --> 00:03:43,000
|
| 331 |
+
And once you have this object,
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:43,000 --> 00:03:45,000
|
| 335 |
+
because that's the object we have to pass here,
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:45,000 --> 00:03:47,000
|
| 339 |
+
which is custHttp.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:47,000 --> 00:03:50,000
|
| 343 |
+
And here in this bracket or in this definition,
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:50,000 --> 00:03:54,000
|
| 347 |
+
I will say what was the method name registry.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:54,000 --> 00:03:57,000
|
| 351 |
+
So I'll say registry dot
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:57,000 --> 00:04:00,000
|
| 355 |
+
for every request dot authenticated.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:04:00,000 --> 00:04:03,000
|
| 359 |
+
So basically I'm saying get authenticated
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:04:03,000 --> 00:04:05,000
|
| 363 |
+
and that's how we can basically pass this.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:04:05,000 --> 00:04:08,000
|
| 367 |
+
Yeah, so this is basically your imperative style
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:04:08,000 --> 00:04:11,000
|
| 371 |
+
of writing this, not a good idea, right?
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:04:11,000 --> 00:04:13,000
|
| 375 |
+
But then now you know which classes are involved
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:04:13,000 --> 00:04:16,000
|
| 379 |
+
behind the scene, okay?
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:04:16,000 --> 00:04:20,000
|
| 383 |
+
And preferably we'll be using the lambda.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:04:20,000 --> 00:04:23,000
|
| 387 |
+
So this is only for showing you how things looks like,
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:04:23,000 --> 00:04:26,000
|
| 391 |
+
but this is not the actual way of writing code here.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:04:26,000 --> 00:04:28,000
|
| 395 |
+
I would still prefer the lambda.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:04:28,000 --> 00:04:30,000
|
| 399 |
+
Let me just uncomment this.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:04:30,000 --> 00:04:32,000
|
| 403 |
+
For the session, also, we have the same thing.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:04:32,000 --> 00:04:33,000
|
| 407 |
+
You can explore session management.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:04:33,000 --> 00:04:36,000
|
| 411 |
+
We have to create object of customizer session management,
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:04:36,000 --> 00:04:39,000
|
| 415 |
+
configure which of type HttpSecurity and this will work.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:04:39,000 --> 00:04:42,000
|
| 419 |
+
There's one more way of doing this since HTTP
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:04:42,000 --> 00:04:43,000
|
| 423 |
+
follows a buildup pattern.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:04:43,000 --> 00:04:44,000
|
| 427 |
+
Instead of writing all this multiple times,
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:44,000 --> 00:04:48,000
|
| 431 |
+
what you can do is you can HTTP dot CSRF
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:48,000 --> 00:04:50,000
|
| 435 |
+
and then you can say DOT with the same thing.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:50,000 --> 00:04:52,000
|
| 439 |
+
So this is a buildup pattern so you don't have
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:52,000 --> 00:04:54,000
|
| 443 |
+
to mention semicolon there at the end.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:54,000 --> 00:04:57,000
|
| 447 |
+
So we are confidentiality HTTP for CSRF first,
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:57,000 --> 00:05:01,000
|
| 451 |
+
then authorized request and then dot HTTP
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:05:01,000 --> 00:05:03,000
|
| 455 |
+
and then dot session management.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:05:03,000 --> 00:05:06,000
|
| 459 |
+
So you can see we are doing this in a line now
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:05:06,000 --> 00:05:07,000
|
| 463 |
+
and that's what we can do.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:05:07,000 --> 00:05:10,000
|
| 467 |
+
In fact, if you want, you can see at the end dot build
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:05:10,000 --> 00:05:11,000
|
| 471 |
+
and return that object itself
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:05:11,000 --> 00:05:12,000
|
| 475 |
+
instead of doing all those things.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:05:12,000 --> 00:05:14,000
|
| 479 |
+
And that's why most of the time you will see this type
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:05:14,000 --> 00:05:16,000
|
| 483 |
+
of configuration or somewhere you can also see this in a new
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:05:16,000 --> 00:05:20,000
|
| 487 |
+
line if you want just to make things visible.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:05:20,000 --> 00:05:23,000
|
| 491 |
+
So yeah, that's how we can configure the CSRF disable
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:05:23,000 --> 00:05:24,000
|
| 495 |
+
and other things here.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:05:24,000 --> 00:05:27,000
|
| 499 |
+
There are many, many configuration which we can do.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:05:27,000 --> 00:05:29,000
|
| 503 |
+
Maybe having multiple username password, not just one.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:05:29,000 --> 00:05:32,000
|
| 507 |
+
But how do you do that, let's say in the upcoming videos.
|
| 508 |
+
|
20 - Spring Security/017 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.17%20Working%20With%20Multiple%20Users/spring-sec-demo
|
20 - Spring Security/017 Working with Multiple Users_en.srt
ADDED
|
@@ -0,0 +1,860 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:06,000
|
| 11 |
+
that we can have multiple users
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:06,000 --> 00:00:09,000
|
| 15 |
+
and of course we want the users coming from database,
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:09,000 --> 00:00:11,000
|
| 19 |
+
but then we'll go step by step so that it'll make sense.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:11,000 --> 00:00:14,000
|
| 23 |
+
The first thing we will do is let's hardcode the username
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:14,000 --> 00:00:17,000
|
| 27 |
+
password values, not from database,
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:17,000 --> 00:00:19,000
|
| 31 |
+
but let's hardcode them here in the code.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:19,000 --> 00:00:21,000
|
| 35 |
+
And I don't want to use this username password now.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:21,000 --> 00:00:24,000
|
| 39 |
+
The way you can achieve that, if you go back
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:24,000 --> 00:00:25,000
|
| 43 |
+
to your security configuration,
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:25,000 --> 00:00:28,000
|
| 47 |
+
and if you don't mention anything here by default,
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:28,000 --> 00:00:30,000
|
| 51 |
+
the spring security uses something called
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:30,000 --> 00:00:32,000
|
| 55 |
+
a UserDetailsService.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:32,000 --> 00:00:35,000
|
| 59 |
+
Now it uses this class to basically check
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:35,000 --> 00:00:38,000
|
| 63 |
+
for your application properties
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:38,000 --> 00:00:39,000
|
| 67 |
+
and see do you have username password there?
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:39,000 --> 00:00:42,000
|
| 71 |
+
If yes, it will use it, but I don't want to use that.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:42,000 --> 00:00:46,000
|
| 75 |
+
I want to define my own UserDetailsService.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:46,000 --> 00:00:50,000
|
| 79 |
+
So what we will do is let's create a bean which will
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:50,000 --> 00:00:53,000
|
| 83 |
+
return a UserDetailsService object.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:53,000 --> 00:00:57,000
|
| 87 |
+
And I can say this is UserDetailsService method, okay?
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:57,000 --> 00:00:59,000
|
| 91 |
+
So basically I want to return the object
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:59,000 --> 00:01:02,000
|
| 95 |
+
of user detail service and I want this to be bean.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:02,000 --> 00:01:05,000
|
| 99 |
+
Now what will happen is your spring security will look at
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:05,000 --> 00:01:08,000
|
| 103 |
+
this particular object to get the data for the user.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:08,000 --> 00:01:10,000
|
| 107 |
+
So whatever data you're going to return on this,
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:10,000 --> 00:01:13,000
|
| 111 |
+
will be your actual data where a spring security will check.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:13,000 --> 00:01:15,000
|
| 115 |
+
Okay, makes sense, but how do you return the data?
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:15,000 --> 00:01:17,000
|
| 119 |
+
How do I specify the users?
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:17,000 --> 00:01:20,000
|
| 123 |
+
And basically how can I return this user detail service?
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:20,000 --> 00:01:23,000
|
| 127 |
+
Now if you go back to user detail service,
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:23,000 --> 00:01:24,000
|
| 131 |
+
it's an interface, right?
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:24,000 --> 00:01:27,000
|
| 135 |
+
And it has a method called load user by the username, okay?
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:27,000 --> 00:01:29,000
|
| 139 |
+
So this is a method which is getting used behind the scene.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:29,000 --> 00:01:34,000
|
| 143 |
+
Our concern is this particular interface, it's an interface.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:34,000 --> 00:01:36,000
|
| 147 |
+
First of all, it has a method which returns the object
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:36,000 --> 00:01:37,000
|
| 151 |
+
of user detail service.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:37,000 --> 00:01:40,000
|
| 155 |
+
So for us, the two important thing is this interface name
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:40,000 --> 00:01:43,000
|
| 159 |
+
and it returns return type, which is user details.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:43,000 --> 00:01:44,000
|
| 163 |
+
If I go back here
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:44,000 --> 00:01:47,000
|
| 167 |
+
and if I try to understand how do I create an object
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:47,000 --> 00:01:52,000
|
| 171 |
+
for this, of course we don't want to get our own class now.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:52,000 --> 00:01:54,000
|
| 175 |
+
There is an inbuilt class which we can use.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:54,000 --> 00:01:55,000
|
| 179 |
+
So I can simply say return.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:55,000 --> 00:01:57,000
|
| 183 |
+
And the name of the inbuilt class is, if you can see,
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:57,000 --> 00:02:02,000
|
| 187 |
+
we have something called InMemoryUserDetailsManager.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:02:02,000 --> 00:02:05,000
|
| 191 |
+
So we are going to use this because this particular object,
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:02:05,000 --> 00:02:09,000
|
| 195 |
+
and if you see this implements, user details manager,
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:02:09,000 --> 00:02:11,000
|
| 199 |
+
which extends user detail service.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:02:11,000 --> 00:02:14,000
|
| 203 |
+
So indirectly, this particular class,
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:14,000 --> 00:02:16,000
|
| 207 |
+
which is InMemoryUserDetailsManager
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:16,000 --> 00:02:17,000
|
| 211 |
+
implements the user detail service.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:17,000 --> 00:02:19,000
|
| 215 |
+
So our job is done because if you can return the object
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:19,000 --> 00:02:21,000
|
| 219 |
+
of this indirectly hitting the object
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:21,000 --> 00:02:23,000
|
| 223 |
+
of user detail service, okay,
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:23,000 --> 00:02:26,000
|
| 227 |
+
but then we don't want to return the empty object, right?
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:26,000 --> 00:02:28,000
|
| 231 |
+
We have to specify some values.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:28,000 --> 00:02:31,000
|
| 235 |
+
Let's try, and I want to really check if this works.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:31,000 --> 00:02:35,000
|
| 239 |
+
If I do this, it should not even accept the username
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:35,000 --> 00:02:36,000
|
| 243 |
+
and password which is
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:36,000 --> 00:02:38,000
|
| 247 |
+
specified in the application properties.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:38,000 --> 00:02:41,000
|
| 251 |
+
Let's try it out, so I hope this will, okay,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:41,000 --> 00:02:43,000
|
| 255 |
+
I will just manually restart sometime.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:43,000 --> 00:02:45,000
|
| 259 |
+
We don't trust the hard reload,
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:45,000 --> 00:02:46,000
|
| 263 |
+
especially when you're experimenting.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:46,000 --> 00:02:48,000
|
| 267 |
+
Okay, reload, done, let me go back to the browser
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:48,000 --> 00:02:50,000
|
| 271 |
+
and again, I will go for the incognito mode.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:52,000 --> 00:02:55,000
|
| 275 |
+
And here let's specify localized 8080.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:55,000 --> 00:02:58,000
|
| 279 |
+
It'll give you a prompt and now I will specify Telusko.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:58,000 --> 00:03:01,000
|
| 283 |
+
And 1, 2, 3, 4, enter, it's not working.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:03:01,000 --> 00:03:02,000
|
| 287 |
+
So basically the username, password,
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:03:02,000 --> 00:03:04,000
|
| 291 |
+
which you have mentioned in the application properties
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:03:04,000 --> 00:03:06,000
|
| 295 |
+
is not getting read.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:03:06,000 --> 00:03:08,000
|
| 299 |
+
Okay, so now let's specify the values here.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:03:08,000 --> 00:03:10,000
|
| 303 |
+
Now how do I specify the values?
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:03:10,000 --> 00:03:13,000
|
| 307 |
+
See in this constructor of InMemoryUserDetailsManager,
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:03:13,000 --> 00:03:16,000
|
| 311 |
+
if you click here, you can see it has multiple constructors.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:03:16,000 --> 00:03:20,000
|
| 315 |
+
One of the constructor is this, a collection of users.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:20,000 --> 00:03:22,000
|
| 319 |
+
If you don't want to pass a collection,
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:22,000 --> 00:03:25,000
|
| 323 |
+
you can also pass a variable length arguments,
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:25,000 --> 00:03:26,000
|
| 327 |
+
which is with Varargs,
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:26,000 --> 00:03:28,000
|
| 331 |
+
and you can pass multiple users.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:28,000 --> 00:03:29,000
|
| 335 |
+
So I want to use this particular constructor
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:29,000 --> 00:03:33,000
|
| 339 |
+
and I can pass any number of users I want.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:33,000 --> 00:03:34,000
|
| 343 |
+
And what object, what type of object
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:34,000 --> 00:03:37,000
|
| 347 |
+
you wanna return, the user details object.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:37,000 --> 00:03:39,000
|
| 351 |
+
So that means here, even if you want
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:39,000 --> 00:03:41,000
|
| 355 |
+
to create one particular user, you have
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:41,000 --> 00:03:42,000
|
| 359 |
+
to create object of user details.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:42,000 --> 00:03:44,000
|
| 363 |
+
Here I would say user is equal to,
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:44,000 --> 00:03:46,000
|
| 367 |
+
I should be importing this package.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:46,000 --> 00:03:48,000
|
| 371 |
+
I think it's already done.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:48,000 --> 00:03:50,000
|
| 375 |
+
And now how do I create the object of this?
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:50,000 --> 00:03:54,000
|
| 379 |
+
If you go back to user details, oh, this is also interface.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:54,000 --> 00:03:56,000
|
| 383 |
+
I mean it's all coded for the interface, no problem.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:56,000 --> 00:04:00,000
|
| 387 |
+
We'll go back here and there's a class called user.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:04:00,000 --> 00:04:03,000
|
| 391 |
+
Okay, so the way we have user details, we also have user,
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:04:03,000 --> 00:04:07,000
|
| 395 |
+
and this particular class, it has multiple methods.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:04:07,000 --> 00:04:09,000
|
| 399 |
+
It returns object of user builder,
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:04:09,000 --> 00:04:11,000
|
| 403 |
+
if you can see, and user builder.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:04:11,000 --> 00:04:14,000
|
| 407 |
+
So it has a method called build, which returns user details.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:04:14,000 --> 00:04:17,000
|
| 411 |
+
And of course you don't have to remember every flow here,
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:04:17,000 --> 00:04:22,000
|
| 415 |
+
just imagine the user has a method called user builder,
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:04:22,000 --> 00:04:24,000
|
| 419 |
+
I mean a builder.build.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:04:24,000 --> 00:04:26,000
|
| 423 |
+
So basically user.builder.build will give
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:04:26,000 --> 00:04:27,000
|
| 427 |
+
you the object of user details.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:27,000 --> 00:04:28,000
|
| 431 |
+
But then this is empty, right?
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:28,000 --> 00:04:30,000
|
| 435 |
+
We don't want to go with empty one.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:30,000 --> 00:04:31,000
|
| 439 |
+
I want to specify some values to it.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:31,000 --> 00:04:33,000
|
| 443 |
+
So the first thing we have to mention
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:33,000 --> 00:04:34,000
|
| 447 |
+
is the password encoder.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:34,000 --> 00:04:36,000
|
| 451 |
+
As I mentioned before, you don't want
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:36,000 --> 00:04:38,000
|
| 455 |
+
to store your password in a plain text.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:38,000 --> 00:04:40,000
|
| 459 |
+
You want to store that in a encoded format.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:40,000 --> 00:04:42,000
|
| 463 |
+
So this, to start with, let's not do any encoding.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:42,000 --> 00:04:45,000
|
| 467 |
+
I will go for a default password encoder, this one.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:45,000 --> 00:04:48,000
|
| 471 |
+
So what I'm doing is I'm saying, "Hey, I'm going
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:48,000 --> 00:04:49,000
|
| 475 |
+
for a default password encoder
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:49,000 --> 00:04:51,000
|
| 479 |
+
and now I want to specify my username".
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:51,000 --> 00:04:54,000
|
| 483 |
+
So you can say .username and you can mention the username.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:54,000 --> 00:04:55,000
|
| 487 |
+
So let's say I want to go for username
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:55,000 --> 00:04:57,000
|
| 491 |
+
as navin and then you can say dot.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:57,000 --> 00:04:58,000
|
| 495 |
+
You can also set the password.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:58,000 --> 00:05:01,000
|
| 499 |
+
I want to set the password as n@123.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:05:01,000 --> 00:05:03,000
|
| 503 |
+
That's a password, and then if you want,
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:05:03,000 --> 00:05:05,000
|
| 507 |
+
you can also specify the roles
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:05:05,000 --> 00:05:07,000
|
| 511 |
+
and you can specify multiple roles here.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:05:07,000 --> 00:05:11,000
|
| 515 |
+
So if navin, I wanted to be admin as well as I want navin
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:05:11,000 --> 00:05:15,000
|
| 519 |
+
to be user, I can specify both,
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:05:15,000 --> 00:05:16,000
|
| 523 |
+
but at this point, let's say I want
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:05:16,000 --> 00:05:17,000
|
| 527 |
+
to specify only one thing,
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:05:17,000 --> 00:05:18,000
|
| 531 |
+
and that too makes sense if you have
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:05:18,000 --> 00:05:20,000
|
| 535 |
+
in the capital, so it's a user.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:05:20,000 --> 00:05:22,000
|
| 539 |
+
And then at the end you can say build
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:22,000 --> 00:05:24,000
|
| 543 |
+
because build returns object of user details.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:24,000 --> 00:05:26,000
|
| 547 |
+
And that's what we want, right?
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:26,000 --> 00:05:27,000
|
| 551 |
+
Now if you want this to look good,
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:27,000 --> 00:05:29,000
|
| 555 |
+
what you can also do is at this point you can say enter just
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:29,000 --> 00:05:32,000
|
| 559 |
+
like a buildup pattern and you can say enter here.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:05:32,000 --> 00:05:35,000
|
| 563 |
+
So at least it'll make it much more readable
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:05:35,000 --> 00:05:37,000
|
| 567 |
+
compared to the earlier one.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:05:37,000 --> 00:05:40,000
|
| 571 |
+
And if you try to read now what it says is,
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:05:40,000 --> 00:05:44,000
|
| 575 |
+
we got a user in which we have a chain of methods.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:05:44,000 --> 00:05:45,000
|
| 579 |
+
We are going for a default password encoder.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:05:45,000 --> 00:05:47,000
|
| 583 |
+
Then we are going for the username, password,
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:05:47,000 --> 00:05:49,000
|
| 587 |
+
roles and build.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:05:49,000 --> 00:05:51,000
|
| 591 |
+
And this particular object, the user object,
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:05:51,000 --> 00:05:52,000
|
| 595 |
+
I can simply pass here
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:05:52,000 --> 00:05:56,000
|
| 599 |
+
because that's how we can pass the object of user details
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:05:56,000 --> 00:05:58,000
|
| 603 |
+
to the constructor here.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:05:58,000 --> 00:06:00,000
|
| 607 |
+
And you can pass multiple objects, not just one user.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:06:00,000 --> 00:06:02,000
|
| 611 |
+
You can create multiple user details, object,
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:06:02,000 --> 00:06:04,000
|
| 615 |
+
and you can pass it here for multiple users.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:06:04,000 --> 00:06:06,000
|
| 619 |
+
And now let's talk about this.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:06:06,000 --> 00:06:08,000
|
| 623 |
+
What is this with default password encoder?
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:06:08,000 --> 00:06:11,000
|
| 627 |
+
Now basically this is a method which says I don't want to go
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:06:11,000 --> 00:06:13,000
|
| 631 |
+
for any encoder at this point.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:06:13,000 --> 00:06:15,000
|
| 635 |
+
Later on we'll move to different encoders,
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:06:15,000 --> 00:06:16,000
|
| 639 |
+
but at this point we're not using it.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:06:16,000 --> 00:06:18,000
|
| 643 |
+
But again, not recommended.
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:06:18,000 --> 00:06:20,000
|
| 647 |
+
And that's why it says it is deprecated.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:06:20,000 --> 00:06:22,000
|
| 651 |
+
We should not be using this in the production
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:06:22,000 --> 00:06:23,000
|
| 655 |
+
or I mean it,
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:06:23,000 --> 00:06:25,000
|
| 659 |
+
you should be only using it while learning purpose.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:06:25,000 --> 00:06:27,000
|
| 663 |
+
Never use it for even for experiments.
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:06:27,000 --> 00:06:29,000
|
| 667 |
+
Sometime yes, you want
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:06:29,000 --> 00:06:30,000
|
| 671 |
+
to check if everything is flowing well
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:06:30,000 --> 00:06:33,000
|
| 675 |
+
and you have a pathway in database.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:06:33,000 --> 00:06:35,000
|
| 679 |
+
And if you want to verify, that's when you can do it,
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:06:35,000 --> 00:06:37,000
|
| 683 |
+
but not in a normal scenario.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:06:37,000 --> 00:06:39,000
|
| 687 |
+
Okay, so we got a user and I can do the same thing.
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:06:39,000 --> 00:06:43,000
|
| 691 |
+
Let's say I want to have one more user here, which is this.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:06:43,000 --> 00:06:46,000
|
| 695 |
+
And I can say this is user, maybe I want
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:06:46,000 --> 00:06:48,000
|
| 699 |
+
to create an admin now with default encoder.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:06:48,000 --> 00:06:50,000
|
| 703 |
+
And I will say, let's execute in,
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:06:50,000 --> 00:06:52,000
|
| 707 |
+
or maybe I can have admin itself.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:06:52,000 --> 00:06:56,000
|
| 711 |
+
And the password I want to go for is admin@789.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:06:58,000 --> 00:07:00,000
|
| 715 |
+
And the goal I want to give here is admin, okay?
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:07:00,000 --> 00:07:02,000
|
| 719 |
+
That's how we can create another user here.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:07:02,000 --> 00:07:05,000
|
| 723 |
+
And here we can pass admin as well.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:07:05,000 --> 00:07:06,000
|
| 727 |
+
So depending upon how many objects you have,
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:07:06,000 --> 00:07:08,000
|
| 731 |
+
we can pass those objects here.
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:07:08,000 --> 00:07:11,000
|
| 735 |
+
Now I hope this will work, let me relaunch again.
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:07:11,000 --> 00:07:16,000
|
| 739 |
+
I don't trust the hot reloads, so it's launching.
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:07:16,000 --> 00:07:18,000
|
| 743 |
+
I will go back to my browser, refresh.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:07:18,000 --> 00:07:20,000
|
| 747 |
+
Okay, so we're not started yet.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:07:20,000 --> 00:07:22,000
|
| 751 |
+
So I was started and now here I will say,
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:07:22,000 --> 00:07:24,000
|
| 755 |
+
let me try Telusko once again.
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:07:24,000 --> 00:07:26,000
|
| 759 |
+
And I would say 1234, not working.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:07:26,000 --> 00:07:28,000
|
| 763 |
+
Let me say Navin and the password,
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:07:28,000 --> 00:07:30,000
|
| 767 |
+
I will just enter a random password, which is incorrect.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:07:30,000 --> 00:07:32,000
|
| 771 |
+
Sign in not working.
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:07:32,000 --> 00:07:37,000
|
| 775 |
+
Again, I will send Navin and the password is n@123,
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:07:37,000 --> 00:07:39,000
|
| 779 |
+
sign in, worked, okay?
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:07:39,000 --> 00:07:42,000
|
| 783 |
+
So whatever details
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:07:42,000 --> 00:07:43,000
|
| 787 |
+
or whatever username password you mentioned,
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:07:43,000 --> 00:07:45,000
|
| 791 |
+
you can use that here.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:07:45,000 --> 00:07:47,000
|
| 795 |
+
What if I wanna try with admin, let's try.
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:07:47,000 --> 00:07:49,000
|
| 799 |
+
So that's the new incognito mode.
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:07:49,000 --> 00:07:53,000
|
| 803 |
+
I would say admin, password is admin@789.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:07:53,000 --> 00:07:55,000
|
| 807 |
+
Enter, it worked.
|
| 808 |
+
|
| 809 |
+
203
|
| 810 |
+
00:07:55,000 --> 00:07:56,000
|
| 811 |
+
So basically whatever username password
|
| 812 |
+
|
| 813 |
+
204
|
| 814 |
+
00:07:56,000 --> 00:07:58,000
|
| 815 |
+
you mentioned here, it will work.
|
| 816 |
+
|
| 817 |
+
205
|
| 818 |
+
00:07:58,000 --> 00:07:59,000
|
| 819 |
+
But again, this is not coming from database.
|
| 820 |
+
|
| 821 |
+
206
|
| 822 |
+
00:07:59,000 --> 00:08:01,000
|
| 823 |
+
Let's see, how do you make it work
|
| 824 |
+
|
| 825 |
+
207
|
| 826 |
+
00:08:01,000 --> 00:08:03,000
|
| 827 |
+
with the database in the upcoming videos.
|
| 828 |
+
|
| 829 |
+
208
|
| 830 |
+
00:08:03,000 --> 00:08:05,000
|
| 831 |
+
But at this point, what we are doing is we are not going
|
| 832 |
+
|
| 833 |
+
209
|
| 834 |
+
00:08:05,000 --> 00:08:07,000
|
| 835 |
+
for a default implementation of user detail service.
|
| 836 |
+
|
| 837 |
+
210
|
| 838 |
+
00:08:07,000 --> 00:08:09,000
|
| 839 |
+
We are defining it by ourself.
|
| 840 |
+
|
| 841 |
+
211
|
| 842 |
+
00:08:09,000 --> 00:08:11,000
|
| 843 |
+
And the way you can do that is by returning the object
|
| 844 |
+
|
| 845 |
+
212
|
| 846 |
+
00:08:11,000 --> 00:08:14,000
|
| 847 |
+
of InMemoryUserDetailsManager.
|
| 848 |
+
|
| 849 |
+
213
|
| 850 |
+
00:08:14,000 --> 00:08:16,000
|
| 851 |
+
And we are returning these two objects.
|
| 852 |
+
|
| 853 |
+
214
|
| 854 |
+
00:08:16,000 --> 00:08:18,000
|
| 855 |
+
So yeah, that's it from this video.
|
| 856 |
+
|
| 857 |
+
215
|
| 858 |
+
00:08:18,000 --> 00:08:19,000
|
| 859 |
+
See you in the upcoming videos.
|
| 860 |
+
|
20 - Spring Security/018 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.18%20Creating%20User%20Table%20And%20Db%20Properties/spring-sec-demo
|
20 - Spring Security/019 AuthenticationProvider_en.srt
ADDED
|
@@ -0,0 +1,536 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(gentle music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:05,000
|
| 7 |
+
-: And now let's try to create that provider.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:09,000
|
| 11 |
+
So basically behind the scene, you are the Spring config.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:09,000 --> 00:00:11,000
|
| 15 |
+
Whenever you implement Spring security,
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:11,000 --> 00:00:14,000
|
| 19 |
+
it'll provide you a authentication provider.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:14,000 --> 00:00:16,000
|
| 23 |
+
But I don't want to use default one
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:16,000 --> 00:00:17,000
|
| 27 |
+
because I want to create my own now,
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:17,000 --> 00:00:18,000
|
| 31 |
+
which we will link with database.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:18,000 --> 00:00:21,000
|
| 35 |
+
So what I will do is I will create a bean
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:21,000 --> 00:00:26,000
|
| 39 |
+
which returns an authentication provider, okay?
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:26,000 --> 00:00:28,000
|
| 43 |
+
And of course you can have multiple providers
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:28,000 --> 00:00:29,000
|
| 47 |
+
in the same application.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:29,000 --> 00:00:31,000
|
| 51 |
+
At this point, I'm just working with DAO.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:31,000 --> 00:00:33,000
|
| 55 |
+
So I will say public authentication provider
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:33,000 --> 00:00:35,000
|
| 59 |
+
and I will have the method name as auth provider.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:35,000 --> 00:00:38,000
|
| 63 |
+
Now what we to do is first of all, we have to make this
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:38,000 --> 00:00:40,000
|
| 67 |
+
as a bean and then we have to return the object
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:40,000 --> 00:00:42,000
|
| 71 |
+
of authentication provider.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:42,000 --> 00:00:44,000
|
| 75 |
+
Now if you jump to authentication provider,
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:44,000 --> 00:00:45,000
|
| 79 |
+
you can see it's the interface.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:45,000 --> 00:00:46,000
|
| 83 |
+
Basically we have to search
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:46,000 --> 00:00:49,000
|
| 87 |
+
for the class which implements this interface, right?
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:49,000 --> 00:00:52,000
|
| 91 |
+
And it has only one method visit, which is authenticate.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:52,000 --> 00:00:55,000
|
| 95 |
+
So basically whenever you pass a username password,
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:55,000 --> 00:00:58,000
|
| 99 |
+
that becomes a part of authentication object.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:58,000 --> 00:00:59,000
|
| 103 |
+
You can see we have an object here
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:00:59,000 --> 00:01:02,000
|
| 107 |
+
and then this using this object, it will authenticate it.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:02,000 --> 00:01:03,000
|
| 111 |
+
If the user is there,
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:03,000 --> 00:01:05,000
|
| 115 |
+
of course you will get the object of authentication.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:05,000 --> 00:01:08,000
|
| 119 |
+
If the user is not there, if the authentication fails,
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:08,000 --> 00:01:09,000
|
| 123 |
+
it'll throw an exception.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:09,000 --> 00:01:11,000
|
| 127 |
+
Okay? So that's what we want.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:11,000 --> 00:01:12,000
|
| 131 |
+
But then I don't have a class, right?
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:12,000 --> 00:01:14,000
|
| 135 |
+
So do we have a class in build?
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:14,000 --> 00:01:16,000
|
| 139 |
+
Now for different type of authentication,
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:16,000 --> 00:01:18,000
|
| 143 |
+
we have different type of authentication provider.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:18,000 --> 00:01:20,000
|
| 147 |
+
Now since we are working with database,
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:20,000 --> 00:01:23,000
|
| 151 |
+
we have something called a DAO authentication provider.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:23,000 --> 00:01:25,000
|
| 155 |
+
So if you jump here,
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:25,000 --> 00:01:26,000
|
| 159 |
+
you can see this is a class which
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:26,000 --> 00:01:27,000
|
| 163 |
+
is DAO authentication provider.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:27,000 --> 00:01:30,000
|
| 167 |
+
It's a class that means we can create an object
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:30,000 --> 00:01:31,000
|
| 171 |
+
and this extends the
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:31,000 --> 00:01:34,000
|
| 175 |
+
abstract user details authentication provider.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:34,000 --> 00:01:37,000
|
| 179 |
+
If I click on this, it implements authentication provider
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:37,000 --> 00:01:39,000
|
| 183 |
+
so that it'll do our job, right?
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:39,000 --> 00:01:41,000
|
| 187 |
+
So that means if I create object
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:41,000 --> 00:01:44,000
|
| 191 |
+
of DAO authentication provider, I would say provider
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:44,000 --> 00:01:47,000
|
| 195 |
+
equal to new authentication provider.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:47,000 --> 00:01:50,000
|
| 199 |
+
And then if I return the same object provider,
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:50,000 --> 00:01:51,000
|
| 203 |
+
our job is done, right?
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:51,000 --> 00:01:53,000
|
| 207 |
+
See, we wanted the object of authentication provider
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:53,000 --> 00:01:56,000
|
| 211 |
+
and we got the object of authentication provider
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:01:56,000 --> 00:01:58,000
|
| 215 |
+
and we are returning it, right?
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:01:58,000 --> 00:02:00,000
|
| 219 |
+
Now, this basically connects with the database
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:00,000 --> 00:02:02,000
|
| 223 |
+
and it'll return the object.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:02,000 --> 00:02:04,000
|
| 227 |
+
And that's the thing we want, right?
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:04,000 --> 00:02:05,000
|
| 231 |
+
Now will this work?
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:05,000 --> 00:02:07,000
|
| 235 |
+
See, we have done the job,
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:07,000 --> 00:02:09,000
|
| 239 |
+
we have created the authentication provider,
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:09,000 --> 00:02:11,000
|
| 243 |
+
but then this will not work
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:11,000 --> 00:02:14,000
|
| 247 |
+
because this particular class object has no idea
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:14,000 --> 00:02:16,000
|
| 251 |
+
which DBMS you're working with.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:16,000 --> 00:02:18,000
|
| 255 |
+
How do I represent a user class?
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:18,000 --> 00:02:20,000
|
| 259 |
+
And what is the user table name?
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:20,000 --> 00:02:22,000
|
| 263 |
+
So we have to mention all those things.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:22,000 --> 00:02:24,000
|
| 267 |
+
And the way you can do that is we have
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:24,000 --> 00:02:26,000
|
| 271 |
+
to create a user detail service.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:26,000 --> 00:02:27,000
|
| 275 |
+
We do have it here,
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:27,000 --> 00:02:29,000
|
| 279 |
+
but then this user detail service
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:29,000 --> 00:02:31,000
|
| 283 |
+
works with the static values.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:31,000 --> 00:02:33,000
|
| 287 |
+
We don't want to work with static values.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:33,000 --> 00:02:35,000
|
| 291 |
+
So what I will do is I will just commend this part.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:35,000 --> 00:02:37,000
|
| 295 |
+
I don't want to work with static values now.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:37,000 --> 00:02:40,000
|
| 299 |
+
I want to have a dynamic database connectivity.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:40,000 --> 00:02:44,000
|
| 303 |
+
And to achieve this, to create a user digital service,
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:44,000 --> 00:02:45,000
|
| 307 |
+
first of all, why do we need it?
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:45,000 --> 00:02:47,000
|
| 311 |
+
So if you say provider here,
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:47,000 --> 00:02:49,000
|
| 315 |
+
and when you say dot,
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:02:49,000 --> 00:02:53,000
|
| 319 |
+
there's a option of set user details service,
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:02:53,000 --> 00:02:55,000
|
| 323 |
+
because authentication provider will say, I will check,
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:02:55,000 --> 00:02:57,000
|
| 327 |
+
but tell me how do I connect with the user table?
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:02:57,000 --> 00:02:59,000
|
| 331 |
+
What's the process I have follow?
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:02:59,000 --> 00:03:02,000
|
| 335 |
+
And that is taken care by the user detailed service.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:02,000 --> 00:03:04,000
|
| 339 |
+
And that's what we have done before that as well.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:04,000 --> 00:03:06,000
|
| 343 |
+
But then that was study values.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:06,000 --> 00:03:08,000
|
| 347 |
+
I want to use this service for the database connectivity.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:08,000 --> 00:03:10,000
|
| 351 |
+
And for that we have to create a separate class
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:10,000 --> 00:03:12,000
|
| 355 |
+
to achieve that.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:12,000 --> 00:03:15,000
|
| 359 |
+
And that class object need to specify here.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:15,000 --> 00:03:18,000
|
| 363 |
+
Now this particular method needs object
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:18,000 --> 00:03:19,000
|
| 367 |
+
of user detail service.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:19,000 --> 00:03:21,000
|
| 371 |
+
So what I can do is
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:21,000 --> 00:03:24,000
|
| 375 |
+
before we create a class, I want to create a bean here.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:24,000 --> 00:03:28,000
|
| 379 |
+
So I would say private user details service,
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:28,000 --> 00:03:29,000
|
| 383 |
+
and I would say user detailed service.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:29,000 --> 00:03:32,000
|
| 387 |
+
And I want this to be auto wired.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:32,000 --> 00:03:34,000
|
| 391 |
+
So basically I'm asking, Hey, Spring Framework,
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:34,000 --> 00:03:36,000
|
| 395 |
+
I want the object of user digital service.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:36,000 --> 00:03:37,000
|
| 399 |
+
I don't know where, from where you get it,
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:37,000 --> 00:03:39,000
|
| 403 |
+
give me this object so that I can pass it here.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:03:39,000 --> 00:03:42,000
|
| 407 |
+
Okay? But then even Spring has no idea how do we do that?
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:03:42,000 --> 00:03:45,000
|
| 411 |
+
Okay, so we have to configure this.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:03:45,000 --> 00:03:48,000
|
| 415 |
+
We have to basically implement the user digital service
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:03:48,000 --> 00:03:49,000
|
| 419 |
+
because that's an interface.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:03:49,000 --> 00:03:50,000
|
| 423 |
+
And that's why I mentioned, right?
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:03:50,000 --> 00:03:52,000
|
| 427 |
+
We have multiple classes to implement.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:03:52,000 --> 00:03:55,000
|
| 431 |
+
So basically the provider here, okay, where? Where's that?
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:03:55,000 --> 00:03:57,000
|
| 435 |
+
Let me just close all the extra files.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:03:57,000 --> 00:03:59,000
|
| 439 |
+
So yeah, so the provider here is dependent
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:03:59,000 --> 00:04:01,000
|
| 443 |
+
on the user data service.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:01,000 --> 00:04:04,000
|
| 447 |
+
If we can pass the object of this, our job is done,
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:04,000 --> 00:04:06,000
|
| 451 |
+
but then this is the interface, right?
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:06,000 --> 00:04:07,000
|
| 455 |
+
We have to create a class which will implement
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:07,000 --> 00:04:09,000
|
| 459 |
+
this interface where we have
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:09,000 --> 00:04:11,000
|
| 463 |
+
the implementation and then this will work.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:11,000 --> 00:04:12,000
|
| 467 |
+
So that's the first thing you have to do.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:12,000 --> 00:04:14,000
|
| 471 |
+
The second one is we have
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:14,000 --> 00:04:16,000
|
| 475 |
+
to also specify the password encoder.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:16,000 --> 00:04:19,000
|
| 479 |
+
Again, I don't want to use any password encoder here.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:19,000 --> 00:04:21,000
|
| 483 |
+
So I will say set password encoder.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:21,000 --> 00:04:23,000
|
| 487 |
+
If you don't want to have any password encoder,
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:23,000 --> 00:04:24,000
|
| 491 |
+
you can simply opt
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:24,000 --> 00:04:28,000
|
| 495 |
+
for NoOpPasswordEncoder.getinstance.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:28,000 --> 00:04:31,000
|
| 499 |
+
So we are getting the object of no op password encoder.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:04:31,000 --> 00:04:33,000
|
| 503 |
+
So basically I don't want to use any password encoder.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:04:33,000 --> 00:04:36,000
|
| 507 |
+
In future, if you want to use any password encoder,
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:04:36,000 --> 00:04:37,000
|
| 511 |
+
just replace this and your job is done.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:04:37,000 --> 00:04:39,000
|
| 515 |
+
And we are saying set password encoder. That's it.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:04:39,000 --> 00:04:41,000
|
| 519 |
+
These are the two things you have to mention.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:04:41,000 --> 00:04:42,000
|
| 523 |
+
But again, this will not work
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:04:42,000 --> 00:04:44,000
|
| 527 |
+
because we don't have the implementation
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:04:44,000 --> 00:04:45,000
|
| 531 |
+
for the use detailed service.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:04:45,000 --> 00:04:48,000
|
| 535 |
+
Okay, how do I do that? Let's see in the next video.
|
| 536 |
+
|
20 - Spring Security/019 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.19%20Authenticationprovider/spring-sec-demo
|
20 - Spring Security/020 Creating a UserDetailsService_en.srt
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(bright music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:07,000
|
| 7 |
+
-: Okay, now it's time to implement the user details service.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:07,000 --> 00:00:10,000
|
| 11 |
+
So what I will do is I will create a new class.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:10,000 --> 00:00:12,000
|
| 15 |
+
And in fact, you know, before we do that,
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:12,000 --> 00:00:15,000
|
| 19 |
+
I just want to put everything in a particular package
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:15,000 --> 00:00:17,000
|
| 23 |
+
that should make sense.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:17,000 --> 00:00:20,000
|
| 27 |
+
So I will just create a new package
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:20,000 --> 00:00:22,000
|
| 31 |
+
and I will say these are controllers.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:22,000 --> 00:00:24,000
|
| 35 |
+
So I will have all my controllers here.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:24,000 --> 00:00:27,000
|
| 39 |
+
So basically I want to move the hello controller,
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:27,000 --> 00:00:30,000
|
| 43 |
+
string controller, and this particular controller.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:30,000 --> 00:00:32,000
|
| 47 |
+
Yes, refactor.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:32,000 --> 00:00:36,000
|
| 51 |
+
I want to have a model class somewhere else.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:36,000 --> 00:00:38,000
|
| 55 |
+
I will say model.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:38,000 --> 00:00:40,000
|
| 59 |
+
And the student basically is a model class.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:40,000 --> 00:00:42,000
|
| 63 |
+
I will move that to, oh, I've created a model class,
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:42,000 --> 00:00:43,000
|
| 67 |
+
not the package.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:48,000 --> 00:00:51,000
|
| 71 |
+
So model package, the student will go there.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:51,000 --> 00:00:54,000
|
| 75 |
+
And then I want to have a service layer as well.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:54,000 --> 00:00:56,000
|
| 79 |
+
Maybe in your project you want
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:56,000 --> 00:00:57,000
|
| 83 |
+
to have multiple service classes.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:57,000 --> 00:00:59,000
|
| 87 |
+
I will say this is service layer.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:59,000 --> 00:01:00,000
|
| 91 |
+
And in this service layer,
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:00,000 --> 00:01:03,000
|
| 95 |
+
I want to create a class for the user details service
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:03,000 --> 00:01:05,000
|
| 99 |
+
because that's a service, right?
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:05,000 --> 00:01:07,000
|
| 103 |
+
So I'll just right click here and say New Java class
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:07,000 --> 00:01:11,000
|
| 107 |
+
and I will name this as my user details service,
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:11,000 --> 00:01:14,000
|
| 111 |
+
because this is going to implement user details service.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:14,000 --> 00:01:15,000
|
| 115 |
+
I will say create.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:15,000 --> 00:01:20,000
|
| 119 |
+
And this is going to implement the user details service.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:20,000 --> 00:01:22,000
|
| 123 |
+
Okay, so we've got a class now
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:22,000 --> 00:01:24,000
|
| 127 |
+
and this class object,
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:24,000 --> 00:01:27,000
|
| 131 |
+
basically I have to pass in here, okay?
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:27,000 --> 00:01:31,000
|
| 135 |
+
And the way you can do that is by making this as a service.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:31,000 --> 00:01:32,000
|
| 139 |
+
Of course you can also say component,
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:32,000 --> 00:01:33,000
|
| 143 |
+
but this is service layer.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:33,000 --> 00:01:35,000
|
| 147 |
+
So service make much more sense.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:35,000 --> 00:01:37,000
|
| 151 |
+
Now what we are doing is when you say auto wire,
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:37,000 --> 00:01:40,000
|
| 155 |
+
this particular class object will be injected,
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:40,000 --> 00:01:42,000
|
| 159 |
+
but then you are getting an error here.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:42,000 --> 00:01:43,000
|
| 163 |
+
We are getting the error
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:43,000 --> 00:01:46,000
|
| 167 |
+
because if you go to user detail, user detailed service,
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:46,000 --> 00:01:49,000
|
| 171 |
+
it has a method called load user by username.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:49,000 --> 00:01:53,000
|
| 175 |
+
That means we have to implement that particular method.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:53,000 --> 00:01:55,000
|
| 179 |
+
So what I will do here is I will go back here
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:55,000 --> 00:01:57,000
|
| 183 |
+
and let's implement it.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:57,000 --> 00:01:59,000
|
| 187 |
+
I will simply ask my IDE say,
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:59,000 --> 00:02:02,000
|
| 191 |
+
implement the methods and it will just implement the method.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:02:02,000 --> 00:02:04,000
|
| 195 |
+
Of course the logic you have to define,
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:02:04,000 --> 00:02:06,000
|
| 199 |
+
but it'll give you a structure.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:02:06,000 --> 00:02:08,000
|
| 203 |
+
So the structure is this particular class
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:08,000 --> 00:02:11,000
|
| 207 |
+
or this particular method, which is load user by username,
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:11,000 --> 00:02:14,000
|
| 211 |
+
takes a string username as a parameter,
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:14,000 --> 00:02:16,000
|
| 215 |
+
and then we can perform the operation there.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:16,000 --> 00:02:18,000
|
| 219 |
+
And after performing the operation,
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:18,000 --> 00:02:22,000
|
| 223 |
+
we have to return the object of user details.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:22,000 --> 00:02:24,000
|
| 227 |
+
Now, this is some, this is something we have to do now.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:24,000 --> 00:02:26,000
|
| 231 |
+
Oh, okay, the code is not getting completed, right?
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:26,000 --> 00:02:28,000
|
| 235 |
+
But yeah, we'll be there, don't worry.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:28,000 --> 00:02:31,000
|
| 239 |
+
So since we are going step by step, let's focus.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:31,000 --> 00:02:33,000
|
| 243 |
+
So we have lower the user by username.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:33,000 --> 00:02:34,000
|
| 247 |
+
So that's the method we have to implement.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:34,000 --> 00:02:36,000
|
| 251 |
+
Now if you observe,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:36,000 --> 00:02:38,000
|
| 255 |
+
basically we are saying load user by username.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:38,000 --> 00:02:40,000
|
| 259 |
+
That means when you get a username,
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:40,000 --> 00:02:45,000
|
| 263 |
+
we have to basically hit the database to get this detail.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:45,000 --> 00:02:48,000
|
| 267 |
+
Now question guys, how will you hit the database
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:48,000 --> 00:02:49,000
|
| 271 |
+
and how will you return this?
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:49,000 --> 00:02:51,000
|
| 275 |
+
Now to hit the database,
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:51,000 --> 00:02:53,000
|
| 279 |
+
we need to have a repo layer, right?
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:53,000 --> 00:02:55,000
|
| 283 |
+
Database connectivity is done by the repo layer,
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:55,000 --> 00:02:56,000
|
| 287 |
+
not the service class.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:56,000 --> 00:03:00,000
|
| 291 |
+
And for that, we have to create object of user repo.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:03:00,000 --> 00:03:02,000
|
| 295 |
+
Now, user repo is not a class.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:03:02,000 --> 00:03:04,000
|
| 299 |
+
This is something we have to create.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:03:04,000 --> 00:03:05,000
|
| 303 |
+
It can be a class or the interface.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:03:05,000 --> 00:03:07,000
|
| 307 |
+
If you're using normal JDPC, we have to get a class.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:03:07,000 --> 00:03:10,000
|
| 311 |
+
If you're using JPA, we can do that
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:03:10,000 --> 00:03:11,000
|
| 315 |
+
with the help of interface.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:11,000 --> 00:03:13,000
|
| 319 |
+
So I'm saying user repo, repo,
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:13,000 --> 00:03:15,000
|
| 323 |
+
and I want this to be auto wired.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:15,000 --> 00:03:20,000
|
| 327 |
+
I will say auto wired and I will make this as private.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:20,000 --> 00:03:22,000
|
| 331 |
+
Now, basically using this particular class
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:22,000 --> 00:03:25,000
|
| 335 |
+
or the interface, we have to get the database connectivity
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:25,000 --> 00:03:27,000
|
| 339 |
+
and implement the code here.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:27,000 --> 00:03:28,000
|
| 343 |
+
Now the code is actually very simple.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:28,000 --> 00:03:31,000
|
| 347 |
+
The code is you use this particular repository
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:31,000 --> 00:03:34,000
|
| 351 |
+
and fire the query to the data database.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:34,000 --> 00:03:38,000
|
| 355 |
+
If you get a user in return, that's great, you got a login.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:38,000 --> 00:03:41,000
|
| 359 |
+
But what if you don't have a user that time you can say,
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:41,000 --> 00:03:44,000
|
| 363 |
+
user not found, or user 404, some error, right?
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:44,000 --> 00:03:46,000
|
| 367 |
+
And then at the end you have
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:46,000 --> 00:03:47,000
|
| 371 |
+
to return the object of user details.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:47,000 --> 00:03:50,000
|
| 375 |
+
So how do we do that? And to do that, we have to first
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:50,000 --> 00:03:53,000
|
| 379 |
+
of all create this interface called user repo.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:53,000 --> 00:03:55,000
|
| 383 |
+
How do we create that? Let's say in the next video.
|
| 384 |
+
|
20 - Spring Security/020 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.20%20Creating%20A%20Userdetailsservice/spring-sec-demo
|
20 - Spring Security/021 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.21%20User%20Repository/spring-sec-demo
|
20 - Spring Security/021 User Repository_en.srt
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:02,000
|
| 3 |
+
(upbeat music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:02,000 --> 00:00:06,000
|
| 7 |
+
-: Okay, so now it's time to create this interface
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:06,000 --> 00:00:07,000
|
| 11 |
+
or a class called UserRepo.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:07,000 --> 00:00:10,000
|
| 15 |
+
Now, since we are using JPA, we are going
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:10,000 --> 00:00:12,000
|
| 19 |
+
to create a interface and that's what we are seeing here.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:12,000 --> 00:00:15,000
|
| 23 |
+
So you can see it says, "Hey, we don't have this UserRepo".
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:15,000 --> 00:00:18,000
|
| 27 |
+
I will say, "okay, create a interface
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:18,000 --> 00:00:20,000
|
| 31 |
+
called UserRepo in the package".
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:20,000 --> 00:00:23,000
|
| 35 |
+
I'll say Dao layer and click on, okay?
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:23,000 --> 00:00:25,000
|
| 39 |
+
And you can see we've got a Dao layer
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:25,000 --> 00:00:26,000
|
| 43 |
+
in which you have as UserRepo.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:26,000 --> 00:00:30,000
|
| 47 |
+
And this particular UserRepo is going to extend
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:30,000 --> 00:00:33,000
|
| 51 |
+
the JPA repository.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:33,000 --> 00:00:34,000
|
| 55 |
+
Now since we are connecting with database,
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:34,000 --> 00:00:36,000
|
| 59 |
+
we have to do that.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:36,000 --> 00:00:39,000
|
| 63 |
+
And then in this JPA repository we have to pass two things.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:39,000 --> 00:00:41,000
|
| 67 |
+
The first one is the table name,
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:41,000 --> 00:00:43,000
|
| 71 |
+
which we'll connect with the class.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:43,000 --> 00:00:44,000
|
| 75 |
+
Basically we have to mention the class name,
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:44,000 --> 00:00:47,000
|
| 79 |
+
which we'll connect with the table, the ORM entity.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:47,000 --> 00:00:49,000
|
| 83 |
+
And then we have to mention the primary key.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:49,000 --> 00:00:51,000
|
| 87 |
+
The primary key is of type integer, okay?
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:51,000 --> 00:00:54,000
|
| 91 |
+
So basically we need to get this interface called UserRepo,
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:54,000 --> 00:00:56,000
|
| 95 |
+
which extends our JPA repository.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:56,000 --> 00:01:00,000
|
| 99 |
+
But the problem is we don't have this class yet.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:00,000 --> 00:01:04,000
|
| 103 |
+
So what I will do is I will create this class called user
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:04,000 --> 00:01:06,000
|
| 107 |
+
and I will do that in my own package.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:06,000 --> 00:01:09,000
|
| 111 |
+
So I will go back to model and that's what, right?
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:09,000 --> 00:01:12,000
|
| 115 |
+
So you have to remember which file goes where.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:12,000 --> 00:01:15,000
|
| 119 |
+
So in the model we'll create a user
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:15,000 --> 00:01:17,000
|
| 123 |
+
which will represent a table.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:17,000 --> 00:01:21,000
|
| 127 |
+
And this particular class will have the same number
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:21,000 --> 00:01:23,000
|
| 131 |
+
of properties as you have in the table, right?
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:23,000 --> 00:01:26,000
|
| 135 |
+
So I will say private int id.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:26,000 --> 00:01:31,000
|
| 139 |
+
Then I want a private string username
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:31,000 --> 00:01:35,000
|
| 143 |
+
and a private string password.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:35,000 --> 00:01:37,000
|
| 147 |
+
Now this is the same thing we have in the table.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:37,000 --> 00:01:38,000
|
| 151 |
+
So if you go back to your table,
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:38,000 --> 00:01:40,000
|
| 155 |
+
you can see we have the same properties, Id,
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:40,000 --> 00:01:42,000
|
| 159 |
+
username and password.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:42,000 --> 00:01:46,000
|
| 163 |
+
Now the problem here is I don't want to use dataset,
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:46,000 --> 00:01:47,000
|
| 167 |
+
I just want to use Lombok.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:47,000 --> 00:01:51,000
|
| 171 |
+
And I think we don't have a Lombok here.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:51,000 --> 00:01:55,000
|
| 175 |
+
So we'll go back to my pom.xml and Lombok,
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:55,000 --> 00:01:56,000
|
| 179 |
+
okay Lombok is there.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:56,000 --> 00:01:58,000
|
| 183 |
+
So what I can do is I can simply use Lombok here
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:58,000 --> 00:02:02,000
|
| 187 |
+
for the users and I want to close all the extra files.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:02:02,000 --> 00:02:04,000
|
| 191 |
+
So I don't want to use controller anymore.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:02:04,000 --> 00:02:05,000
|
| 195 |
+
Showing control are done,
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:02:05,000 --> 00:02:08,000
|
| 199 |
+
student we are not going to use now.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:02:08,000 --> 00:02:09,000
|
| 203 |
+
Xml, we are not going to touch.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:09,000 --> 00:02:11,000
|
| 207 |
+
So these are the files we have
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:11,000 --> 00:02:14,000
|
| 211 |
+
and okay, let's go back to the user.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:14,000 --> 00:02:17,000
|
| 215 |
+
And I want to have a data, okay?
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:17,000 --> 00:02:21,000
|
| 219 |
+
Now since this is also a entity for the OLM,
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:21,000 --> 00:02:23,000
|
| 223 |
+
so I will say this is entity
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:23,000 --> 00:02:26,000
|
| 227 |
+
and then this will also have a primary key,
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:26,000 --> 00:02:27,000
|
| 231 |
+
which is Id here.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:27,000 --> 00:02:29,000
|
| 235 |
+
And we have talked about all those things in data JP, right?
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:29,000 --> 00:02:32,000
|
| 239 |
+
So let's not waste our time more on explanation,
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:32,000 --> 00:02:33,000
|
| 243 |
+
but we have done this.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:33,000 --> 00:02:36,000
|
| 247 |
+
So we got entity, we got Id and okay,
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:36,000 --> 00:02:37,000
|
| 251 |
+
there's one little problem.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:37,000 --> 00:02:39,000
|
| 255 |
+
The class name I'm using as user,
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:39,000 --> 00:02:42,000
|
| 259 |
+
but the table name is users, okay?
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:42,000 --> 00:02:44,000
|
| 263 |
+
We have a different table name.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:44,000 --> 00:02:46,000
|
| 267 |
+
So if you want to have a different table name,
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:46,000 --> 00:02:49,000
|
| 271 |
+
we have to basically mention at table,
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:49,000 --> 00:02:51,000
|
| 275 |
+
and you can mention the table name here.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:51,000 --> 00:02:54,000
|
| 279 |
+
So you can say name is equal to users.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:54,000 --> 00:02:56,000
|
| 283 |
+
Since we have a different table name,
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:56,000 --> 00:02:57,000
|
| 287 |
+
that's the only reason here.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:57,000 --> 00:02:59,000
|
| 291 |
+
And that's it, you got user, user table created.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:59,000 --> 00:03:01,000
|
| 295 |
+
I can go back here
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:03:01,000 --> 00:03:03,000
|
| 299 |
+
and import the package from our, remember that we have
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:03:03,000 --> 00:03:07,000
|
| 303 |
+
to import from our own package, not from the spring.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:03:07,000 --> 00:03:10,000
|
| 307 |
+
And that's it, we got this UserRepo, okay?
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:03:10,000 --> 00:03:13,000
|
| 311 |
+
Now there's one little thing we have to do here
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:03:13,000 --> 00:03:16,000
|
| 315 |
+
because if you say load user by username,
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:16,000 --> 00:03:17,000
|
| 319 |
+
we are passing a username, right?
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:17,000 --> 00:03:21,000
|
| 323 |
+
And that means the repo has to search by username.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:21,000 --> 00:03:23,000
|
| 327 |
+
And to achieve that, we have to use a method
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:23,000 --> 00:03:26,000
|
| 331 |
+
which will return me a user.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:26,000 --> 00:03:28,000
|
| 335 |
+
I will say find by username.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:28,000 --> 00:03:31,000
|
| 339 |
+
And in the bracket I will say string username.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:31,000 --> 00:03:34,000
|
| 343 |
+
Technically we have one mistake in our code, not the code,
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:34,000 --> 00:03:35,000
|
| 347 |
+
but the design of this database.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:35,000 --> 00:03:38,000
|
| 351 |
+
Don't you think the username should be unique?
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:38,000 --> 00:03:40,000
|
| 355 |
+
Or maybe you can make your username as primary key,
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:40,000 --> 00:03:42,000
|
| 359 |
+
not the Id, because we want to have it unique.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:42,000 --> 00:03:45,000
|
| 363 |
+
So when you create it, make sure that you have
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:45,000 --> 00:03:47,000
|
| 367 |
+
not null or unique
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:47,000 --> 00:03:50,000
|
| 371 |
+
or maybe just make your username as your primary key.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:50,000 --> 00:03:51,000
|
| 375 |
+
That will make much more sense.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:51,000 --> 00:03:54,000
|
| 379 |
+
But even this works, I will just make sure
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:54,000 --> 00:03:56,000
|
| 383 |
+
that I have a use unique username there.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:56,000 --> 00:03:59,000
|
| 387 |
+
Okay, so we got this repo ready
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:59,000 --> 00:04:03,000
|
| 391 |
+
and now I can use this repo in this particular method.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:04:03,000 --> 00:04:05,000
|
| 395 |
+
How do I do that, so one thing is for sure,
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:04:05,000 --> 00:04:08,000
|
| 399 |
+
when we use this repo, so if I say repo dot,
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:04:08,000 --> 00:04:11,000
|
| 403 |
+
you can see we have a method called find by username
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:04:11,000 --> 00:04:13,000
|
| 407 |
+
in which you can pass the same username.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:04:13,000 --> 00:04:18,000
|
| 411 |
+
So now this repo is responsible to connect with database,
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:04:18,000 --> 00:04:20,000
|
| 415 |
+
get the data, and we are getting this data here.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:04:20,000 --> 00:04:23,000
|
| 419 |
+
So when you say repo dot find user by username,
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:04:23,000 --> 00:04:24,000
|
| 423 |
+
it'll fire the query behind the scene.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:04:24,000 --> 00:04:27,000
|
| 427 |
+
And what you will get in return is the type
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:27,000 --> 00:04:28,000
|
| 431 |
+
which you have mentioned here.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:28,000 --> 00:04:30,000
|
| 435 |
+
The type is user.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:30,000 --> 00:04:34,000
|
| 439 |
+
So you can simply go back here and say user user equal to.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:34,000 --> 00:04:36,000
|
| 443 |
+
So what we are getting in return is user,
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:36,000 --> 00:04:39,000
|
| 447 |
+
and this user is from my own package, not spring.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:39,000 --> 00:04:41,000
|
| 451 |
+
Now, once you got the user, you have
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:41,000 --> 00:04:44,000
|
| 455 |
+
to check if the user is null or not, right?
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:44,000 --> 00:04:47,000
|
| 459 |
+
So we'll check, if the user is null.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:47,000 --> 00:04:50,000
|
| 463 |
+
In that case, we have to throw an exception.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:50,000 --> 00:04:52,000
|
| 467 |
+
Remember, you can see we have this particular method,
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:52,000 --> 00:04:56,000
|
| 471 |
+
load user by username, throws a user not found exception.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:56,000 --> 00:04:58,000
|
| 475 |
+
So I can simply throw the same exception.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:58,000 --> 00:05:01,000
|
| 479 |
+
So I can say, in fact, I want to print on console as well.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:05:01,000 --> 00:05:06,000
|
| 483 |
+
First of all, I will say user 404, user not found.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:05:06,000 --> 00:05:07,000
|
| 487 |
+
And I will throw the same exception.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:05:07,000 --> 00:05:12,000
|
| 491 |
+
So I will say, throw new user, not found exception.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:05:12,000 --> 00:05:15,000
|
| 495 |
+
I can print a message as well.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:05:15,000 --> 00:05:19,000
|
| 499 |
+
Maybe the same message if you want, yeah, that's it.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:05:19,000 --> 00:05:21,000
|
| 503 |
+
So if the user is not found,
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:05:21,000 --> 00:05:23,000
|
| 507 |
+
we can simply throw the exception.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:05:23,000 --> 00:05:25,000
|
| 511 |
+
But what if you found the user?
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:05:25,000 --> 00:05:29,000
|
| 515 |
+
In that case, we have to return the user,
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:05:29,000 --> 00:05:31,000
|
| 519 |
+
but you can't simply return a user.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:05:31,000 --> 00:05:35,000
|
| 523 |
+
You can see what you are expecting here is not just a user,
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:05:35,000 --> 00:05:37,000
|
| 527 |
+
but a user details.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:05:37,000 --> 00:05:40,000
|
| 531 |
+
Okay, so we need to make this work.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:05:40,000 --> 00:05:41,000
|
| 535 |
+
So instead of return a user,
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:05:41,000 --> 00:05:43,000
|
| 539 |
+
we have to return a user, user details.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:43,000 --> 00:05:48,000
|
| 543 |
+
But if you click on user details, it's an interface.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:48,000 --> 00:05:49,000
|
| 547 |
+
So now you know what's the next video?
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:49,000 --> 00:05:53,000
|
| 551 |
+
The next video is about let's implement this user details
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:53,000 --> 00:05:55,000
|
| 555 |
+
so that we can return it from here.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:55,000 --> 00:05:57,000
|
| 559 |
+
How to do that, let's see in the next video.
|
| 560 |
+
|
20 - Spring Security/022 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.22%20Userdetails%20And%20Userprincipal/spring-sec-demo
|
20 - Spring Security/022 UserDetails and UserPrincipal_en.srt
ADDED
|
@@ -0,0 +1,732 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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9 |
+
3
|
| 10 |
+
00:00:07,000 --> 00:00:10,000
|
| 11 |
+
But again, we have interface, we have to be a class.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:10,000 --> 00:00:13,000
|
| 15 |
+
So the next step is create a UserDetails.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:13,000 --> 00:00:16,000
|
| 19 |
+
I will do that in the model package, not in dao.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:16,000 --> 00:00:19,000
|
| 23 |
+
I'll just go back here and say new class.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:19,000 --> 00:00:24,000
|
| 27 |
+
And this class nickname as UserDetailsImplementation
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:25,000 --> 00:00:26,000
|
| 31 |
+
because we are implementing
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:26,000 --> 00:00:28,000
|
| 35 |
+
this particular interface.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:28,000 --> 00:00:33,000
|
| 39 |
+
Or a better name for that is UserPrincipal.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:33,000 --> 00:00:35,000
|
| 43 |
+
Because in the terms of Spring Security,
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:35,000 --> 00:00:38,000
|
| 47 |
+
when you are representing a current user,
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:38,000 --> 00:00:39,000
|
| 51 |
+
we call them as principals.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:39,000 --> 00:00:41,000
|
| 55 |
+
So the current user, which we are authenticating,
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:41,000 --> 00:00:42,000
|
| 59 |
+
is a principal, okay?
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:42,000 --> 00:00:45,000
|
| 63 |
+
So UserPrincipal makes much more sense,
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:45,000 --> 00:00:47,000
|
| 67 |
+
but again, you can name your class
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:47,000 --> 00:00:50,000
|
| 71 |
+
as UserDetailsImplementation, your choice.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:50,000 --> 00:00:55,000
|
| 75 |
+
So this UserPrincipal implements the UserDetails, okay?
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:56,000 --> 00:00:58,000
|
| 79 |
+
And now let's provide the methods.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:58,000 --> 00:00:59,000
|
| 83 |
+
We have multiple methods there,
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:59,000 --> 00:01:00,000
|
| 87 |
+
so we have to implement them.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:01:00,000 --> 00:01:02,000
|
| 91 |
+
So what I will do is I will just go back here
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:01:02,000 --> 00:01:04,000
|
| 95 |
+
and say implement methods.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:04,000 --> 00:01:06,000
|
| 99 |
+
And you can see we have multiple methods
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:06,000 --> 00:01:07,000
|
| 103 |
+
and we don't have a choice.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:07,000 --> 00:01:08,000
|
| 107 |
+
We have to implement everything.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:08,000 --> 00:01:10,000
|
| 111 |
+
And I will click on OK.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:10,000 --> 00:01:12,000
|
| 115 |
+
Now all these methods provides different purpose.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:12,000 --> 00:01:16,000
|
| 119 |
+
Example, let's go from bottom to up. So first is it enabled?
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:16,000 --> 00:01:18,000
|
| 123 |
+
We have to check if the account is enabled.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:18,000 --> 00:01:20,000
|
| 127 |
+
Then is the credentials not expired?
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:20,000 --> 00:01:22,000
|
| 131 |
+
We have to check for the expiry.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:22,000 --> 00:01:24,000
|
| 135 |
+
Is the account logged? We have to check for that.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:24,000 --> 00:01:27,000
|
| 139 |
+
Is the account expired? We have to check for that.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:27,000 --> 00:01:28,000
|
| 143 |
+
And then we have to check
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:28,000 --> 00:01:30,000
|
| 147 |
+
for the username, password,
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:30,000 --> 00:01:32,000
|
| 151 |
+
and then the authority.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:32,000 --> 00:01:35,000
|
| 155 |
+
Also, right, because every user will have different access,
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:35,000 --> 00:01:39,000
|
| 159 |
+
admin access, user access, trainer access.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:39,000 --> 00:01:41,000
|
| 163 |
+
So whatever access you can mention, you can do that here.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:41,000 --> 00:01:42,000
|
| 167 |
+
Now since in this particular example,
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:42,000 --> 00:01:44,000
|
| 171 |
+
we are not focusing on all these things.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:44,000 --> 00:01:47,000
|
| 175 |
+
So we'll keep it true. We don't want to check them.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:47,000 --> 00:01:50,000
|
| 179 |
+
So we are not even checking if it is expired.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:50,000 --> 00:01:52,000
|
| 183 |
+
Is it enabled, is it logged?
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:52,000 --> 00:01:53,000
|
| 187 |
+
We are saying everything is good,
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:53,000 --> 00:01:55,000
|
| 191 |
+
no need to worry about the expiry and logging.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:55,000 --> 00:01:57,000
|
| 195 |
+
So we'll keep it as true.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:57,000 --> 00:01:58,000
|
| 199 |
+
We have to work with this three methods.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:58,000 --> 00:02:02,000
|
| 203 |
+
First one is getAuthorities, getPassword and getUsername.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:02,000 --> 00:02:05,000
|
| 207 |
+
Now (indistinct) where you will get it.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:05,000 --> 00:02:08,000
|
| 211 |
+
See if you go back to your UserDetails service,
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:08,000 --> 00:02:10,000
|
| 215 |
+
we do have this in user object
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:10,000 --> 00:02:12,000
|
| 219 |
+
because user object will have everything.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:12,000 --> 00:02:14,000
|
| 223 |
+
The username, the password, also authority.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:14,000 --> 00:02:17,000
|
| 227 |
+
I'm not doing that so I will just hardcode that.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:17,000 --> 00:02:19,000
|
| 231 |
+
But if in your table we can have one more column
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:19,000 --> 00:02:23,000
|
| 235 |
+
for the authority and you can return that in the user class.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:23,000 --> 00:02:24,000
|
| 239 |
+
So the user class will have username, password,
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:24,000 --> 00:02:26,000
|
| 243 |
+
and authority as well.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:26,000 --> 00:02:27,000
|
| 247 |
+
At this point, I don't wanna do that.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:27,000 --> 00:02:30,000
|
| 251 |
+
Okay, so we'll keep it, we'll hardcode this part,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:30,000 --> 00:02:32,000
|
| 255 |
+
but the question arise, how will I get the access
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:32,000 --> 00:02:36,000
|
| 259 |
+
of this particular user object in here?
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:36,000 --> 00:02:38,000
|
| 263 |
+
So what we can do is here,
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:38,000 --> 00:02:39,000
|
| 267 |
+
when you are returning the object,
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:39,000 --> 00:02:41,000
|
| 271 |
+
so instead of saying return User,
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:41,000 --> 00:02:45,000
|
| 275 |
+
I can say return new UserPrincipal
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:45,000 --> 00:02:48,000
|
| 279 |
+
because UserPrincipal implements the UserDetails, right?
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:48,000 --> 00:02:50,000
|
| 283 |
+
So you can see there's no error now,
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:50,000 --> 00:02:52,000
|
| 287 |
+
but what if you can actually pass this object here?
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:52,000 --> 00:02:54,000
|
| 291 |
+
Now when you can pass this object here,
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:54,000 --> 00:02:58,000
|
| 295 |
+
we can accept the object here and then we can work with it.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:58,000 --> 00:03:00,000
|
| 299 |
+
And to accept it, we need a constructor.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:03:00,000 --> 00:03:03,000
|
| 303 |
+
So I'll say public UserPrincipal,
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:03:03,000 --> 00:03:05,000
|
| 307 |
+
which will accept the user objects.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:03:05,000 --> 00:03:10,000
|
| 311 |
+
I will say User user. And I will, okay.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:03:10,000 --> 00:03:12,000
|
| 315 |
+
So I will also create object here
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:12,000 --> 00:03:15,000
|
| 319 |
+
so that I can get the instance access
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:15,000 --> 00:03:19,000
|
| 323 |
+
and this.user is equal to user.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:19,000 --> 00:03:22,000
|
| 327 |
+
So whatever object I'm receiving from the UserDetails,
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:22,000 --> 00:03:23,000
|
| 331 |
+
I will just assign this to here
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:23,000 --> 00:03:25,000
|
| 335 |
+
so that I can access in other methods.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:25,000 --> 00:03:28,000
|
| 339 |
+
Okay, now how do I get the username? It's very simple.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:28,000 --> 00:03:31,000
|
| 343 |
+
You can simply say user.getUsername.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:31,000 --> 00:03:32,000
|
| 347 |
+
How will I get the password?
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:32,000 --> 00:03:35,000
|
| 351 |
+
It's very simple. You can say user.getPassword.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:35,000 --> 00:03:36,000
|
| 355 |
+
How will you get the authority?
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:36,000 --> 00:03:38,000
|
| 359 |
+
We don't have it in the user.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:38,000 --> 00:03:40,000
|
| 363 |
+
So I can just return a hardcoded value,
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:40,000 --> 00:03:43,000
|
| 367 |
+
and you can see it is expecting you
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:43,000 --> 00:03:45,000
|
| 371 |
+
to return a Collection.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:45,000 --> 00:03:48,000
|
| 375 |
+
So I will say Collections.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:48,000 --> 00:03:49,000
|
| 379 |
+
And then we just want
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:49,000 --> 00:03:51,000
|
| 383 |
+
to return one particular object, right?
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:51,000 --> 00:03:52,000
|
| 387 |
+
So I can say singleton.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:52,000 --> 00:03:53,000
|
| 391 |
+
Now I can specify the type here.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:53,000 --> 00:03:55,000
|
| 395 |
+
Now you can see this singleton,
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:55,000 --> 00:03:59,000
|
| 399 |
+
which returns one object, is expecting you to have an object
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:59,000 --> 00:04:03,000
|
| 403 |
+
of GrantedAuthority because that's the type we are using.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:04:03,000 --> 00:04:06,000
|
| 407 |
+
So collection of type GrantedAuthority.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:04:06,000 --> 00:04:07,000
|
| 411 |
+
So we have to get object here.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:04:07,000 --> 00:04:10,000
|
| 415 |
+
So it's a new, so the class which implements
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:04:10,000 --> 00:04:12,000
|
| 419 |
+
because if you say GrantedAuthority, it's interface.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:04:12,000 --> 00:04:16,000
|
| 423 |
+
So the class which implements this is simple,
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:04:18,000 --> 00:04:21,000
|
| 427 |
+
GrantedAuthority, and this you can pass the authority.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:21,000 --> 00:04:22,000
|
| 431 |
+
So let's say, I will say this is user.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:22,000 --> 00:04:25,000
|
| 435 |
+
So by default, every user which I have in database
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:25,000 --> 00:04:27,000
|
| 439 |
+
will be by default user.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:27,000 --> 00:04:28,000
|
| 443 |
+
But again, it will make much more sense when
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:28,000 --> 00:04:31,000
|
| 447 |
+
to have extra column of authorities there.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:31,000 --> 00:04:34,000
|
| 451 |
+
And that's it, this is your UserPrincipal class,
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:34,000 --> 00:04:38,000
|
| 455 |
+
which I'm using it here, and looks like everything is there.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:38,000 --> 00:04:40,000
|
| 459 |
+
But the question is, will it work?
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:40,000 --> 00:04:43,000
|
| 463 |
+
Now finally, we are going to run this project,
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:43,000 --> 00:04:46,000
|
| 467 |
+
after four to five videos, we are running this project
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:46,000 --> 00:04:48,000
|
| 471 |
+
and we can get the error, and we'll solve it
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:48,000 --> 00:04:49,000
|
| 475 |
+
if you get the error.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:49,000 --> 00:04:50,000
|
| 479 |
+
Let's relaunch it.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:50,000 --> 00:04:53,000
|
| 483 |
+
Okay, there's still some problem here.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:53,000 --> 00:04:55,000
|
| 487 |
+
Maybe hard reloading is not working properly.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:55,000 --> 00:04:57,000
|
| 491 |
+
I will just restart the application manually. Let's restart.
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:57,000 --> 00:05:00,000
|
| 495 |
+
Okay, so at this point there's no problem.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:05:00,000 --> 00:05:03,000
|
| 499 |
+
I will just open my browser, again in incognito mode.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:05:03,000 --> 00:05:06,000
|
| 503 |
+
So I will say new incognito mode.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:05:06,000 --> 00:05:08,000
|
| 507 |
+
And I will go to localhost:8080,
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:05:08,000 --> 00:05:10,000
|
| 511 |
+
asking for the username password,
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:05:10,000 --> 00:05:12,000
|
| 515 |
+
and we'll enter the username password,
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:05:12,000 --> 00:05:14,000
|
| 519 |
+
which is mentioned in the database.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:05:14,000 --> 00:05:15,000
|
| 523 |
+
So let me go back to database to check.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:05:15,000 --> 00:05:17,000
|
| 527 |
+
So we have a username, kiran,
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:05:17,000 --> 00:05:20,000
|
| 531 |
+
and the password is n@789.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:05:20,000 --> 00:05:24,000
|
| 535 |
+
So yeah, so kiran, it's n@789.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:05:26,000 --> 00:05:28,000
|
| 539 |
+
First of all, we'll give a wrong password to check.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:28,000 --> 00:05:30,000
|
| 543 |
+
So I will just enter some random data
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:30,000 --> 00:05:31,000
|
| 547 |
+
and sign in, not working.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:31,000 --> 00:05:35,000
|
| 551 |
+
That's great. So the negative case is not working.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:35,000 --> 00:05:37,000
|
| 555 |
+
Let's try with positive values,
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:37,000 --> 00:05:41,000
|
| 559 |
+
n@789, click on sign in, worked.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:05:41,000 --> 00:05:41,000
|
| 563 |
+
Okay.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:05:41,000 --> 00:05:44,000
|
| 567 |
+
So feeling better, when things works out, it feels better.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:05:44,000 --> 00:05:46,000
|
| 571 |
+
Okay, why we are getting error,
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:05:46,000 --> 00:05:48,000
|
| 575 |
+
because we are not mapping for the homepage,
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:05:48,000 --> 00:05:49,000
|
| 579 |
+
you can see we have it here.
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:05:49,000 --> 00:05:51,000
|
| 583 |
+
Refresh, refresh, refresh. It works.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:05:51,000 --> 00:05:53,000
|
| 587 |
+
Now I will try a different user.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:05:53,000 --> 00:05:56,000
|
| 591 |
+
So again, incognito mode, localhost:8080,
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:05:56,000 --> 00:05:58,000
|
| 595 |
+
again asking for username, password.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:05:58,000 --> 00:06:02,000
|
| 599 |
+
This time we'll go for harsh and h@123.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:06:02,000 --> 00:06:07,000
|
| 603 |
+
So I just go back here, I will say harsh, h@123, it worked.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:06:09,000 --> 00:06:11,000
|
| 607 |
+
Okay? So yeah.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:06:11,000 --> 00:06:14,000
|
| 611 |
+
So now we are actually connecting with database.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:06:14,000 --> 00:06:16,000
|
| 615 |
+
And you can see at one point when I was entering
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:06:16,000 --> 00:06:19,000
|
| 619 |
+
a wrong username, we got the error which is User 404.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:06:19,000 --> 00:06:22,000
|
| 623 |
+
Okay, so if you don't have a proper username,
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:06:22,000 --> 00:06:24,000
|
| 627 |
+
it will give you 404.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:06:24,000 --> 00:06:25,000
|
| 631 |
+
And that's the message we have, which you're printing.
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:06:25,000 --> 00:06:29,000
|
| 635 |
+
And by doing this, we have implemented the entire stuff.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:06:29,000 --> 00:06:31,000
|
| 639 |
+
So what I'll do is in the next video, let's try
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:06:31,000 --> 00:06:34,000
|
| 643 |
+
to go all the steps one by one,
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:06:34,000 --> 00:06:35,000
|
| 647 |
+
which will make much more sense.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:06:35,000 --> 00:06:38,000
|
| 651 |
+
But what we have done in this video is we have created this
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:06:38,000 --> 00:06:41,000
|
| 655 |
+
particular class called UserPrincipal,
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:06:41,000 --> 00:06:42,000
|
| 659 |
+
which implements the UserDetails.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:06:42,000 --> 00:06:43,000
|
| 663 |
+
Of course, as I mentioned before,
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:06:43,000 --> 00:06:45,000
|
| 667 |
+
you can have a different name,
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:06:45,000 --> 00:06:48,000
|
| 671 |
+
but then principal simply means a current user, okay?
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:06:48,000 --> 00:06:50,000
|
| 675 |
+
So whenever you are authenticating a user,
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:06:50,000 --> 00:06:52,000
|
| 679 |
+
we call them as principals.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:06:52,000 --> 00:06:54,000
|
| 683 |
+
And in this principal, basically we have multiple methods
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:06:54,000 --> 00:06:57,000
|
| 687 |
+
to work with, like getAuthorities, getUsername,
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:06:57,000 --> 00:07:00,000
|
| 691 |
+
getPassword, and multiple settings here.
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:07:00,000 --> 00:07:02,000
|
| 695 |
+
And if you want to have this feature in your project
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:07:02,000 --> 00:07:04,000
|
| 699 |
+
where maybe after a few days,
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:07:04,000 --> 00:07:06,000
|
| 703 |
+
you want to expire the credentials,
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:07:06,000 --> 00:07:08,000
|
| 707 |
+
after a few days, maybe you want to,
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:07:08,000 --> 00:07:09,000
|
| 711 |
+
if there's an inactive for a long time,
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:07:09,000 --> 00:07:11,000
|
| 715 |
+
you can lock the account, you can expire the account,
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:07:11,000 --> 00:07:13,000
|
| 719 |
+
you can do all those settings here.
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:07:13,000 --> 00:07:14,000
|
| 723 |
+
But at this point I'm not doing it.
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:07:14,000 --> 00:07:16,000
|
| 727 |
+
So yeah, in the next video, let's try
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:07:16,000 --> 00:07:17,000
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(soft bright music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:05,000
|
| 7 |
+
-: So let's try to understand the project here.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:08,000
|
| 11 |
+
So what I'll do is let's start with the security config.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:08,000 --> 00:00:09,000
|
| 15 |
+
Now what we are trying to do is
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:09,000 --> 00:00:13,000
|
| 19 |
+
basically we want to verify the user from a database.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:13,000 --> 00:00:15,000
|
| 23 |
+
The data database which I'm using is Postgres.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:15,000 --> 00:00:16,000
|
| 27 |
+
So in our date table,
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:16,000 --> 00:00:19,000
|
| 31 |
+
basically we have the ID, username and password.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:19,000 --> 00:00:20,000
|
| 35 |
+
The table name is users.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:20,000 --> 00:00:21,000
|
| 39 |
+
And to achieve that,
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:21,000 --> 00:00:24,000
|
| 43 |
+
we have to change our authentication provider
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:24,000 --> 00:00:26,000
|
| 47 |
+
and we want to say that I want to connect with database.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:26,000 --> 00:00:30,000
|
| 51 |
+
And to do that we have to use DAO authentication provider
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:30,000 --> 00:00:32,000
|
| 55 |
+
because DAO is your database access.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:32,000 --> 00:00:33,000
|
| 59 |
+
And then to achieve that,
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:33,000 --> 00:00:36,000
|
| 63 |
+
we have to specify the user details service
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:36,000 --> 00:00:38,000
|
| 67 |
+
because if authentication provider wants to work,
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:38,000 --> 00:00:41,000
|
| 71 |
+
it will ask you for the service class.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:41,000 --> 00:00:42,000
|
| 75 |
+
Now this service is an interface
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:42,000 --> 00:00:43,000
|
| 79 |
+
which is user detailed service.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:43,000 --> 00:00:45,000
|
| 83 |
+
We have to implement it.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:45,000 --> 00:00:46,000
|
| 87 |
+
And the way we have implemented
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:46,000 --> 00:00:50,000
|
| 91 |
+
is by creating a class called My User Detailed Service,
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:50,000 --> 00:00:52,000
|
| 95 |
+
which implements the user detailed service
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:52,000 --> 00:00:54,000
|
| 99 |
+
in which you have only one method,
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:54,000 --> 00:00:55,000
|
| 103 |
+
which is load user by username.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:00:55,000 --> 00:00:58,000
|
| 107 |
+
But then since the data is coming from database,
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:00:58,000 --> 00:01:00,000
|
| 111 |
+
we also need a user repo layer.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:00,000 --> 00:01:03,000
|
| 115 |
+
Now using this repo, which has a method
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:03,000 --> 00:01:07,000
|
| 119 |
+
called find user by username, and we are using JPA,
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:07,000 --> 00:01:08,000
|
| 123 |
+
so we don't have to write their skill queries.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:08,000 --> 00:01:11,000
|
| 127 |
+
What we are doing is we are firing a method
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:11,000 --> 00:01:12,000
|
| 131 |
+
or we are calling a method
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:12,000 --> 00:01:14,000
|
| 135 |
+
which returns you the object of user.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:14,000 --> 00:01:15,000
|
| 139 |
+
If the user is there,
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:15,000 --> 00:01:18,000
|
| 143 |
+
then of course you have to return the object of user.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:18,000 --> 00:01:19,000
|
| 147 |
+
But if the user is not there,
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:19,000 --> 00:01:22,000
|
| 151 |
+
we have to throw an exception,
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:22,000 --> 00:01:24,000
|
| 155 |
+
but (indistinct) how will we return this user?
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:24,000 --> 00:01:27,000
|
| 159 |
+
So we have to basically wrap this user object
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:27,000 --> 00:01:29,000
|
| 163 |
+
into a user principle,
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:29,000 --> 00:01:33,000
|
| 167 |
+
for extra things like expiry and all those stuff.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:33,000 --> 00:01:34,000
|
| 171 |
+
And to achieve that,
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:34,000 --> 00:01:37,000
|
| 175 |
+
we have to implement the user details interface.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:37,000 --> 00:01:39,000
|
| 179 |
+
And we have done that in this class,
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:39,000 --> 00:01:41,000
|
| 183 |
+
which is user principle.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:41,000 --> 00:01:42,000
|
| 187 |
+
Now, user principle is a class
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:42,000 --> 00:01:43,000
|
| 191 |
+
which implements the user details
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:43,000 --> 00:01:45,000
|
| 195 |
+
and principle means current user.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:45,000 --> 00:01:49,000
|
| 199 |
+
And in this particular class we have multiple methods,
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:49,000 --> 00:01:50,000
|
| 203 |
+
three methods, one for authority,
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:50,000 --> 00:01:52,000
|
| 207 |
+
one for username, one for password.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:52,000 --> 00:01:54,000
|
| 211 |
+
Apart from this, others are for your expiry,
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:01:54,000 --> 00:01:57,000
|
| 215 |
+
for your account, and for your credentials.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:01:57,000 --> 00:02:00,000
|
| 219 |
+
And then, you know, basically just to give you a summary,
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:00,000 --> 00:02:04,000
|
| 223 |
+
in a bank account, you get a notification
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:04,000 --> 00:02:05,000
|
| 227 |
+
after every one month or three months
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:05,000 --> 00:02:07,000
|
| 231 |
+
that change your password.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:07,000 --> 00:02:09,000
|
| 235 |
+
That's how they basically set this up. Okay?
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:09,000 --> 00:02:11,000
|
| 239 |
+
So yeah, but then we have not done that.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:11,000 --> 00:02:14,000
|
| 243 |
+
So we have only focused on this three.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:14,000 --> 00:02:17,000
|
| 247 |
+
And all this thing, basically you have your table
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:17,000 --> 00:02:19,000
|
| 251 |
+
and your class, which represents that,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:19,000 --> 00:02:20,000
|
| 255 |
+
which is your user class,
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:20,000 --> 00:02:22,000
|
| 259 |
+
which is an entity which has three columns.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:22,000 --> 00:02:25,000
|
| 263 |
+
Now depended upon your number of columns in the table,
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:25,000 --> 00:02:25,000
|
| 267 |
+
this will change.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:25,000 --> 00:02:28,000
|
| 271 |
+
So if you have three columns, you'll have three properties.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:28,000 --> 00:02:30,000
|
| 275 |
+
If you have five columns, you'll have five properties here.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:30,000 --> 00:02:32,000
|
| 279 |
+
Which you want to map and that's how it is working.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:32,000 --> 00:02:33,000
|
| 283 |
+
A few other changes which you have made
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:33,000 --> 00:02:34,000
|
| 287 |
+
in the operation properties,
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:34,000 --> 00:02:36,000
|
| 291 |
+
we have specified the properties
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:36,000 --> 00:02:38,000
|
| 295 |
+
to connect with the Postgres.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:38,000 --> 00:02:40,000
|
| 299 |
+
If you have a different DBMS, you will change this.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:40,000 --> 00:02:43,000
|
| 303 |
+
And also in the xml file, we have to mention two things,
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:43,000 --> 00:02:46,000
|
| 307 |
+
the JP repository, the data JPA,
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:46,000 --> 00:02:48,000
|
| 311 |
+
and we have to mention the post quiz.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:48,000 --> 00:02:50,000
|
| 315 |
+
And by doing this, the security is working.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:02:50,000 --> 00:02:54,000
|
| 319 |
+
Your application is secure with the help of database,
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:02:54,000 --> 00:02:56,000
|
| 323 |
+
but it's not completely secure
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:02:56,000 --> 00:03:00,000
|
| 327 |
+
because we are still storing data in the plain text.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:00,000 --> 00:03:01,000
|
| 331 |
+
We have to change this.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:01,000 --> 00:03:03,000
|
| 335 |
+
Let's do that in the upcoming videos.
|
| 336 |
+
|
20 - Spring Security/024 What is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--> 00:00:09,000
|
| 15 |
+
Basically, when I say data, I'm talking about the users
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:09,000 --> 00:00:11,000
|
| 19 |
+
and then we can validate them with the help
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:11,000 --> 00:00:12,000
|
| 23 |
+
of username, password.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:12,000 --> 00:00:16,000
|
| 27 |
+
And we are securing this with the help of spring security.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:16,000 --> 00:00:18,000
|
| 31 |
+
And for that we have created multiple files.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:18,000 --> 00:00:21,000
|
| 35 |
+
If you look at the logic, logic files are very less.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:21,000 --> 00:00:23,000
|
| 39 |
+
If you compare here, we got hello controller,
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:23,000 --> 00:00:25,000
|
| 43 |
+
student controller, student.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:25,000 --> 00:00:26,000
|
| 47 |
+
I think that's it.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:26,000 --> 00:00:28,000
|
| 51 |
+
Those are your actual logic files
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:28,000 --> 00:00:32,000
|
| 55 |
+
and others are your configuration files for Spring Security.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:32,000 --> 00:00:34,000
|
| 59 |
+
And maybe you're thinking, security files
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:34,000 --> 00:00:36,000
|
| 63 |
+
are more than the actual logic.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:36,000 --> 00:00:38,000
|
| 67 |
+
See, once you talk about the big application,
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:38,000 --> 00:00:41,000
|
| 71 |
+
you'll be having more files, not just two.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:41,000 --> 00:00:42,000
|
| 75 |
+
You'll be having multiple there,
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:42,000 --> 00:00:44,000
|
| 79 |
+
maybe 50, 60 doesn't matter.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:44,000 --> 00:00:46,000
|
| 83 |
+
But the configuration files are limited.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:46,000 --> 00:00:48,000
|
| 87 |
+
So you can see we have this number of config files.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:48,000 --> 00:00:51,000
|
| 91 |
+
It might increase and it will in the upcoming videos.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:51,000 --> 00:00:53,000
|
| 95 |
+
But then this is the basic layout out we have.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:53,000 --> 00:00:55,000
|
| 99 |
+
And everything is working at this point, right?
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:55,000 --> 00:00:57,000
|
| 103 |
+
We were able to run this application,
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:00:57,000 --> 00:00:59,000
|
| 107 |
+
we were able to log in as well.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:00:59,000 --> 00:01:00,000
|
| 111 |
+
But there's one little problem.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:00,000 --> 00:01:02,000
|
| 115 |
+
The problem is, not a little problem.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:02,000 --> 00:01:04,000
|
| 119 |
+
It's actually a big problem.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:04,000 --> 00:01:05,000
|
| 123 |
+
If we look at our database,
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:05,000 --> 00:01:07,000
|
| 127 |
+
we are storing our password in a plain text,
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:07,000 --> 00:01:09,000
|
| 131 |
+
not a good sight, right?
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:09,000 --> 00:01:13,000
|
| 135 |
+
So not just we are storing data in a plain text,
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:13,000 --> 00:01:16,000
|
| 139 |
+
but also we are transferring this data in a plain text.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:16,000 --> 00:01:19,000
|
| 143 |
+
So how do you secure this?
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:19,000 --> 00:01:20,000
|
| 147 |
+
So one thing you can do
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:20,000 --> 00:01:22,000
|
| 151 |
+
is you can use something called a cryptography here.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:22,000 --> 00:01:25,000
|
| 155 |
+
Now in cryptography, basically we have a concept
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:25,000 --> 00:01:29,000
|
| 159 |
+
of cryptography where you encrypt a message
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:29,000 --> 00:01:31,000
|
| 163 |
+
and then on the other hand, you decrypt it.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:31,000 --> 00:01:34,000
|
| 167 |
+
So basically what I'm saying is when you want
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:34,000 --> 00:01:37,000
|
| 171 |
+
to store a password, you can encrypt a password with a key,
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:37,000 --> 00:01:39,000
|
| 175 |
+
and then when you want to verify the password,
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:39,000 --> 00:01:42,000
|
| 179 |
+
you can decrypt the data and you can verify the password.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:42,000 --> 00:01:46,000
|
| 183 |
+
Example, let's say we have storing h@123 here.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:46,000 --> 00:01:49,000
|
| 187 |
+
we can change this value, we can encrypt this value.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:49,000 --> 00:01:51,000
|
| 191 |
+
And maybe the new output you got is,
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:51,000 --> 00:01:54,000
|
| 195 |
+
let me write the new output here, some random value here.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:54,000 --> 00:01:56,000
|
| 199 |
+
Let's say this is your output for this encryption.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:56,000 --> 00:01:58,000
|
| 203 |
+
And then this is what you will be storing
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:58,000 --> 00:02:00,000
|
| 207 |
+
in a password field in the database.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:00,000 --> 00:02:02,000
|
| 211 |
+
When you want to verify,
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:02,000 --> 00:02:04,000
|
| 215 |
+
of course a user will not enter this value.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:04,000 --> 00:02:06,000
|
| 219 |
+
User will enter h at rate 123.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:06,000 --> 00:02:08,000
|
| 223 |
+
Then you have to decrypt this
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:08,000 --> 00:02:10,000
|
| 227 |
+
and you have to get the password
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:10,000 --> 00:02:12,000
|
| 231 |
+
and you can verify that point.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:12,000 --> 00:02:12,000
|
| 235 |
+
That's one way.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:12,000 --> 00:02:13,000
|
| 239 |
+
The problem with this is
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:13,000 --> 00:02:15,000
|
| 243 |
+
when you have the encryption technique
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:15,000 --> 00:02:17,000
|
| 247 |
+
for cryptography, you have a key, right?
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:17,000 --> 00:02:19,000
|
| 251 |
+
And some way it is not that safe
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:19,000 --> 00:02:21,000
|
| 255 |
+
because if you get the key, you are gone.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:21,000 --> 00:02:22,000
|
| 259 |
+
All the passwords are linked.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:22,000 --> 00:02:24,000
|
| 263 |
+
The other way you can do
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:24,000 --> 00:02:25,000
|
| 267 |
+
is you can have a one way encryption,
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:25,000 --> 00:02:27,000
|
| 271 |
+
which is called hashing basically.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:27,000 --> 00:02:30,000
|
| 275 |
+
In hashing, you don't decrypt the message.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:30,000 --> 00:02:34,000
|
| 279 |
+
Example, if this is your, okay, this is not a valid one
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:34,000 --> 00:02:36,000
|
| 283 |
+
because it will beg a decimal.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:36,000 --> 00:02:39,000
|
| 287 |
+
But for that matter, let's say we have this value.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:39,000 --> 00:02:42,000
|
| 291 |
+
Now let's say this is your hash, okay?
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:42,000 --> 00:02:44,000
|
| 295 |
+
Now hash is basically one way.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:44,000 --> 00:02:46,000
|
| 299 |
+
So for every data, you will get only one hash.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:46,000 --> 00:02:48,000
|
| 303 |
+
There's no collision here.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:48,000 --> 00:02:50,000
|
| 307 |
+
Now what will happen is you can't get it back.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:50,000 --> 00:02:53,000
|
| 311 |
+
So you can't simply go from this particular output
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:53,000 --> 00:02:57,000
|
| 315 |
+
to h at 123, because that's one way.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:02:57,000 --> 00:02:58,000
|
| 319 |
+
Now, how do we verify this?
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:02:58,000 --> 00:03:02,000
|
| 323 |
+
So every time a user enters h at rate 123,
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:02,000 --> 00:03:04,000
|
| 327 |
+
then you convert that into a hash again.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:04,000 --> 00:03:06,000
|
| 331 |
+
And then you compare this two hash.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:06,000 --> 00:03:07,000
|
| 335 |
+
If they are matching, that's good, right?
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:07,000 --> 00:03:09,000
|
| 339 |
+
Now what are the algorithms we have?
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:09,000 --> 00:03:11,000
|
| 343 |
+
So for hashing, we have different algorithms available.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:11,000 --> 00:03:15,000
|
| 347 |
+
We got MD5, we got SHA256,
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:15,000 --> 00:03:17,000
|
| 351 |
+
but then we want a more secure way of doing it
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:17,000 --> 00:03:20,000
|
| 355 |
+
and the secure way of doing it, what if you can use SHA,
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:20,000 --> 00:03:23,000
|
| 359 |
+
but not just in one round, in multiple rounds?
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:23,000 --> 00:03:26,000
|
| 363 |
+
So what hashing does is, basically it converts your text
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:26,000 --> 00:03:29,000
|
| 367 |
+
into a numbers using hashing algorithm.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:29,000 --> 00:03:31,000
|
| 371 |
+
This is one of the algorithm we have.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:31,000 --> 00:03:33,000
|
| 375 |
+
And then it will do only once.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:33,000 --> 00:03:35,000
|
| 379 |
+
But what if you can repeat this process multiple times,
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:35,000 --> 00:03:38,000
|
| 383 |
+
1, 2, times, 10 times, 100 times?
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:38,000 --> 00:03:41,000
|
| 387 |
+
And if we can do that, it'll be difficult for anyone
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:41,000 --> 00:03:43,000
|
| 391 |
+
to hack or to get the password.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:43,000 --> 00:03:45,000
|
| 395 |
+
And to achieve that, we are going
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:45,000 --> 00:03:46,000
|
| 399 |
+
to use some other technique
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:46,000 --> 00:03:50,000
|
| 403 |
+
and we have to use algorithm called bcrypt.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:03:50,000 --> 00:03:52,000
|
| 407 |
+
So how do we use bcrypt here?
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:03:52,000 --> 00:03:54,000
|
| 411 |
+
And you will, it will make much more sense
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:03:54,000 --> 00:03:56,000
|
| 415 |
+
once we start implementing it.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:03:56,000 --> 00:04:00,000
|
| 419 |
+
But bcrypt will help you to generate a password
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:04:00,000 --> 00:04:02,000
|
| 423 |
+
or it will encode your password.
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:04:02,000 --> 00:04:04,000
|
| 427 |
+
To show an example, I will open my browser, I'll search
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:04,000 --> 00:04:08,000
|
| 431 |
+
for bcrypt password generator, you can see here.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:08,000 --> 00:04:09,000
|
| 435 |
+
And I will go through this website,
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:09,000 --> 00:04:12,000
|
| 439 |
+
which I have used multiple times and it is not coming up.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:12,000 --> 00:04:14,000
|
| 443 |
+
All I can see is ads.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:14,000 --> 00:04:16,000
|
| 447 |
+
Okay, it's here, second only.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:16,000 --> 00:04:19,000
|
| 451 |
+
So you got this website, which is browser link.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:19,000 --> 00:04:21,000
|
| 455 |
+
And here basically you can get your password.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:21,000 --> 00:04:24,000
|
| 459 |
+
So let's say I want to get the bcrypt password.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:24,000 --> 00:04:27,000
|
| 463 |
+
So I will enter maybe h at the rate 123,
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:27,000 --> 00:04:29,000
|
| 467 |
+
and I can click on bcrypt.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:29,000 --> 00:04:32,000
|
| 471 |
+
So you can see this is the encoded format.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:32,000 --> 00:04:34,000
|
| 475 |
+
Okay, so we are using a password encoder now,
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:34,000 --> 00:04:37,000
|
| 479 |
+
which is bcrypt, and it, this is your encoded format.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:37,000 --> 00:04:38,000
|
| 483 |
+
And if you look at this format,
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:38,000 --> 00:04:40,000
|
| 487 |
+
of course you have some weird values here,
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:40,000 --> 00:04:41,000
|
| 491 |
+
but if you look at the first one,
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:41,000 --> 00:04:44,000
|
| 495 |
+
so $2A is a version for bcrypt.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:44,000 --> 00:04:46,000
|
| 499 |
+
So that different versions are available.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:04:46,000 --> 00:04:48,000
|
| 503 |
+
We got 2A, 2Y also.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:04:48,000 --> 00:04:50,000
|
| 507 |
+
And then after this we have $10,
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:04:50,000 --> 00:04:52,000
|
| 511 |
+
which is basically your number of rounds.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:04:52,000 --> 00:04:54,000
|
| 515 |
+
So you can see, I'm saying 10 rounds here.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:04:54,000 --> 00:04:55,000
|
| 519 |
+
So by default it will be 10 rounds,
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:04:55,000 --> 00:04:57,000
|
| 523 |
+
but you can change the rounds here.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:04:57,000 --> 00:04:59,000
|
| 527 |
+
So I can say 12 rounds.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:04:59,000 --> 00:05:00,000
|
| 531 |
+
And now when I click on bcrypt,
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:05:00,000 --> 00:05:02,000
|
| 535 |
+
you will get a different number.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:05:02,000 --> 00:05:04,000
|
| 539 |
+
Of course, you will get a different string here.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:04,000 --> 00:05:07,000
|
| 543 |
+
And we got $12, which is 12 rounds.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:07,000 --> 00:05:08,000
|
| 547 |
+
Okay.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:08,000 --> 00:05:10,000
|
| 551 |
+
Now when I say 12 rounds,
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:10,000 --> 00:05:12,000
|
| 555 |
+
it is actually two raised to 12 rounds.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:12,000 --> 00:05:14,000
|
| 559 |
+
It's not just 12 rounds, okay?
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:05:14,000 --> 00:05:16,000
|
| 563 |
+
So it's a huge number.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:05:16,000 --> 00:05:17,000
|
| 567 |
+
So if you divide in half to leave with 10
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:05:17,000 --> 00:05:18,000
|
| 571 |
+
so it is 2 raised to 10,
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:05:18,000 --> 00:05:20,000
|
| 575 |
+
which is that number of rounds,
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:05:20,000 --> 00:05:21,000
|
| 579 |
+
it will take 200, this text here
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:05:21,000 --> 00:05:24,000
|
| 583 |
+
So it is very difficult for anyone to hack it.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:05:24,000 --> 00:05:26,000
|
| 587 |
+
So even if they want to do a brute force,
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:05:26,000 --> 00:05:28,000
|
| 591 |
+
they have to do this multiple times.
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:05:28,000 --> 00:05:31,000
|
| 595 |
+
And every time you do a hashing, it takes some time,
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:05:31,000 --> 00:05:33,000
|
| 599 |
+
it takes some computation.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:05:33,000 --> 00:05:34,000
|
| 603 |
+
So that means if you do computation,
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:05:34,000 --> 00:05:37,000
|
| 607 |
+
let's say if you do it only for once, one round,
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:05:37,000 --> 00:05:38,000
|
| 611 |
+
let's say if it takes one milliseconds,
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:05:38,000 --> 00:05:41,000
|
| 615 |
+
imagine if you do 4,000 rounds.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:05:41,000 --> 00:05:43,000
|
| 619 |
+
That's huge, right?
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:05:43,000 --> 00:05:46,000
|
| 623 |
+
So it will make sure that it will be less vulnerable
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:05:46,000 --> 00:05:50,000
|
| 627 |
+
compared to the plain text and even for SHA256.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:05:50,000 --> 00:05:52,000
|
| 631 |
+
Now how we are going to use this in our code?
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:05:52,000 --> 00:05:55,000
|
| 635 |
+
That's what we are going to see on the upcoming videos.
|
| 636 |
+
|
20 - Spring Security/025 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.25%20User%20Registration/spring-sec-demo
|
20 - Spring Security/025 User Registration_en.srt
ADDED
|
@@ -0,0 +1,524 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(gentle music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:06,000
|
| 7 |
+
-: So now, we have to implement the Password Encoder,
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:06,000 --> 00:00:07,000
|
| 11 |
+
which is Bcrypt.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:07,000 --> 00:00:09,000
|
| 15 |
+
But before that, we want to also create a user option.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:09,000 --> 00:00:12,000
|
| 19 |
+
So basically, I want an option where a user can register,
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:12,000 --> 00:00:13,000
|
| 23 |
+
right?
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:13,000 --> 00:00:16,000
|
| 27 |
+
And to do that, what I will do is I will create a controller
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:16,000 --> 00:00:18,000
|
| 31 |
+
where a user can send a request to register.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:18,000 --> 00:00:21,000
|
| 35 |
+
And I will save this as UserController
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:21,000 --> 00:00:23,000
|
| 39 |
+
in the controller package.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:23,000 --> 00:00:28,000
|
| 43 |
+
And we need to make sure that this is RestController.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:28,000 --> 00:00:30,000
|
| 47 |
+
And then, we'll create an endpoint.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:30,000 --> 00:00:32,000
|
| 51 |
+
So the endpoint here will be "public",
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:32,000 --> 00:00:35,000
|
| 55 |
+
and I want to return the same user, which I'm creating.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:35,000 --> 00:00:37,000
|
| 59 |
+
So I will say a "User".
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:37,000 --> 00:00:39,000
|
| 63 |
+
But unfortunately, we don't have.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:39,000 --> 00:00:40,000
|
| 67 |
+
Okay, we do have a user, okay?
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:40,000 --> 00:00:41,000
|
| 71 |
+
So we can say "User".
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:41,000 --> 00:00:44,000
|
| 75 |
+
And then I will say "register"
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:44,000 --> 00:00:46,000
|
| 79 |
+
in which I am going to accept the object of register.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:46,000 --> 00:00:50,000
|
| 83 |
+
So I will say "RequestBody User_user".
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:52,000 --> 00:00:55,000
|
| 87 |
+
And then, let's return the same user.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:55,000 --> 00:00:58,000
|
| 91 |
+
Okay, and then this should be mapped with a "Get".
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:58,000 --> 00:00:59,000
|
| 95 |
+
No, not GetMapping, PostMapping,
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:59,000 --> 00:01:01,000
|
| 99 |
+
because we will be sending data.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:01,000 --> 00:01:05,000
|
| 103 |
+
And here I will say "register".
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:05,000 --> 00:01:07,000
|
| 107 |
+
So now, using this particular URL,
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:07,000 --> 00:01:09,000
|
| 111 |
+
we can send a request for the registration,
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:09,000 --> 00:01:10,000
|
| 115 |
+
and then we are simply returning it.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:10,000 --> 00:01:12,000
|
| 119 |
+
Of course, I want to store that somewhere, right?
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:12,000 --> 00:01:14,000
|
| 123 |
+
So where do you want to store it?
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:14,000 --> 00:01:15,000
|
| 127 |
+
Of course, in the database.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:15,000 --> 00:01:20,000
|
| 131 |
+
And to do that, I will create a service class for the user.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:20,000 --> 00:01:22,000
|
| 135 |
+
And I will say, this is UserService.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:24,000 --> 00:01:26,000
|
| 139 |
+
I will integrate this with a Service.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:26,000 --> 00:01:28,000
|
| 143 |
+
And then, here we'll have a method.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:28,000 --> 00:01:30,000
|
| 147 |
+
So I will say "public_User",
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:30,000 --> 00:01:34,000
|
| 151 |
+
and I will say, "Save", maybe "saveUser".
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:34,000 --> 00:01:36,000
|
| 155 |
+
And here, let's import the package.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:36,000 --> 00:01:37,000
|
| 159 |
+
Okay, so from the controller,
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:37,000 --> 00:01:39,000
|
| 163 |
+
basically I have to send the user object
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:39,000 --> 00:01:43,000
|
| 167 |
+
and then I can save that object in database, okay?
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:43,000 --> 00:01:45,000
|
| 171 |
+
But then to store that in database,
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:45,000 --> 00:01:47,000
|
| 175 |
+
let me return the same object first.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:47,000 --> 00:01:48,000
|
| 179 |
+
At this point, we are doing that.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:48,000 --> 00:01:50,000
|
| 183 |
+
Let's send the same object.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:50,000 --> 00:01:51,000
|
| 187 |
+
But I want to store it in database, right?
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:51,000 --> 00:01:53,000
|
| 191 |
+
So for database, we already have a Repo.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:53,000 --> 00:01:56,000
|
| 195 |
+
So if you see we do have a UserRepo, and we can use this.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:56,000 --> 00:02:00,000
|
| 199 |
+
So I can simply create object of UserRepo.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:02:00,000 --> 00:02:01,000
|
| 203 |
+
I will say Repo.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:01,000 --> 00:02:04,000
|
| 207 |
+
And then we have to AutoWire this.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:04,000 --> 00:02:05,000
|
| 211 |
+
Okay.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:05,000 --> 00:02:06,000
|
| 215 |
+
And now with this particular Repo,
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:06,000 --> 00:02:11,000
|
| 219 |
+
I can call it save and I can pass the user.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:11,000 --> 00:02:13,000
|
| 223 |
+
So basically, whatever data I'm getting from the controller,
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:13,000 --> 00:02:15,000
|
| 227 |
+
I'm just passing it to the repository layer.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:15,000 --> 00:02:18,000
|
| 231 |
+
And we are calling it the save method.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:18,000 --> 00:02:19,000
|
| 235 |
+
And of course, the repository layer will
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:19,000 --> 00:02:20,000
|
| 239 |
+
take care of the method execution
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:20,000 --> 00:02:22,000
|
| 243 |
+
because we are using .jpa here, okay?
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:22,000 --> 00:02:23,000
|
| 247 |
+
And I hope this will work.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:23,000 --> 00:02:25,000
|
| 251 |
+
So basically, I'm passing the object,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:25,000 --> 00:02:27,000
|
| 255 |
+
I'm just asking service layer to add it.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:27,000 --> 00:02:29,000
|
| 259 |
+
And we have not implemented Bcrypt yet.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:29,000 --> 00:02:30,000
|
| 263 |
+
We'll do that.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:30,000 --> 00:02:31,000
|
| 267 |
+
I'm just going step by step.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:31,000 --> 00:02:32,000
|
| 271 |
+
I want to register the user first.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:32,000 --> 00:02:35,000
|
| 275 |
+
And this is looking good.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:35,000 --> 00:02:38,000
|
| 279 |
+
So let me see if the project is running, it's not.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:38,000 --> 00:02:39,000
|
| 283 |
+
So I will just run this.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:39,000 --> 00:02:42,000
|
| 287 |
+
And now, let's head back to our Postman.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:42,000 --> 00:02:44,000
|
| 291 |
+
The request which we are sending now is for register.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:44,000 --> 00:02:46,000
|
| 295 |
+
Let's verify the Headers
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:46,000 --> 00:02:48,000
|
| 299 |
+
and in fact, authorization.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:48,000 --> 00:02:49,000
|
| 303 |
+
This should not be "telusko",
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:49,000 --> 00:02:51,000
|
| 307 |
+
this should be,
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:51,000 --> 00:02:55,000
|
| 311 |
+
let's go with harsh and h@123.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:55,000 --> 00:02:58,000
|
| 315 |
+
So I'll say this is harsh and h@123.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:02:58,000 --> 00:03:01,000
|
| 319 |
+
That's the Username-Password we have in table.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:01,000 --> 00:03:04,000
|
| 323 |
+
And now, we have to pass data as well.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:04,000 --> 00:03:05,000
|
| 327 |
+
So basically, we already have some data here.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:05,000 --> 00:03:06,000
|
| 331 |
+
I don't want to use this.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:06,000 --> 00:03:08,000
|
| 335 |
+
Let's say, I want to say "id" is 3.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:08,000 --> 00:03:10,000
|
| 339 |
+
Name, I will register myself
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:10,000 --> 00:03:12,000
|
| 343 |
+
because in database, I don't have my name.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:12,000 --> 00:03:13,000
|
| 347 |
+
So I'll say Navin.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:13,000 --> 00:03:15,000
|
| 351 |
+
And the password, so it should be not Name,
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:15,000 --> 00:03:16,000
|
| 355 |
+
it should be "username".
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:16,000 --> 00:03:20,000
|
| 359 |
+
This should match with your class, the user class.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:20,000 --> 00:03:22,000
|
| 363 |
+
And this is your password.
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:22,000 --> 00:03:26,000
|
| 367 |
+
And the password I want to store is "n@345".
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:28,000 --> 00:03:30,000
|
| 371 |
+
Okay, that's the password I have.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:30,000 --> 00:03:33,000
|
| 375 |
+
And now, let's click on Send.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:33,000 --> 00:03:35,000
|
| 379 |
+
Usually, I will give a wrong password just to see.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:35,000 --> 00:03:38,000
|
| 383 |
+
Let's say I'm passing password four,
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:38,000 --> 00:03:39,000
|
| 387 |
+
fourth authorization,
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:39,000 --> 00:03:41,000
|
| 391 |
+
and I'm creating a new record with this data.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:41,000 --> 00:03:42,000
|
| 395 |
+
Click on Send, it failed.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:42,000 --> 00:03:44,000
|
| 399 |
+
You can see we got 401.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:44,000 --> 00:03:47,000
|
| 403 |
+
Let's pass the right password, which is 123.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:03:47,000 --> 00:03:48,000
|
| 407 |
+
Click on Send.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:03:48,000 --> 00:03:51,000
|
| 411 |
+
And you can see that this time we got 200.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:03:51,000 --> 00:03:53,000
|
| 415 |
+
And we also got the data in back, which is this data,
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:03:53,000 --> 00:03:54,000
|
| 419 |
+
which is stored in database.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:03:54,000 --> 00:03:56,000
|
| 423 |
+
How do I verify this?
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:03:56,000 --> 00:03:59,000
|
| 427 |
+
Let's go back to our database and say "select * from users"
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:03:59,000 --> 00:04:00,000
|
| 431 |
+
Run.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:00,000 --> 00:04:02,000
|
| 435 |
+
Okay, it's not working.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:02,000 --> 00:04:05,000
|
| 439 |
+
So maybe I have to reload.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:06,000 --> 00:04:08,000
|
| 443 |
+
Okay, you know what?
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:08,000 --> 00:04:11,000
|
| 447 |
+
I'm not calling anyone "Service service" layer, my bad.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:11,000 --> 00:04:16,000
|
| 451 |
+
So this should be object of "private UserService service".
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:18,000 --> 00:04:21,000
|
| 455 |
+
And then we have to annotate this with "Autowired".
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:21,000 --> 00:04:23,000
|
| 459 |
+
And now, I can use a service.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:23,000 --> 00:04:26,000
|
| 463 |
+
In fact, service returns this object, right?
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:26,000 --> 00:04:29,000
|
| 467 |
+
So it's a "service.saveUser" and pass the user object.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:29,000 --> 00:04:31,000
|
| 471 |
+
This is the steps which was missing.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:31,000 --> 00:04:32,000
|
| 475 |
+
Let's restart.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:32,000 --> 00:04:34,000
|
| 479 |
+
I don't want to depend upon the hot reload.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:34,000 --> 00:04:37,000
|
| 483 |
+
Okay, let's go back to Postman, answer issue again.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:37,000 --> 00:04:40,000
|
| 487 |
+
Okay, this time also, we got this user here,
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:40,000 --> 00:04:42,000
|
| 491 |
+
but the way you can verify that
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:42,000 --> 00:04:44,000
|
| 495 |
+
is with the help of database and it worked.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:44,000 --> 00:04:45,000
|
| 499 |
+
You can see we got a new user.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:04:45,000 --> 00:04:48,000
|
| 503 |
+
So this is also layer, which we have done.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:04:48,000 --> 00:04:49,000
|
| 507 |
+
And now, in the next video,
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:04:49,000 --> 00:04:52,000
|
| 511 |
+
let's try to implement Bcrypt here.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:04:52,000 --> 00:04:54,000
|
| 515 |
+
So basically, I want to create a user
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:04:54,000 --> 00:04:56,000
|
| 519 |
+
with a Bcrypt implementation.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:04:56,000 --> 00:04:58,000
|
| 523 |
+
So see you in the next video.
|
| 524 |
+
|
20 - Spring Security/026 BCrypt Encoding for User Registration_en.srt
ADDED
|
@@ -0,0 +1,568 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(logo chimes)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:05,000
|
| 7 |
+
-: Now, let's implement the bcrypt.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:06,000
|
| 11 |
+
But, you know,
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:06,000 --> 00:00:08,000
|
| 15 |
+
even if you implement bcrypt for the registration
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:08,000 --> 00:00:10,000
|
| 19 |
+
and for the searching, see, what happens is,
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:10,000 --> 00:00:12,000
|
| 23 |
+
when you register a new user,
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:12,000 --> 00:00:14,000
|
| 27 |
+
and even if you send request
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:14,000 --> 00:00:15,000
|
| 31 |
+
with this data which you're sending.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:15,000 --> 00:00:16,000
|
| 35 |
+
Let's say we have a new user.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:16,000 --> 00:00:18,000
|
| 39 |
+
This time we'll say 4.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:18,000 --> 00:00:20,000
|
| 43 |
+
And I will say avni.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:20,000 --> 00:00:24,000
|
| 47 |
+
And this is let's say a@123.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:24,000 --> 00:00:27,000
|
| 51 |
+
Now, if this is my new user, it should work, right?
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:27,000 --> 00:00:28,000
|
| 55 |
+
But then, the moment you implement bcrypt,
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:28,000 --> 00:00:31,000
|
| 59 |
+
and if you go back to your authorization,
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:31,000 --> 00:00:33,000
|
| 63 |
+
here you can see we are sending a plain password.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:33,000 --> 00:00:36,000
|
| 67 |
+
And, of course, you have to send plain password.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:36,000 --> 00:00:38,000
|
| 71 |
+
But in the database as well, we're having a plain password.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:38,000 --> 00:00:40,000
|
| 75 |
+
And the moment you implement bcrypt,
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:40,000 --> 00:00:41,000
|
| 79 |
+
it'll try to encode that, right?
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:41,000 --> 00:00:43,000
|
| 83 |
+
So, we have to also make sure
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:43,000 --> 00:00:44,000
|
| 87 |
+
that you change one of the field here.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:44,000 --> 00:00:46,000
|
| 91 |
+
So, let's say I want to change
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:46,000 --> 00:00:47,000
|
| 95 |
+
the navin's password to something else,
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:47,000 --> 00:00:49,000
|
| 99 |
+
some new password here.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:49,000 --> 00:00:50,000
|
| 103 |
+
And the way you can do that is,
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:00:50,000 --> 00:00:52,000
|
| 107 |
+
I will file the update query.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:00:52,000 --> 00:00:54,000
|
| 111 |
+
So, update users
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:00:54,000 --> 00:00:59,000
|
| 115 |
+
and I will set the password is equal to
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:00,000 --> 00:01:03,000
|
| 119 |
+
something where the id=3.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:03,000 --> 00:01:05,000
|
| 123 |
+
So, basically, I'm changing this particular record here,
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:05,000 --> 00:01:06,000
|
| 127 |
+
the third record.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:06,000 --> 00:01:08,000
|
| 131 |
+
But then, what should be the password?
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:08,000 --> 00:01:11,000
|
| 135 |
+
I want to find the bcrypt of this. How do I get that?
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:11,000 --> 00:01:12,000
|
| 139 |
+
I will just simply copy this,
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:12,000 --> 00:01:16,000
|
| 143 |
+
and, remember, this website where we created a password.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:16,000 --> 00:01:18,000
|
| 147 |
+
I will just enter that here.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:18,000 --> 00:01:21,000
|
| 151 |
+
And let me just go with the default one, which is 10.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:21,000 --> 00:01:22,000
|
| 155 |
+
Or, maybe I will just go with 12
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:22,000 --> 00:01:24,000
|
| 159 |
+
because I'm going to use that everywhere.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:24,000 --> 00:01:26,000
|
| 163 |
+
So, I'm going for Rounds 12.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:26,000 --> 00:01:28,000
|
| 167 |
+
And this is a password which I want to convert.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:28,000 --> 00:01:29,000
|
| 171 |
+
I will say Bcrypt.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:29,000 --> 00:01:31,000
|
| 175 |
+
Now, this is your new password,
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:31,000 --> 00:01:34,000
|
| 179 |
+
so I'll just copy this and store that here,
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:34,000 --> 00:01:36,000
|
| 183 |
+
so that at least I can authorize it.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:36,000 --> 00:01:38,000
|
| 187 |
+
And this is a new password, and the way we can verify...
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:38,000 --> 00:01:40,000
|
| 191 |
+
Okay , we have to execute this as well.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:40,000 --> 00:01:43,000
|
| 195 |
+
Run. Okay.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:45,000 --> 00:01:47,000
|
| 199 |
+
Also run, okay, update done.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:47,000 --> 00:01:49,000
|
| 203 |
+
And now, I will file the query,
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:49,000 --> 00:01:51,000
|
| 207 |
+
and you can see we got the new password there.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:51,000 --> 00:01:54,000
|
| 211 |
+
Now, once you have this new password, I can go back here,
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:01:54,000 --> 00:01:57,000
|
| 215 |
+
and let me log in with navin,
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:01:57,000 --> 00:02:01,000
|
| 219 |
+
and the password is n@345.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:01,000 --> 00:02:03,000
|
| 223 |
+
Now, of course, from the field you have to pass this.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:03,000 --> 00:02:06,000
|
| 227 |
+
Then, in between it'll convert that into bcrypt.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:06,000 --> 00:02:08,000
|
| 231 |
+
But how will you convert that?
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:08,000 --> 00:02:11,000
|
| 235 |
+
So, let me go back to my code and let's do the actual work.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:11,000 --> 00:02:14,000
|
| 239 |
+
So, when I say register in this service layer,
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:14,000 --> 00:02:16,000
|
| 243 |
+
before you register the user,
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:16,000 --> 00:02:18,000
|
| 247 |
+
this is where we have to change it, right?
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:18,000 --> 00:02:20,000
|
| 251 |
+
So, I want to change the user data.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:20,000 --> 00:02:22,000
|
| 255 |
+
I have to set the new password.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:22,000 --> 00:02:24,000
|
| 259 |
+
So, instead of storing the password, which is in plain text,
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:24,000 --> 00:02:26,000
|
| 263 |
+
I want to store that in the bcrypt.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:26,000 --> 00:02:28,000
|
| 267 |
+
So, I want to convert the password,
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:28,000 --> 00:02:29,000
|
| 271 |
+
which I'm getting from the user,
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:29,000 --> 00:02:31,000
|
| 275 |
+
which is, by default, the plain text,
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:31,000 --> 00:02:33,000
|
| 279 |
+
to our encrypted format.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:33,000 --> 00:02:34,000
|
| 283 |
+
And to achieve that,
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:34,000 --> 00:02:37,000
|
| 287 |
+
we can use something called a bcrypt encoder.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:37,000 --> 00:02:40,000
|
| 291 |
+
And to use that, we have to get object of bcrypt.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:40,000 --> 00:02:43,000
|
| 295 |
+
I'll say private BcryptPasswordEncoder.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:44,000 --> 00:02:46,000
|
| 299 |
+
And if you're thinking we are using something else,
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:46,000 --> 00:02:49,000
|
| 303 |
+
so we have to add a extra library, no,
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:49,000 --> 00:02:50,000
|
| 307 |
+
it's a part of Spring Security.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:50,000 --> 00:02:52,000
|
| 311 |
+
So, you can see BcryptPasswordEncoder
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:52,000 --> 00:02:54,000
|
| 315 |
+
is a part of Spring Security.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:02:54,000 --> 00:02:56,000
|
| 319 |
+
So, we don't have to add an extra library.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:02:56,000 --> 00:03:00,000
|
| 323 |
+
Let's create the variable as encoder,
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:00,000 --> 00:03:02,000
|
| 327 |
+
and then I can create the object like this.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:02,000 --> 00:03:03,000
|
| 331 |
+
This is one way.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:03,000 --> 00:03:06,000
|
| 335 |
+
Or, you can basically create a bean
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:06,000 --> 00:03:09,000
|
| 339 |
+
inside your configuration in the security config,
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:09,000 --> 00:03:11,000
|
| 343 |
+
return a bean of PasswordEncoder.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:11,000 --> 00:03:13,000
|
| 347 |
+
Again, you have a choice.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:13,000 --> 00:03:15,000
|
| 351 |
+
I'm just going for this variable thing here.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:15,000 --> 00:03:18,000
|
| 355 |
+
And then, in this, you can pass a strength.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:18,000 --> 00:03:20,000
|
| 359 |
+
So, how many rounds you want to go with.
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:20,000 --> 00:03:22,000
|
| 363 |
+
So, we have done that 12 in the,
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:22,000 --> 00:03:23,000
|
| 367 |
+
when we are generating your password,
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:23,000 --> 00:03:25,000
|
| 371 |
+
I'll also go for 12 here.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:25,000 --> 00:03:28,000
|
| 375 |
+
We can also set different versions here if you want.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:28,000 --> 00:03:30,000
|
| 379 |
+
So, example, if I go back here,
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:30,000 --> 00:03:31,000
|
| 383 |
+
and say Control+Space,
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:31,000 --> 00:03:34,000
|
| 387 |
+
you can see we can specify the BCryptVersion
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:34,000 --> 00:03:35,000
|
| 391 |
+
as $2A, $2B, $2Y.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:36,000 --> 00:03:37,000
|
| 395 |
+
These are the options you have,
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:37,000 --> 00:03:38,000
|
| 399 |
+
but I don't want to specify that.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:38,000 --> 00:03:40,000
|
| 403 |
+
Let me go with default one, which is two 12A.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:03:40,000 --> 00:03:42,000
|
| 407 |
+
And you can see we got the strength.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:03:42,000 --> 00:03:46,000
|
| 411 |
+
And now, with this encoder, so I can say encoder dot,
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:03:46,000 --> 00:03:49,000
|
| 415 |
+
I can basically encode a password, encode.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:03:49,000 --> 00:03:51,000
|
| 419 |
+
And what do you want to encode?
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:03:51,000 --> 00:03:54,000
|
| 423 |
+
So, whatever user has, so user.getPassword,
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:03:54,000 --> 00:03:55,000
|
| 427 |
+
that's what I'm encoding.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:03:55,000 --> 00:03:57,000
|
| 431 |
+
And then, assign it to back to the password.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:03:57,000 --> 00:04:00,000
|
| 435 |
+
And time being, let me also print
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:00,000 --> 00:04:02,000
|
| 439 |
+
the new password which we assigned,
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:02,000 --> 00:04:04,000
|
| 443 |
+
so that we can see in the console what the new password is.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:04,000 --> 00:04:05,000
|
| 447 |
+
Not a good idea in the production,
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:05,000 --> 00:04:08,000
|
| 451 |
+
but since we're learning, we can see what is happening.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:08,000 --> 00:04:10,000
|
| 455 |
+
So now, when you register a new user,
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:10,000 --> 00:04:13,000
|
| 459 |
+
it'll be registered with the help of this password, okay?
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:13,000 --> 00:04:15,000
|
| 463 |
+
And, but there's one issue,
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:15,000 --> 00:04:17,000
|
| 467 |
+
we have not implemented for reading,
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:17,000 --> 00:04:21,000
|
| 471 |
+
so we'll still go with the same harsh and harsh@123
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:21,000 --> 00:04:22,000
|
| 475 |
+
for verification.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:22,000 --> 00:04:27,000
|
| 479 |
+
So, let's go with harsh and h@123,
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:27,000 --> 00:04:32,000
|
| 483 |
+
because we have not done the bcrypt encoder for retrieving
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:32,000 --> 00:04:34,000
|
| 487 |
+
or to verify the user, okay?
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:34,000 --> 00:04:36,000
|
| 491 |
+
Let's register a new user, which is this,
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:36,000 --> 00:04:39,000
|
| 495 |
+
avni and a@123, that's a password.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:39,000 --> 00:04:42,000
|
| 499 |
+
I'll click on Send, and you can see it worked.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:04:42,000 --> 00:04:44,000
|
| 503 |
+
And this time, you can see we got a different password.
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:04:44,000 --> 00:04:46,000
|
| 507 |
+
This is the encoded password.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:04:46,000 --> 00:04:48,000
|
| 511 |
+
Also, we can verify in the console
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:04:48,000 --> 00:04:49,000
|
| 515 |
+
because we are printing it.
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:04:49,000 --> 00:04:51,000
|
| 519 |
+
This is a new password.
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:04:51,000 --> 00:04:53,000
|
| 523 |
+
Also, we can verify in database.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:04:53,000 --> 00:04:55,000
|
| 527 |
+
And I will just hit this particular query here.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:04:55,000 --> 00:04:57,000
|
| 531 |
+
So, we've got a new user with this password.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:04:57,000 --> 00:04:59,000
|
| 535 |
+
Now, this is the encoded password.
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:04:59,000 --> 00:05:02,000
|
| 539 |
+
Of course, while sending it, you have sent a@123,
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:02,000 --> 00:05:05,000
|
| 543 |
+
but we got encoded format here.
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:05,000 --> 00:05:08,000
|
| 547 |
+
But now, let's implement this for retrieving.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:08,000 --> 00:05:09,000
|
| 551 |
+
So, what we have done is,
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:09,000 --> 00:05:13,000
|
| 555 |
+
we used bcrypt for storing up a new user
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:13,000 --> 00:05:16,000
|
| 559 |
+
or grasping a new user, right?
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:05:16,000 --> 00:05:19,000
|
| 563 |
+
But how do I verify this for the authentication?
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:05:19,000 --> 00:05:21,000
|
| 567 |
+
Let's try that in the next video.
|
| 568 |
+
|
20 - Spring Security/026 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.26%20Bcrypt%20Encoding%20For%20User%20Registration/spring-sec-demo
|
20 - Spring Security/027 Setting Password Encoder_en.srt
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(peaceful music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:05,000
|
| 7 |
+
-: And now let's do it for the authentication.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:07,000
|
| 11 |
+
So basically the registration done
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:07,000 --> 00:00:10,000
|
| 15 |
+
and we also got a password in the incorrect format.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:10,000 --> 00:00:12,000
|
| 19 |
+
And you can see even if someone hacks the database
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:12,000 --> 00:00:14,000
|
| 23 |
+
for this two records, at least,
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:14,000 --> 00:00:15,000
|
| 27 |
+
they can't see the passwords.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:15,000 --> 00:00:17,000
|
| 31 |
+
Here we can, but that's what we have done before.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:17,000 --> 00:00:21,000
|
| 35 |
+
But now I want to authenticate right?
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:21,000 --> 00:00:23,000
|
| 39 |
+
Now you'll be thinking we have to get multiple classes,
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:23,000 --> 00:00:25,000
|
| 43 |
+
multiple files, not exactly.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:25,000 --> 00:00:29,000
|
| 47 |
+
If you go back to your security config, remember this line,
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:29,000 --> 00:00:32,000
|
| 51 |
+
this line is the only thing we have to change.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:32,000 --> 00:00:34,000
|
| 55 |
+
Everything else remains same.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:34,000 --> 00:00:35,000
|
| 59 |
+
Let me show you how.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:35,000 --> 00:00:36,000
|
| 63 |
+
Now when you say set password encode,
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:36,000 --> 00:00:38,000
|
| 67 |
+
remember when we talked about
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:38,000 --> 00:00:39,000
|
| 71 |
+
authentication provider,
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:39,000 --> 00:00:42,000
|
| 75 |
+
which was using a DAO authentication provider,
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:42,000 --> 00:00:44,000
|
| 79 |
+
and we have set the password encoder
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:44,000 --> 00:00:45,000
|
| 83 |
+
as no OP password encoder,
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:45,000 --> 00:00:47,000
|
| 87 |
+
and that's why it was checking with a plain text.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:47,000 --> 00:00:50,000
|
| 91 |
+
Now let's replace this with our library.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:50,000 --> 00:00:55,000
|
| 95 |
+
So we'll simply say new Bcrypt password encoder
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:55,000 --> 00:00:58,000
|
| 99 |
+
and just say 12, done.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:58,000 --> 00:01:00,000
|
| 103 |
+
That's the only change which which have to do
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:00,000 --> 00:01:01,000
|
| 107 |
+
for the authentication
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:01,000 --> 00:01:03,000
|
| 111 |
+
because other things we have already done,
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:03,000 --> 00:01:05,000
|
| 115 |
+
right, now will this work, let's try.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:05,000 --> 00:01:07,000
|
| 119 |
+
Now, the way I can try
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:07,000 --> 00:01:08,000
|
| 123 |
+
that is let me restart the application first
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:08,000 --> 00:01:13,000
|
| 127 |
+
and let's try with the new account, which is Omni, right?
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:13,000 --> 00:01:15,000
|
| 131 |
+
So let me go back to my postman
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:15,000 --> 00:01:18,000
|
| 135 |
+
and let's hit the query for the hello, right?
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:18,000 --> 00:01:19,000
|
| 139 |
+
So let's try to send hello.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:19,000 --> 00:01:21,000
|
| 143 |
+
And this time I will set the code,
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:21,000 --> 00:01:23,000
|
| 147 |
+
one, two, three, four, send.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:23,000 --> 00:01:24,000
|
| 151 |
+
Of course you will get error
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:24,000 --> 00:01:25,000
|
| 155 |
+
because we don't have this user.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:25,000 --> 00:01:29,000
|
| 159 |
+
And now I will try with something which is in plain text,
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:29,000 --> 00:01:32,000
|
| 163 |
+
which is Hirsch and Hirsch at the rate one, two, three.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:32,000 --> 00:01:36,000
|
| 167 |
+
So it's a Hirsch and H at the data one, two, three.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:36,000 --> 00:01:39,000
|
| 171 |
+
Click on send. Even this is not working.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:39,000 --> 00:01:41,000
|
| 175 |
+
We do have this user, it's not working,
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:41,000 --> 00:01:44,000
|
| 179 |
+
because we are searching for a plain text.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:44,000 --> 00:01:45,000
|
| 183 |
+
And in the coding we have said
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:45,000 --> 00:01:47,000
|
| 187 |
+
that you have to use a Bcrypt.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:47,000 --> 00:01:50,000
|
| 191 |
+
And in the database it's not Bcrypt, it's a plain text.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:50,000 --> 00:01:53,000
|
| 195 |
+
So now I will go with Avni because it's already Bcrypt.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:53,000 --> 00:01:58,000
|
| 199 |
+
So I will say A at the rate one, two, three, run, it worked.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:59,000 --> 00:02:00,000
|
| 203 |
+
You can see that?
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:00,000 --> 00:02:02,000
|
| 207 |
+
So this is how basically we can implement
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:02,000 --> 00:02:05,000
|
| 211 |
+
Bcrypt for password encoding.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:05,000 --> 00:02:07,000
|
| 215 |
+
So you these two users you can delete now.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:07,000 --> 00:02:09,000
|
| 219 |
+
You can only focus on this two Navin and Avni,
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:09,000 --> 00:02:12,000
|
| 223 |
+
and that's the passwords which are in encrypted format.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:12,000 --> 00:02:15,000
|
| 227 |
+
So it's so easy to implement a password encoder
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:15,000 --> 00:02:18,000
|
| 231 |
+
to secure your database, not database,
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:18,000 --> 00:02:19,000
|
| 235 |
+
but then the password fields.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:19,000 --> 00:02:23,000
|
| 239 |
+
So that's it from this video where we talked about Bcrypt.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:23,000 --> 00:02:24,000
|
| 243 |
+
How do we implement this?
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:24,000 --> 00:02:28,000
|
| 247 |
+
So just to give you a overall picture for registration,
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:28,000 --> 00:02:30,000
|
| 251 |
+
this particular controller has no idea
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:30,000 --> 00:02:31,000
|
| 255 |
+
that we have to do encoding.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:31,000 --> 00:02:34,000
|
| 259 |
+
The actual encoding is happening in the user service,
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:34,000 --> 00:02:35,000
|
| 263 |
+
which is service layer,
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:35,000 --> 00:02:38,000
|
| 267 |
+
and whatever user you're getting from the controller,
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:38,000 --> 00:02:40,000
|
| 271 |
+
you are basically encoding the password,
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:40,000 --> 00:02:42,000
|
| 275 |
+
then you are saving the user,
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:42,000 --> 00:02:43,000
|
| 279 |
+
and then when you are authenticating,
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:43,000 --> 00:02:47,000
|
| 283 |
+
basically here we have used a password encoder,
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:47,000 --> 00:02:49,000
|
| 287 |
+
set password encoder with Bcrypt,
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:49,000 --> 00:02:50,000
|
| 291 |
+
you have to make sure that you use the same strength,
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:50,000 --> 00:02:51,000
|
| 295 |
+
otherwise it'll not work.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:51,000 --> 00:02:52,000
|
| 299 |
+
If you specify 10 here,
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:52,000 --> 00:02:56,000
|
| 303 |
+
if you specify 12 in the creation, this will not work.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:56,000 --> 00:02:59,000
|
| 307 |
+
So you have to make sure that you specify the same strength.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:59,000 --> 00:03:02,000
|
| 311 |
+
So that's it from this video. See you in the next topic.
|
| 312 |
+
|
20 - Spring Security/027 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.27%20Setting%20Password%20Encoder/spring-sec-demo
|
20 - Spring Security/external-links.txt
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
003 Source-Code
|
| 3 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.3%20Creating%20A%20Spring%20Security%20Project/spring-sec-demo
|
| 4 |
+
|
| 5 |
+
004 Source-Code
|
| 6 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.4%20Default%20Login%20Form/spring-sec-demo
|
| 7 |
+
|
| 8 |
+
006 Source-Code
|
| 9 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.6%20Session%20Id/spring-sec-demo
|
| 10 |
+
|
| 11 |
+
007 Source-Code
|
| 12 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.7%20Setting%20Username%20And%20Password/spring-sec-demo4
|
| 13 |
+
|
| 14 |
+
010 Source-Code
|
| 15 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.10%20Error%20Without%20Csrf%20Token/spring-sec-demo
|
| 16 |
+
|
| 17 |
+
011 Source-Code
|
| 18 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.11%20Sending%20Csrf%20Token/spring-sec-demo
|
| 19 |
+
|
| 20 |
+
013 Source-Code
|
| 21 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.13%20Security%20Configuration/spring-sec-demo
|
| 22 |
+
|
| 23 |
+
014 Source-Code
|
| 24 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.14%20Disabling%20Csrf%20Token/spring-sec-demo
|
| 25 |
+
|
| 26 |
+
015 Source-Code
|
| 27 |
+
https://github.com/navinreddy20/spring6-course/tree/86a7c9e9036f7665f50c28c243fed20247f180d7/12%20Spring%20security/12.15%20Without%20Lambda/spring-sec-demo
|
| 28 |
+
|
| 29 |
+
017 Source-Code
|
| 30 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.17%20Working%20With%20Multiple%20Users/spring-sec-demo
|
| 31 |
+
|
| 32 |
+
018 Source-Code
|
| 33 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.18%20Creating%20User%20Table%20And%20Db%20Properties/spring-sec-demo
|
| 34 |
+
|
| 35 |
+
019 Source-Code
|
| 36 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.19%20Authenticationprovider/spring-sec-demo
|
| 37 |
+
|
| 38 |
+
020 Source-Code
|
| 39 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.20%20Creating%20A%20Userdetailsservice/spring-sec-demo
|
| 40 |
+
|
| 41 |
+
021 Source-Code
|
| 42 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.21%20User%20Repository/spring-sec-demo
|
| 43 |
+
|
| 44 |
+
022 Source-Code
|
| 45 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.22%20Userdetails%20And%20Userprincipal/spring-sec-demo
|
| 46 |
+
|
| 47 |
+
025 Source-Code
|
| 48 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.25%20User%20Registration/spring-sec-demo
|
| 49 |
+
|
| 50 |
+
026 Source-Code
|
| 51 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.26%20Bcrypt%20Encoding%20For%20User%20Registration/spring-sec-demo
|
| 52 |
+
|
| 53 |
+
027 Source-Code
|
| 54 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/12.27%20Setting%20Password%20Encoder/spring-sec-demo
|
21 - Securing Job App/001 Plan to secure Job App Project_en.srt
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(gentle music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:06,000
|
| 7 |
+
-: Now it's time to secure our job application.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:06,000 --> 00:00:08,000
|
| 11 |
+
So to this point, basically we have worked
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:08,000 --> 00:00:09,000
|
| 15 |
+
with a separate project
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:09,000 --> 00:00:10,000
|
| 19 |
+
and you can see we have project name,
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:10,000 --> 00:00:13,000
|
| 23 |
+
which is spring-security-demo,
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:13,000 --> 00:00:16,000
|
| 27 |
+
in which basically we had two controllers,
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:16,000 --> 00:00:17,000
|
| 31 |
+
one for the HelloController,
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:17,000 --> 00:00:21,000
|
| 35 |
+
where we were simply printing returning Hello World,
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:21,000 --> 00:00:24,000
|
| 39 |
+
and then we also have a string controller.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:24,000 --> 00:00:26,000
|
| 43 |
+
And then we tried to secure this application
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:26,000 --> 00:00:29,000
|
| 47 |
+
with the help of Spring Security.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:29,000 --> 00:00:31,000
|
| 51 |
+
And for that, we have basically created
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:31,000 --> 00:00:33,000
|
| 55 |
+
multiple classes, multiple interfaces.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:33,000 --> 00:00:36,000
|
| 59 |
+
Example, we got this interface which use repo,
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:36,000 --> 00:00:37,000
|
| 63 |
+
which connects with the database.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:37,000 --> 00:00:38,000
|
| 67 |
+
So if you can see,
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:38,000 --> 00:00:40,000
|
| 71 |
+
we also have our database here, which is this.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:40,000 --> 00:00:43,000
|
| 75 |
+
And in this, what we are doing is basically we have a table
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:43,000 --> 00:00:47,000
|
| 79 |
+
called users in which you got three columns
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:47,000 --> 00:00:49,000
|
| 83 |
+
and then out of this we have four records
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:49,000 --> 00:00:52,000
|
| 87 |
+
in which two records are vacated,
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:52,000 --> 00:00:54,000
|
| 91 |
+
and of course we are going to use this one,
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:54,000 --> 00:00:56,000
|
| 95 |
+
not the other two because they're plain text,
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:56,000 --> 00:00:57,000
|
| 99 |
+
it will not even work.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:57,000 --> 00:01:00,000
|
| 103 |
+
And now, apart from this, we also have a class
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:00,000 --> 00:01:02,000
|
| 107 |
+
for the user to represent user,
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:02,000 --> 00:01:04,000
|
| 111 |
+
and then we got user principle,
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:04,000 --> 00:01:06,000
|
| 115 |
+
which deals with user details,
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:06,000 --> 00:01:08,000
|
| 119 |
+
and then we got two classes for service.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:08,000 --> 00:01:12,000
|
| 123 |
+
Actually, we can add this part inside this service itself.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:12,000 --> 00:01:16,000
|
| 127 |
+
So you don't have to have two different classes.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:16,000 --> 00:01:19,000
|
| 131 |
+
We can basically copy this class, this method here,
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:19,000 --> 00:01:22,000
|
| 135 |
+
and paste it in the user details, even that will work.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:22,000 --> 00:01:26,000
|
| 139 |
+
So, but then we have those two classes just to differentiate
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:26,000 --> 00:01:28,000
|
| 143 |
+
what is compulsory and what we are doing
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:28,000 --> 00:01:30,000
|
| 147 |
+
for the user service.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:30,000 --> 00:01:32,000
|
| 151 |
+
And we have done something,
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:32,000 --> 00:01:33,000
|
| 155 |
+
some changes in the application properties.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:33,000 --> 00:01:35,000
|
| 159 |
+
We have a database connectivity.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:35,000 --> 00:01:36,000
|
| 163 |
+
I think it'll be same there.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:36,000 --> 00:01:38,000
|
| 167 |
+
And then to secure, we have to use
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:38,000 --> 00:01:41,000
|
| 171 |
+
this particular dependency, which is Spring Security.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:41,000 --> 00:01:43,000
|
| 175 |
+
Now we need to implement this in the job portal.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:43,000 --> 00:01:46,000
|
| 179 |
+
Now if you go back to job portal, which we have done,
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:46,000 --> 00:01:47,000
|
| 183 |
+
now, if you want to get this project,
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:47,000 --> 00:01:51,000
|
| 187 |
+
this is from our lecture name Search by Keyword
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:51,000 --> 00:01:52,000
|
| 191 |
+
from data JPA.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:52,000 --> 00:01:54,000
|
| 195 |
+
This is the project which we're going to change,
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:54,000 --> 00:01:57,000
|
| 199 |
+
and this project works, but it is not secure.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:57,000 --> 00:01:58,000
|
| 203 |
+
Let me show you.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:58,000 --> 00:01:58,000
|
| 207 |
+
What I will do is, first of all,
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:58,000 --> 00:02:01,000
|
| 211 |
+
I have to make sure that I'm not running the earlier one
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:01,000 --> 00:02:03,000
|
| 215 |
+
because I want to use the same code number.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:03,000 --> 00:02:06,000
|
| 219 |
+
Let me run this, the project, which we have done way back,
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:06,000 --> 00:02:08,000
|
| 223 |
+
and this should work, so let me run this.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:08,000 --> 00:02:09,000
|
| 227 |
+
So this job portal,
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:09,000 --> 00:02:12,000
|
| 231 |
+
which is not secure at this point, I'm running it.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:12,000 --> 00:02:17,000
|
| 235 |
+
Let me go back to Postman and hit the URL for job portal.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:17,000 --> 00:02:18,000
|
| 239 |
+
So if you go back,
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:18,000 --> 00:02:20,000
|
| 243 |
+
this is the job portal which we had, right,
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:20,000 --> 00:02:22,000
|
| 247 |
+
so let me just pick up this.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:22,000 --> 00:02:23,000
|
| 251 |
+
So you can see this is a (indistinct),
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:23,000 --> 00:02:26,000
|
| 255 |
+
localhost:8080/jobPost
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:26,000 --> 00:02:29,000
|
| 259 |
+
and I know you might be watching this bit later
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:29,000 --> 00:02:32,000
|
| 263 |
+
so I just want to show you the end points.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:32,000 --> 00:02:34,000
|
| 267 |
+
So if I go back to Job Rest Controller,
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:34,000 --> 00:02:37,000
|
| 271 |
+
you can see we have a Git mapping for jobPost,
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:37,000 --> 00:02:38,000
|
| 275 |
+
which will return all the posts.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:38,000 --> 00:02:40,000
|
| 279 |
+
From where we are getting this data,
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:40,000 --> 00:02:43,000
|
| 283 |
+
if you'll see the table, we do have this job post table,
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:43,000 --> 00:02:45,000
|
| 287 |
+
which if I say view all rows,
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:45,000 --> 00:02:47,000
|
| 291 |
+
this is basically a job portal.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:47,000 --> 00:02:49,000
|
| 295 |
+
We only have two jobs, but that's fine.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:49,000 --> 00:02:51,000
|
| 299 |
+
We just want to secure whatever resource we have.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:51,000 --> 00:02:54,000
|
| 303 |
+
I want to secure this and the way you can do that
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:54,000 --> 00:02:55,000
|
| 307 |
+
is by adding Spring Security,
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:55,000 --> 00:02:59,000
|
| 311 |
+
but since we have not added them, let me send the request.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:59,000 --> 00:03:01,000
|
| 315 |
+
Of course, I have to say no auth
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:01,000 --> 00:03:03,000
|
| 319 |
+
in the headers, nothing specified.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:03,000 --> 00:03:05,000
|
| 323 |
+
If I go back to no auth,
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:05,000 --> 00:03:07,000
|
| 327 |
+
click on send and look at the response.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:07,000 --> 00:03:10,000
|
| 331 |
+
We got this data and this is not secured yet.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:10,000 --> 00:03:12,000
|
| 335 |
+
Now let's secure this.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:12,000 --> 00:03:13,000
|
| 339 |
+
So what are the things we have to do?
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:13,000 --> 00:03:14,000
|
| 343 |
+
Of course, if you want to secure this,
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:14,000 --> 00:03:17,000
|
| 347 |
+
the first thing you will do in this project
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:17,000 --> 00:03:19,000
|
| 351 |
+
is you will go to your POM file
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:19,000 --> 00:03:21,000
|
| 355 |
+
and add this Spring Security dependency, that's one.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:21,000 --> 00:03:24,000
|
| 359 |
+
Next, we have to config the security
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:24,000 --> 00:03:26,000
|
| 363 |
+
because now we want to use a table
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:26,000 --> 00:03:29,000
|
| 367 |
+
where you have your users and we already have a table
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:29,000 --> 00:03:31,000
|
| 371 |
+
so we don't have to create one, we just have to map it,
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:31,000 --> 00:03:33,000
|
| 375 |
+
and that's why our job will become easy now,
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:33,000 --> 00:03:34,000
|
| 379 |
+
because we are already done a lot of things
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:34,000 --> 00:03:37,000
|
| 383 |
+
in the earlier project, we can just use them here.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:37,000 --> 00:03:38,000
|
| 387 |
+
So if we have to do the configuration,
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:38,000 --> 00:03:41,000
|
| 391 |
+
we have to create classes for the users,
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:41,000 --> 00:03:43,000
|
| 395 |
+
class for the user detail service,
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:43,000 --> 00:03:46,000
|
| 399 |
+
and then a repo, user repo interface.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:46,000 --> 00:03:49,000
|
| 403 |
+
So all these things will be added in this project,
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:03:49,000 --> 00:03:51,000
|
| 407 |
+
and we'll do step by step.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:03:51,000 --> 00:03:52,000
|
| 411 |
+
I'm not going to code everything
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:03:52,000 --> 00:03:53,000
|
| 415 |
+
because we already done that,
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:03:53,000 --> 00:03:54,000
|
| 419 |
+
I can just use them in this project.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:03:54,000 --> 00:03:56,000
|
| 423 |
+
But we have one more thing
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:03:56,000 --> 00:03:58,000
|
| 427 |
+
which we have not talked about in the previous project,
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:03:58,000 --> 00:04:00,000
|
| 431 |
+
and that is your cross origin.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:00,000 --> 00:04:02,000
|
| 435 |
+
So in the next video, let's try to understand
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:02,000 --> 00:04:04,000
|
| 439 |
+
what is cross origin and then we'll move towards
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:04,000 --> 00:04:05,000
|
| 443 |
+
securing this application.
|
| 444 |
+
|
21 - Securing Job App/001 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/13.1%20Plan%20To%20Secure%20Job%20App%20Project/spring-boot-rest
|
21 - Securing Job App/002 Cross Origin_en.srt
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(gentle music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:07,000
|
| 7 |
+
-: Now let's talk about this CrossOrigin, also called Cross.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:07,000 --> 00:00:08,000
|
| 11 |
+
So basically, what is happening here
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:08,000 --> 00:00:09,000
|
| 15 |
+
is we have two different projects.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:09,000 --> 00:00:12,000
|
| 19 |
+
One for the front end and one for the back end.
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:12,000 --> 00:00:14,000
|
| 23 |
+
We have built our front end using React,
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:14,000 --> 00:00:17,000
|
| 27 |
+
and we have built our back end with Spring.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:17,000 --> 00:00:19,000
|
| 31 |
+
Now the back end, which is Spring,
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:19,000 --> 00:00:22,000
|
| 35 |
+
we are running on a port number 8080,
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:22,000 --> 00:00:24,000
|
| 39 |
+
which is localhost:8080.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:24,000 --> 00:00:26,000
|
| 43 |
+
And then the front end, which is your React application,
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:26,000 --> 00:00:28,000
|
| 47 |
+
is running on a different port number, which is 3000.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:28,000 --> 00:00:32,000
|
| 51 |
+
Now by default, Spring says you can't actually access
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:32,000 --> 00:00:33,000
|
| 55 |
+
a resource from a different origin
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:33,000 --> 00:00:35,000
|
| 59 |
+
because we have a different port number there.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:35,000 --> 00:00:37,000
|
| 63 |
+
So it'll stop it. And why is important is because
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:37,000 --> 00:00:40,000
|
| 67 |
+
what if someone else is trying to access your resource
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:40,000 --> 00:00:42,000
|
| 71 |
+
from a different origin?
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:42,000 --> 00:00:43,000
|
| 75 |
+
And that's a risky part, right?
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:43,000 --> 00:00:45,000
|
| 79 |
+
So that's not security.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:45,000 --> 00:00:46,000
|
| 83 |
+
So if you want to make it more secure
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:46,000 --> 00:00:47,000
|
| 87 |
+
by default, Spring says,
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:47,000 --> 00:00:50,000
|
| 91 |
+
hey, you're not allowed to directly access a resource
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:50,000 --> 00:00:52,000
|
| 95 |
+
from the outside origin.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:52,000 --> 00:00:53,000
|
| 99 |
+
And if you want to allow it,
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:53,000 --> 00:00:55,000
|
| 103 |
+
of course we have to allow it in our application
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:00:55,000 --> 00:00:57,000
|
| 107 |
+
because we are running on two different ports
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:00:57,000 --> 00:00:58,000
|
| 111 |
+
or two different origins.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:00:58,000 --> 00:01:01,000
|
| 115 |
+
And to do that, we are using CrossOrigin
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:01,000 --> 00:01:03,000
|
| 119 |
+
and we are specifying that from where
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:03,000 --> 00:01:05,000
|
| 123 |
+
you will be getting this request.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:05,000 --> 00:01:08,000
|
| 127 |
+
So we are getting this request from localhost:3000.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:08,000 --> 00:01:10,000
|
| 131 |
+
Of course, once you deploy, you will get a different URL.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:10,000 --> 00:01:12,000
|
| 135 |
+
So you will allow it for that.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:12,000 --> 00:01:14,000
|
| 139 |
+
So you will say, okay, whenever you get requests from this,
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:14,000 --> 00:01:15,000
|
| 143 |
+
you have to allow it.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:15,000 --> 00:01:17,000
|
| 147 |
+
And sometime maybe you want your APIs
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:17,000 --> 00:01:18,000
|
| 151 |
+
to be public for the user.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:18,000 --> 00:01:21,000
|
| 155 |
+
In that case you have to simply say CrossOrigin,
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:21,000 --> 00:01:23,000
|
| 159 |
+
then it will allow for all the request.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:23,000 --> 00:01:25,000
|
| 163 |
+
Okay, you can do that on each controller
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:25,000 --> 00:01:27,000
|
| 167 |
+
the way I'm doing here.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:27,000 --> 00:01:30,000
|
| 171 |
+
Or you can do a configuration in the config file
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:30,000 --> 00:01:32,000
|
| 175 |
+
to allow from everywhere.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:32,000 --> 00:01:35,000
|
| 179 |
+
At this point, I'm not doing it, but that's the idea.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:35,000 --> 00:01:37,000
|
| 183 |
+
So CrossOrigin simply means that if you are accessing
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:37,000 --> 00:01:39,000
|
| 187 |
+
the data from the outside world
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:39,000 --> 00:01:41,000
|
| 191 |
+
from this particular application,
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:41,000 --> 00:01:42,000
|
| 195 |
+
then it'll by default blocked.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:42,000 --> 00:01:46,000
|
| 199 |
+
And if you want to allow it, you have to say CrossOrigin.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:46,000 --> 00:01:49,000
|
| 203 |
+
And also cause is basically one of these issues
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:49,000 --> 00:01:52,000
|
| 207 |
+
in the OS top 10, which we have discussed.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:52,000 --> 00:01:55,000
|
| 211 |
+
And that's how basically, Spring takes care of it.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:01:55,000 --> 00:01:56,000
|
| 215 |
+
But yeah, we have used it by default.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:01:56,000 --> 00:01:58,000
|
| 219 |
+
I have not explained to you when we were doing this
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:01:58,000 --> 00:02:01,000
|
| 223 |
+
or maybe you have done that, but not in terms of security.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:01,000 --> 00:02:03,000
|
| 227 |
+
But yes, you have to allow it from the outside world.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:03,000 --> 00:02:05,000
|
| 231 |
+
And if you don't do that, it will not allow.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:05,000 --> 00:02:07,000
|
| 235 |
+
Okay, so that's your CrossOrigin.
|
| 236 |
+
|
21 - Securing Job App/003 Adding Security Configuration_en.srt
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(pleasant, soft music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:05,000
|
| 7 |
+
-: And now, once we have talked about CrossOrigin,
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:06,000
|
| 11 |
+
it's time to secure it.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:06,000 --> 00:00:09,000
|
| 15 |
+
Now, in this project, we have less number of files,
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:09,000 --> 00:00:11,000
|
| 19 |
+
but we'll add more for the security,
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:11,000 --> 00:00:13,000
|
| 23 |
+
and we'll take it from our older project.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:13,000 --> 00:00:14,000
|
| 27 |
+
So, let me go back to my older project,
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:14,000 --> 00:00:16,000
|
| 31 |
+
which is your spring security demo.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:16,000 --> 00:00:19,000
|
| 35 |
+
The first thing you will do is you will add spring security.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:19,000 --> 00:00:22,000
|
| 39 |
+
So I will just copy this dependency block here
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:22,000 --> 00:00:25,000
|
| 43 |
+
from the XML file and go back to our project.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:25,000 --> 00:00:27,000
|
| 47 |
+
Let's open the XML for this particular project,
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:27,000 --> 00:00:30,000
|
| 51 |
+
and now, let's add the dependency.
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:30,000 --> 00:00:32,000
|
| 55 |
+
I will just do it above Lombok,
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:32,000 --> 00:00:35,000
|
| 59 |
+
and now you can see I have added the spring security
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:35,000 --> 00:00:36,000
|
| 63 |
+
dependency of Spring Boot.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:36,000 --> 00:00:38,000
|
| 67 |
+
Now once you add that in your project, you have
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:38,000 --> 00:00:40,000
|
| 71 |
+
to reload your VIN for the changes
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:40,000 --> 00:00:43,000
|
| 75 |
+
and you can say it says resolving dependency done.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:43,000 --> 00:00:45,000
|
| 79 |
+
Now, how do I verify if this is secure?
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:45,000 --> 00:00:46,000
|
| 83 |
+
I have to restart the application
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:46,000 --> 00:00:48,000
|
| 87 |
+
because we have changed the palm file.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:48,000 --> 00:00:51,000
|
| 91 |
+
Okay, so you can see we got this project running.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:51,000 --> 00:00:53,000
|
| 95 |
+
Let me go back to my postman
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:53,000 --> 00:00:55,000
|
| 99 |
+
and let's try to hit the same U model.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:55,000 --> 00:00:57,000
|
| 103 |
+
The moment you add spring security,
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:00:57,000 --> 00:00:59,000
|
| 107 |
+
and when you say send, it'll not work
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:00:59,000 --> 00:01:03,000
|
| 111 |
+
because now your application is kind of secure.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:03,000 --> 00:01:06,000
|
| 115 |
+
So if you want to make it work, you have to say basic auth
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:06,000 --> 00:01:08,000
|
| 119 |
+
and you have to specify the user.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:08,000 --> 00:01:10,000
|
| 123 |
+
Now, this username password will not work.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:10,000 --> 00:01:12,000
|
| 127 |
+
It's because we have not connected with database yet.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:12,000 --> 00:01:14,000
|
| 131 |
+
So even if you try with that, this will not work.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:14,000 --> 00:01:16,000
|
| 135 |
+
You can say we got 4 0 1.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:16,000 --> 00:01:20,000
|
| 139 |
+
So we have to use a default username, which is user
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:20,000 --> 00:01:21,000
|
| 143 |
+
and the default password,
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:21,000 --> 00:01:24,000
|
| 147 |
+
which you'll be getting in the console.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:24,000 --> 00:01:26,000
|
| 151 |
+
So if you go back to console here, not this project.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:26,000 --> 00:01:28,000
|
| 155 |
+
If you go back to console here,
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:28,000 --> 00:01:30,000
|
| 159 |
+
and if you go up, you got a password.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:30,000 --> 00:01:33,000
|
| 163 |
+
And we have done this before, so we can just copy that
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:33,000 --> 00:01:37,000
|
| 167 |
+
and paste it here and click on send, it worked.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:37,000 --> 00:01:40,000
|
| 171 |
+
So basically now it's kind of secured.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:40,000 --> 00:01:41,000
|
| 175 |
+
Now when I say kind of secure,
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:41,000 --> 00:01:43,000
|
| 179 |
+
it's because you are generating a password
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:43,000 --> 00:01:46,000
|
| 183 |
+
in the application, which is same for all the users.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:46,000 --> 00:01:49,000
|
| 187 |
+
Not exactly security, but yeah, we got something, right?
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:49,000 --> 00:01:50,000
|
| 191 |
+
This is partially secured now.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:50,000 --> 00:01:52,000
|
| 195 |
+
Next, what's the next step?
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:52,000 --> 00:01:53,000
|
| 199 |
+
We need to copy files.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:53,000 --> 00:01:56,000
|
| 203 |
+
I have to, I want to change the configuration.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:56,000 --> 00:01:58,000
|
| 207 |
+
So when you say you want to change the configuration from
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:58,000 --> 00:02:01,000
|
| 211 |
+
your older project, we need to get the config file.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:01,000 --> 00:02:03,000
|
| 215 |
+
This one, in the config package.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:03,000 --> 00:02:06,000
|
| 219 |
+
So I'll just copy this, the secure config,
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:06,000 --> 00:02:07,000
|
| 223 |
+
go back to my old project.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:07,000 --> 00:02:11,000
|
| 227 |
+
We don't have a config folder here in the job application.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:11,000 --> 00:02:14,000
|
| 231 |
+
So I will create a package for config.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:14,000 --> 00:02:16,000
|
| 235 |
+
And here, let's paste it.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:16,000 --> 00:02:18,000
|
| 239 |
+
So this particular file will be pasted,
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:18,000 --> 00:02:20,000
|
| 243 |
+
of course this will not work,
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:20,000 --> 00:02:23,000
|
| 247 |
+
is because we don't have these classes created yet.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:23,000 --> 00:02:24,000
|
| 251 |
+
But let me just try
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:24,000 --> 00:02:28,000
|
| 255 |
+
to see if all the packages are imported.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:28,000 --> 00:02:30,000
|
| 259 |
+
We are saying that we want to go with user details,
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:30,000 --> 00:02:32,000
|
| 263 |
+
but it'll pick up the inbuilt,
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:32,000 --> 00:02:35,000
|
| 267 |
+
not the one which we created, but let's try.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:35,000 --> 00:02:37,000
|
| 271 |
+
Let's try, let's see what error you get.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:37,000 --> 00:02:39,000
|
| 275 |
+
Even we are using B crypt here.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:39,000 --> 00:02:42,000
|
| 279 |
+
So let me just try, if this works,
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:42,000 --> 00:02:43,000
|
| 283 |
+
let me just start the application
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:43,000 --> 00:02:47,000
|
| 287 |
+
and go back to our postman just by adding that config file
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:47,000 --> 00:02:50,000
|
| 291 |
+
and I will click on send.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:52,000 --> 00:02:55,000
|
| 295 |
+
Okay, so it looks like we got error here.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:55,000 --> 00:03:00,000
|
| 299 |
+
It says the field user detail service is a bean,
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:03:00,000 --> 00:03:01,000
|
| 303 |
+
but could not be found
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:03:01,000 --> 00:03:03,000
|
| 307 |
+
because we have not created the class for it.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:03:03,000 --> 00:03:06,000
|
| 311 |
+
So let's try to add the classes for user details.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:03:06,000 --> 00:03:07,000
|
| 315 |
+
So next video we'll be bit lengthy
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:07,000 --> 00:03:09,000
|
| 319 |
+
because we'll be adding all the files,
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:09,000 --> 00:03:10,000
|
| 323 |
+
but we got the idea, right?
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:10,000 --> 00:03:13,000
|
| 327 |
+
So we cannot simply add a security config,
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:13,000 --> 00:03:15,000
|
| 331 |
+
we have to add other files as well.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:15,000 --> 00:03:18,000
|
| 335 |
+
So let's do that step by step in the next video.
|
| 336 |
+
|
21 - Securing Job App/003 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/13.3%20Adding%20Security%20Configuration/spring-boot-rest
|
21 - Securing Job App/004 Job App is secure now_en.srt
ADDED
|
@@ -0,0 +1,652 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(calm music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:05,000
|
| 7 |
+
-: And now let's copy those files.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:06,000
|
| 11 |
+
So I will just go back to my project,
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:06,000 --> 00:00:08,000
|
| 15 |
+
which we have done before for the security.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:08,000 --> 00:00:09,000
|
| 19 |
+
Now what are the files we need?
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:09,000 --> 00:00:10,000
|
| 23 |
+
So we copied config,
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:10,000 --> 00:00:15,000
|
| 27 |
+
SecurityConfig, but now we need to get this UserDetails.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:15,000 --> 00:00:17,000
|
| 31 |
+
So I will copy both the service classes,
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:17,000 --> 00:00:19,000
|
| 35 |
+
UserDetails for the configuration
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:19,000 --> 00:00:22,000
|
| 39 |
+
and UserService for your registration.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:22,000 --> 00:00:24,000
|
| 43 |
+
So we'll just copy these two files.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:24,000 --> 00:00:25,000
|
| 47 |
+
Go back to my project.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:25,000 --> 00:00:27,000
|
| 51 |
+
In the service package,
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:27,000 --> 00:00:28,000
|
| 55 |
+
let's paste it, both the files.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:28,000 --> 00:00:30,000
|
| 59 |
+
And when you open the UserService,
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:30,000 --> 00:00:32,000
|
| 63 |
+
of course it will give you some issues
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:32,000 --> 00:00:35,000
|
| 67 |
+
that you don't have this particular UserRepo.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:35,000 --> 00:00:36,000
|
| 71 |
+
Let me remove the imports
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:36,000 --> 00:00:38,000
|
| 75 |
+
because we have a different package name.
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:38,000 --> 00:00:40,000
|
| 79 |
+
It'll create issues. And now we need to get the UserRepo.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:40,000 --> 00:00:42,000
|
| 83 |
+
We need to get the User, and that's it.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:42,000 --> 00:00:44,000
|
| 87 |
+
So we have to get these two files.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:44,000 --> 00:00:46,000
|
| 91 |
+
Also, if you open your UserDetailsService,
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:46,000 --> 00:00:50,000
|
| 95 |
+
even this is dependent on the User and the UserRepo.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:50,000 --> 00:00:52,000
|
| 99 |
+
So we have to remove the invite packages.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:52,000 --> 00:00:55,000
|
| 103 |
+
So ultimately we are dependent upon two files now,
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:00:55,000 --> 00:00:58,000
|
| 107 |
+
UserRepo and the User file, or User class.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:00:58,000 --> 00:01:01,000
|
| 111 |
+
So let me go back here. So it needs a user.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:01,000 --> 00:01:04,000
|
| 115 |
+
So we'll copy User, paste it in the model package.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:04,000 --> 00:01:05,000
|
| 119 |
+
Done.
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:05,000 --> 00:01:07,000
|
| 123 |
+
Okay, so we got the User
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:07,000 --> 00:01:09,000
|
| 127 |
+
and all the imports looks good.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:09,000 --> 00:01:10,000
|
| 131 |
+
Let me go back to my UserDetailsService.
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:10,000 --> 00:01:12,000
|
| 135 |
+
Now we are able to get the user,
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:12,000 --> 00:01:14,000
|
| 139 |
+
you can see there's no problem.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:14,000 --> 00:01:15,000
|
| 143 |
+
We can simply import it.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:15,000 --> 00:01:18,000
|
| 147 |
+
And for the UserService also
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:18,000 --> 00:01:20,000
|
| 151 |
+
the User is resolved.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:20,000 --> 00:01:22,000
|
| 155 |
+
But then repo. Where's repo?
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:22,000 --> 00:01:24,000
|
| 159 |
+
Let me go back to my older project
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:24,000 --> 00:01:28,000
|
| 163 |
+
and get the UserRepo, which should be in dao.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:28,000 --> 00:01:30,000
|
| 167 |
+
So you can see we already have a repo layer.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:30,000 --> 00:01:31,000
|
| 171 |
+
So this time we are not using dao layer.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:31,000 --> 00:01:33,000
|
| 175 |
+
Here we have a repo layer, but that's fine.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:33,000 --> 00:01:35,000
|
| 179 |
+
The concept remains same.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:35,000 --> 00:01:37,000
|
| 183 |
+
Let me remove both this dependency
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:37,000 --> 00:01:41,000
|
| 187 |
+
and say get the User from this
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:41,000 --> 00:01:45,000
|
| 191 |
+
and also the JpaRepository, done.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:45,000 --> 00:01:47,000
|
| 195 |
+
And you can see there's no problem with repo now.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:47,000 --> 00:01:49,000
|
| 199 |
+
In the service, it should be happy
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:49,000 --> 00:01:50,000
|
| 203 |
+
the moment you import UserRepo.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:50,000 --> 00:01:54,000
|
| 207 |
+
So you can see the entire class is ready, the service,
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:54,000 --> 00:01:56,000
|
| 211 |
+
but much detailed service is still not ready
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:01:56,000 --> 00:02:01,000
|
| 215 |
+
because it is dependent on the UserPrincipal.
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:01,000 --> 00:02:03,000
|
| 219 |
+
Okay, there's still some issue with this,
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:03,000 --> 00:02:06,000
|
| 223 |
+
cannot resolve findByUsername in repo
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:06,000 --> 00:02:08,000
|
| 227 |
+
because we have not imported the package.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:08,000 --> 00:02:09,000
|
| 231 |
+
Let's import the package for UserRepo,
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:09,000 --> 00:02:12,000
|
| 235 |
+
which we have added, and now it is resolved.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:12,000 --> 00:02:15,000
|
| 239 |
+
But then not UserPrincipal. So now you know what to do.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:15,000 --> 00:02:16,000
|
| 243 |
+
Let's copy the UserPrincipal,
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:16,000 --> 00:02:19,000
|
| 247 |
+
which goes into the model package.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:20,000 --> 00:02:23,000
|
| 251 |
+
Okay, there's no invite import here.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:23,000 --> 00:02:25,000
|
| 255 |
+
Everything looks cool,
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:25,000 --> 00:02:26,000
|
| 259 |
+
but why is not giving error for user,
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:26,000 --> 00:02:28,000
|
| 263 |
+
okay, it's in the same package.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:28,000 --> 00:02:29,000
|
| 267 |
+
Okay, no problem here, let me go back
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:29,000 --> 00:02:30,000
|
| 271 |
+
to my UserDetailsService
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:30,000 --> 00:02:34,000
|
| 275 |
+
and let's import this UserPrincipal class basically.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:34,000 --> 00:02:37,000
|
| 279 |
+
So we are importing that. Okay, what next?
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:37,000 --> 00:02:39,000
|
| 283 |
+
Any problem you see there?
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:39,000 --> 00:02:42,000
|
| 287 |
+
No, looks good. Everything.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:42,000 --> 00:02:45,000
|
| 291 |
+
Let me just check once any file, which I'm missing here. No.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:45,000 --> 00:02:46,000
|
| 295 |
+
In the application properties,
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:46,000 --> 00:02:48,000
|
| 299 |
+
we do have database configuration,
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:48,000 --> 00:02:51,000
|
| 303 |
+
but I think we already have that in the project.
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:51,000 --> 00:02:53,000
|
| 307 |
+
So if you go back application properties,
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:53,000 --> 00:02:55,000
|
| 311 |
+
we do have the connectivity with the password,
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:55,000 --> 00:02:57,000
|
| 315 |
+
with the database, and we are using the same database.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:02:57,000 --> 00:02:59,000
|
| 319 |
+
There's no problem.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:02:59,000 --> 00:03:00,000
|
| 323 |
+
And if you don't have this configuration,
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:00,000 --> 00:03:01,000
|
| 327 |
+
make sure you have it.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:01,000 --> 00:03:03,000
|
| 331 |
+
And even if you're using some different DBMS,
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:03,000 --> 00:03:06,000
|
| 335 |
+
you have to change these particular details.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:06,000 --> 00:03:07,000
|
| 339 |
+
Everything else will remain same.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:07,000 --> 00:03:12,000
|
| 343 |
+
And yeah, I think our project is ready. Let's verify.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:12,000 --> 00:03:14,000
|
| 347 |
+
How do I verify? Just restart the application.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:14,000 --> 00:03:16,000
|
| 351 |
+
Restart, taking some time.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:16,000 --> 00:03:19,000
|
| 355 |
+
And you can say it is not generating a password now
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:19,000 --> 00:03:21,000
|
| 359 |
+
because now we are using database, right?
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:21,000 --> 00:03:22,000
|
| 363 |
+
Now what's the password in database?
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:22,000 --> 00:03:25,000
|
| 367 |
+
So we have avni, where is our table?
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:25,000 --> 00:03:29,000
|
| 371 |
+
So if I say users, view all rows.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:29,000 --> 00:03:32,000
|
| 375 |
+
So we got avni as a username, if you can see.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:32,000 --> 00:03:33,000
|
| 379 |
+
Yeah, so we got avni, let's use avni.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:33,000 --> 00:03:36,000
|
| 383 |
+
And the password is a@123.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:36,000 --> 00:03:38,000
|
| 387 |
+
But this is Pcrypt, but let's try that.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:38,000 --> 00:03:39,000
|
| 391 |
+
So let me go back to Postman now
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:39,000 --> 00:03:41,000
|
| 395 |
+
and let's try to hit the URL.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:41,000 --> 00:03:42,000
|
| 399 |
+
Of course this will not work,
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:42,000 --> 00:03:45,000
|
| 403 |
+
is because we have a wrong username password.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:03:45,000 --> 00:03:47,000
|
| 407 |
+
So let me use avni here.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:03:47,000 --> 00:03:52,000
|
| 411 |
+
And the password is a@123.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:03:52,000 --> 00:03:55,000
|
| 415 |
+
I hope this will work. Let's click on send, and it worked.
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:03:55,000 --> 00:03:56,000
|
| 419 |
+
Okay, so yeah.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:03:56,000 --> 00:03:58,000
|
| 423 |
+
So our application is secured now,
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:03:58,000 --> 00:04:02,000
|
| 427 |
+
the job portal, right, or the job app, which we have done.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:02,000 --> 00:04:05,000
|
| 431 |
+
So everything was working but it was not secure.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:05,000 --> 00:04:07,000
|
| 435 |
+
So we have done this security part.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:07,000 --> 00:04:08,000
|
| 439 |
+
Now what are the things we have added?
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:08,000 --> 00:04:10,000
|
| 443 |
+
So if you go back to your job application,
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:10,000 --> 00:04:11,000
|
| 447 |
+
we have added certain files.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:11,000 --> 00:04:14,000
|
| 451 |
+
We got SecurityConfig file in which you are saying
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:14,000 --> 00:04:17,000
|
| 455 |
+
that I want to provide my own AuthenticationProvider.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:17,000 --> 00:04:20,000
|
| 459 |
+
And in the security filter I'm disabling the csrf,
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:20,000 --> 00:04:22,000
|
| 463 |
+
I'm saying all the requests going
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:22,000 --> 00:04:23,000
|
| 467 |
+
to the application should be authenticated.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:23,000 --> 00:04:25,000
|
| 471 |
+
I want to have a login page as well,
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:25,000 --> 00:04:26,000
|
| 475 |
+
which works with HTTP headers.
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:26,000 --> 00:04:29,000
|
| 479 |
+
You get a prompt there, not the form.
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:29,000 --> 00:04:33,000
|
| 483 |
+
And then we are saying this session is stateless.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:33,000 --> 00:04:35,000
|
| 487 |
+
That's the thing we are doing here.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:35,000 --> 00:04:39,000
|
| 491 |
+
And if you see this particular SecurityConfig,
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:39,000 --> 00:04:41,000
|
| 495 |
+
it is dependent upon the UserDetailsService.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:41,000 --> 00:04:45,000
|
| 499 |
+
And we have basically implemented this particular interface,
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:04:45,000 --> 00:04:47,000
|
| 503 |
+
UserDetailsService in which you have this method,
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:04:47,000 --> 00:04:50,000
|
| 507 |
+
loadUserByUsername, we are passing a username.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:04:50,000 --> 00:04:51,000
|
| 511 |
+
It is verifying that.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:04:51,000 --> 00:04:54,000
|
| 515 |
+
And to achieve this, it is using a User plus,
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:04:54,000 --> 00:04:57,000
|
| 519 |
+
and also it returns the object
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:04:57,000 --> 00:04:58,000
|
| 523 |
+
of UserPrincipals.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:04:58,000 --> 00:04:59,000
|
| 527 |
+
And the UserPrincipal,
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:04:59,000 --> 00:05:02,000
|
| 531 |
+
basically we are implementing UserDetails
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:05:02,000 --> 00:05:04,000
|
| 535 |
+
and then it has multiple methods in which you're
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:05:04,000 --> 00:05:05,000
|
| 539 |
+
also specifying the role.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:05,000 --> 00:05:09,000
|
| 543 |
+
Maybe we have to also update this rules
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:09,000 --> 00:05:12,000
|
| 547 |
+
because when you say you have a job portal,
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:12,000 --> 00:05:14,000
|
| 551 |
+
we don't want everyone to add a job.
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:14,000 --> 00:05:16,000
|
| 555 |
+
Only employers can do that.
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:16,000 --> 00:05:19,000
|
| 559 |
+
And we don't want anyone to delete the jobs.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:05:19,000 --> 00:05:21,000
|
| 563 |
+
Only employers can do that.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:05:21,000 --> 00:05:24,000
|
| 567 |
+
Or maybe we can have a admin who can add the jobs
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:05:24,000 --> 00:05:26,000
|
| 571 |
+
and remove the jobs, edit the jobs,
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:05:26,000 --> 00:05:28,000
|
| 575 |
+
but job searching can be done by all the users.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:05:28,000 --> 00:05:30,000
|
| 579 |
+
Now that's something we can add here. Okay?
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:05:30,000 --> 00:05:33,000
|
| 583 |
+
And yeah, that's it. Those are the things we have done.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:05:33,000 --> 00:05:35,000
|
| 587 |
+
We also got UserRepo, which is connecting with this table,
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:05:35,000 --> 00:05:37,000
|
| 591 |
+
which is User, I mean User plus,
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:05:37,000 --> 00:05:40,000
|
| 595 |
+
which is representing the users table.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:05:41,000 --> 00:05:43,000
|
| 599 |
+
Oh, it was not that long.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:05:43,000 --> 00:05:45,000
|
| 603 |
+
We completed the stuff very fast
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:05:45,000 --> 00:05:49,000
|
| 607 |
+
because we have already done this in the previous section.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:05:49,000 --> 00:05:50,000
|
| 611 |
+
Okay?
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:05:50,000 --> 00:05:54,000
|
| 615 |
+
So yeah, that's how we can secure our job portal.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:05:54,000 --> 00:05:56,000
|
| 619 |
+
We can also try this with our React application.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:05:56,000 --> 00:05:58,000
|
| 623 |
+
Maybe you can just modify your React application
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:05:58,000 --> 00:06:02,000
|
| 627 |
+
by adding a username, password, or maybe a login form,
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:06:02,000 --> 00:06:06,000
|
| 631 |
+
and just hit this URL just by passing the basic auth, right?
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:06:06,000 --> 00:06:07,000
|
| 635 |
+
And if you do that, it'll work.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:06:07,000 --> 00:06:11,000
|
| 639 |
+
So yeah, that's it from this video where we talked about
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:06:11,000 --> 00:06:14,000
|
| 643 |
+
how do you secure your job portal application,
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:06:14,000 --> 00:06:16,000
|
| 647 |
+
which is this, or job application.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:06:16,000 --> 00:06:17,000
|
| 651 |
+
See you in the next topic.
|
| 652 |
+
|
21 - Securing Job App/004 Source-Code.url
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[InternetShortcut]
|
| 2 |
+
URL=https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/13.4%20Job%20App%20Is%20Secure%20Now/spring-boot-rest
|
21 - Securing Job App/external-links.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
001 Source-Code
|
| 3 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/13.1%20Plan%20To%20Secure%20Job%20App%20Project/spring-boot-rest
|
| 4 |
+
|
| 5 |
+
003 Source-Code
|
| 6 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/13.3%20Adding%20Security%20Configuration/spring-boot-rest
|
| 7 |
+
|
| 8 |
+
004 Source-Code
|
| 9 |
+
https://github.com/navinreddy20/spring6-course/tree/c6690e4f2c70d8f530d70623f13d14ff0ffd7e7d/12%20Spring%20security/13.4%20Job%20App%20Is%20Secure%20Now/spring-boot-rest
|
22 - JWT (JSON Web Token) and OAuth2/001 Encryption and Decryption_en.srt
ADDED
|
@@ -0,0 +1,808 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(gentle music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:06,000
|
| 7 |
+
-: In this video, we'll talk about cryptography.
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:06,000 --> 00:00:07,000
|
| 11 |
+
So what happens is, on the internet,
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:07,000 --> 00:00:10,000
|
| 15 |
+
basically you send information between the servers,
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:10,000 --> 00:00:13,000
|
| 19 |
+
or from client to server, or server to client,
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:13,000 --> 00:00:15,000
|
| 23 |
+
and when you say you are
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:15,000 --> 00:00:17,000
|
| 27 |
+
sending this data through the internet,
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:17,000 --> 00:00:19,000
|
| 31 |
+
anyone in between can check this data.
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:19,000 --> 00:00:21,000
|
| 35 |
+
Of course, right, we have something
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:21,000 --> 00:00:23,000
|
| 39 |
+
called man in middle attack.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:23,000 --> 00:00:26,000
|
| 43 |
+
Basically, they can see your data, they can modify the data.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:26,000 --> 00:00:29,000
|
| 47 |
+
So let's say, if person A says to person B,
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:29,000 --> 00:00:33,000
|
| 51 |
+
"Hey, let's meet at a cafe at 5:00 PM,"
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:33,000 --> 00:00:36,000
|
| 55 |
+
but then when the data is passing, the person C says,
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:36,000 --> 00:00:39,000
|
| 59 |
+
"Okay, I want to make some modification here."
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:39,000 --> 00:00:42,000
|
| 63 |
+
So they go there, they change this data from 5:00 to 6:00,
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:42,000 --> 00:00:44,000
|
| 67 |
+
and they send it to B.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:44,000 --> 00:00:48,000
|
| 71 |
+
Now, here we are not just doing a passive attack
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:48,000 --> 00:00:49,000
|
| 75 |
+
where you are able to read the data,
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:49,000 --> 00:00:51,000
|
| 79 |
+
you are also doing a active attack.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:51,000 --> 00:00:54,000
|
| 83 |
+
Now, how do we secure ourself from this attack?
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:54,000 --> 00:00:56,000
|
| 87 |
+
Now of course there have, we have to use some mechanism
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:56,000 --> 00:00:59,000
|
| 91 |
+
where at least other person cannot see your data.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:59,000 --> 00:01:01,000
|
| 95 |
+
Even if they can see data,
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:01,000 --> 00:01:03,000
|
| 99 |
+
they should not be able to read it.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:03,000 --> 00:01:05,000
|
| 103 |
+
And second, they should not be able to make the changes.
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:05,000 --> 00:01:06,000
|
| 107 |
+
Even if they make the changes,
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:06,000 --> 00:01:10,000
|
| 111 |
+
B should be able to know that something has changed,
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:10,000 --> 00:01:13,000
|
| 115 |
+
and we can do that with the help of cryptography.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:13,000 --> 00:01:14,000
|
| 119 |
+
Now, in cryptography we use
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:14,000 --> 00:01:16,000
|
| 123 |
+
a concept of encryption and decryption.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:16,000 --> 00:01:20,000
|
| 127 |
+
So let's say when A, is sending data to B now,
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:20,000 --> 00:01:22,000
|
| 131 |
+
what you can do is you can do something
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:22,000 --> 00:01:23,000
|
| 135 |
+
called an encryption here.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:23,000 --> 00:01:25,000
|
| 139 |
+
Now, to do the encryption,
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:25,000 --> 00:01:28,000
|
| 143 |
+
what we basically do is we use a key,
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:28,000 --> 00:01:31,000
|
| 147 |
+
and we change our data in such a way
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:31,000 --> 00:01:33,000
|
| 151 |
+
that no one else can read it.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:33,000 --> 00:01:35,000
|
| 155 |
+
Of course, when you send the same data to B,
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:35,000 --> 00:01:37,000
|
| 159 |
+
B cannot read that data now.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:37,000 --> 00:01:40,000
|
| 163 |
+
That's weird, I mean, we wanted B to know the data, right?
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:40,000 --> 00:01:43,000
|
| 167 |
+
But then, what if you can share the key with B?
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:43,000 --> 00:01:46,000
|
| 171 |
+
And now B should be able to decrypt it.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:46,000 --> 00:01:48,000
|
| 175 |
+
So, encryption simply means converting
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:48,000 --> 00:01:50,000
|
| 179 |
+
your normal text to cipher text.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:50,000 --> 00:01:52,000
|
| 183 |
+
And decryption simply means
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:52,000 --> 00:01:55,000
|
| 187 |
+
that you're converting your cipher text to a normal text.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:55,000 --> 00:01:59,000
|
| 191 |
+
So when A is writing the content, that will be your,
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:59,000 --> 00:02:00,000
|
| 195 |
+
and that's your normal text,
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:02:00,000 --> 00:02:03,000
|
| 199 |
+
but then you have to encrypt it so that no one can read it.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:02:03,000 --> 00:02:05,000
|
| 203 |
+
Even A cannot read that now.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:05,000 --> 00:02:07,000
|
| 207 |
+
Of course, A can read if A can decrypt it,
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:07,000 --> 00:02:11,000
|
| 211 |
+
but now when you send this data to B, now B cannot read it,
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:11,000 --> 00:02:12,000
|
| 215 |
+
so they have to decrypt it,
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:12,000 --> 00:02:14,000
|
| 219 |
+
and they will simply, they can be able to read that.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:14,000 --> 00:02:17,000
|
| 223 |
+
Now, even if C is able to get the data,
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:17,000 --> 00:02:19,000
|
| 227 |
+
C cannot read that because it is encrypted.
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:19,000 --> 00:02:21,000
|
| 231 |
+
Now, how can B read it?
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:21,000 --> 00:02:25,000
|
| 235 |
+
Because B has a key, C has no idea what that key is.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:25,000 --> 00:02:27,000
|
| 239 |
+
Now, this key is important here.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:27,000 --> 00:02:29,000
|
| 243 |
+
Now, this key can be of two different types.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:29,000 --> 00:02:33,000
|
| 247 |
+
A key can be a symmetric key or it can be a asymmetric key.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:33,000 --> 00:02:35,000
|
| 251 |
+
So in the symmetric key, what you have is,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:35,000 --> 00:02:37,000
|
| 255 |
+
you have keys which are same.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:37,000 --> 00:02:40,000
|
| 259 |
+
So A and B will have the same keys.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:40,000 --> 00:02:44,000
|
| 263 |
+
And of course, this can be any normal text or normal string,
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:44,000 --> 00:02:46,000
|
| 267 |
+
which you can use as a key,
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:46,000 --> 00:02:47,000
|
| 271 |
+
but they will be having the same key.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:47,000 --> 00:02:51,000
|
| 275 |
+
So if A is encrypting the data with this key,
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:51,000 --> 00:02:54,000
|
| 279 |
+
the same key has to be there with B as well to decrypt it.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:54,000 --> 00:02:57,000
|
| 283 |
+
This is called a symmetric cryptography,
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:57,000 --> 00:02:59,000
|
| 287 |
+
or symmetric key cryptography.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:59,000 --> 00:03:01,000
|
| 291 |
+
The problem with this is,
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:03:01,000 --> 00:03:04,000
|
| 295 |
+
this key need to be shared before the communication.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:03:04,000 --> 00:03:07,000
|
| 299 |
+
Of course, they cannot share this key on the internet now
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:03:07,000 --> 00:03:09,000
|
| 303 |
+
because if they share this key on the internet,
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:03:09,000 --> 00:03:12,000
|
| 307 |
+
C can see the key and then C will say,
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:03:12,000 --> 00:03:13,000
|
| 311 |
+
"Okay, I got the key, now.
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:03:13,000 --> 00:03:15,000
|
| 315 |
+
Even if you encrypted, I can read that."
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:15,000 --> 00:03:17,000
|
| 319 |
+
So that's one challenge here.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:17,000 --> 00:03:19,000
|
| 323 |
+
This key need to be shared beforehand.
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:19,000 --> 00:03:22,000
|
| 327 |
+
Maybe they can meet somewhere in person,
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:22,000 --> 00:03:25,000
|
| 331 |
+
share the key and go back and do the communication.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:25,000 --> 00:03:27,000
|
| 335 |
+
Again, a weird way of sharing a key,
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:27,000 --> 00:03:29,000
|
| 339 |
+
but again, it's very famous,
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:29,000 --> 00:03:31,000
|
| 343 |
+
the symmetric cryptography, it is faster,
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:31,000 --> 00:03:34,000
|
| 347 |
+
and you can also have a large key size,
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:34,000 --> 00:03:36,000
|
| 351 |
+
and the bigger the key size you have, it's more secure.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:36,000 --> 00:03:39,000
|
| 355 |
+
The challenge is of course the key sharing.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:39,000 --> 00:03:42,000
|
| 359 |
+
And also, what if you have multiple members in the network?
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:42,000 --> 00:03:43,000
|
| 363 |
+
We have D, E,
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:43,000 --> 00:03:46,000
|
| 367 |
+
and maybe A want to do communications with D now.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:46,000 --> 00:03:47,000
|
| 371 |
+
So of course, they have to use a different key.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:47,000 --> 00:03:50,000
|
| 375 |
+
They cannot use the same key which is shared by A and B.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:50,000 --> 00:03:55,000
|
| 379 |
+
Maybe if you say K1 is the key used by A and B,
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:55,000 --> 00:03:57,000
|
| 383 |
+
now A cannot use the same key with D,
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:57,000 --> 00:04:00,000
|
| 387 |
+
they need to have a different key, let's say K2.
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:04:00,000 --> 00:04:02,000
|
| 391 |
+
What if D wants to communicate with E?
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:04:02,000 --> 00:04:05,000
|
| 395 |
+
Of course, they have to have a different key, which is K3.
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:04:05,000 --> 00:04:08,000
|
| 399 |
+
That's how you basically have multiple keys
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:04:08,000 --> 00:04:10,000
|
| 403 |
+
in symmetric key cryptography.
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:04:10,000 --> 00:04:13,000
|
| 407 |
+
And the problem is, managing this key becomes difficult.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:04:13,000 --> 00:04:15,000
|
| 411 |
+
What if A want to communicate with everyone?
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:04:15,000 --> 00:04:17,000
|
| 415 |
+
So A has to manage those number of
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:04:17,000 --> 00:04:18,000
|
| 419 |
+
those amount of keys with A.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:04:18,000 --> 00:04:21,000
|
| 423 |
+
The solution for this is asymmetric cryptography,
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:04:21,000 --> 00:04:23,000
|
| 427 |
+
where you don't have a symmetric key.
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:23,000 --> 00:04:25,000
|
| 431 |
+
Of course, that's what asymmetric means.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:25,000 --> 00:04:26,000
|
| 435 |
+
But what you basically have
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:26,000 --> 00:04:29,000
|
| 439 |
+
is you have a concept of public and private key.
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:29,000 --> 00:04:30,000
|
| 443 |
+
Now, how this works.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:30,000 --> 00:04:33,000
|
| 447 |
+
For the encryption and decryption, you'll be using two keys,
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:33,000 --> 00:04:35,000
|
| 451 |
+
encrypt the public key and a private key.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:35,000 --> 00:04:36,000
|
| 455 |
+
And how that works is,
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:36,000 --> 00:04:40,000
|
| 459 |
+
if you encrypt a data with a private key,
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:40,000 --> 00:04:42,000
|
| 463 |
+
then you have to decrypt the data with a public key.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:42,000 --> 00:04:44,000
|
| 467 |
+
And when you encrypt the data with public key,
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:44,000 --> 00:04:46,000
|
| 471 |
+
you have to decrypt the data with private key.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:46,000 --> 00:04:47,000
|
| 475 |
+
So basically,
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:47,000 --> 00:04:50,000
|
| 479 |
+
you have to use the opposite keys
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:50,000 --> 00:04:50,000
|
| 483 |
+
for encryption, decryption.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:50,000 --> 00:04:53,000
|
| 487 |
+
You can't use same key for both.
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:53,000 --> 00:04:54,000
|
| 491 |
+
Now, what happens is,
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:54,000 --> 00:04:56,000
|
| 495 |
+
now since private key is a private key,
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:56,000 --> 00:04:58,000
|
| 499 |
+
only the owner knows the private key.
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:04:58,000 --> 00:04:59,000
|
| 503 |
+
What about the public key?
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:04:59,000 --> 00:05:03,000
|
| 507 |
+
Public key is known by everyone in the network. Okay?
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:05:03,000 --> 00:05:04,000
|
| 511 |
+
Now, what's the advantage of this?
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:05:04,000 --> 00:05:05,000
|
| 515 |
+
So, let's say there's
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:05:05,000 --> 00:05:08,000
|
| 519 |
+
a public key and private key with the B,
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:05:08,000 --> 00:05:10,000
|
| 523 |
+
and now A wants to send data.
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:05:10,000 --> 00:05:12,000
|
| 527 |
+
Now, a question arise, what key A will use.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:05:14,000 --> 00:05:17,000
|
| 531 |
+
Can A use a private key of B? Of course not.
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:05:17,000 --> 00:05:20,000
|
| 535 |
+
Private key is only known by B,
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:05:20,000 --> 00:05:22,000
|
| 539 |
+
but then public key is known by everyone.
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:22,000 --> 00:05:23,000
|
| 543 |
+
So let's say that we have a central repository
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:23,000 --> 00:05:25,000
|
| 547 |
+
where you have all these keys,
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:25,000 --> 00:05:28,000
|
| 551 |
+
public keys of all the members in the network, right?
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:28,000 --> 00:05:29,000
|
| 555 |
+
So they don't have to basically
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:29,000 --> 00:05:31,000
|
| 559 |
+
ask B to give you a public key.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:05:31,000 --> 00:05:33,000
|
| 563 |
+
Everyone knows what is a public key for B.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:05:33,000 --> 00:05:35,000
|
| 567 |
+
And since it's a public key, there's no risk here.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:05:35,000 --> 00:05:38,000
|
| 571 |
+
Now, when A wants to send this data,
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:05:38,000 --> 00:05:41,000
|
| 575 |
+
what a will do is A will use B's public key to encrypt.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:05:41,000 --> 00:05:43,000
|
| 579 |
+
The beauty is, when B receives the message,
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:05:43,000 --> 00:05:48,000
|
| 583 |
+
B can decrypt with its own private key.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:05:48,000 --> 00:05:51,000
|
| 587 |
+
And only B can do that, because B knows the private key.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:05:51,000 --> 00:05:52,000
|
| 591 |
+
What if C comes in between and say,
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:05:52,000 --> 00:05:55,000
|
| 595 |
+
"Hey, I got the data, now I want to decrypt it."
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:05:55,000 --> 00:05:57,000
|
| 599 |
+
C can't decrypt that with C's private key.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:05:57,000 --> 00:06:01,000
|
| 603 |
+
It can be only decrypt with the B's private key.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:06:01,000 --> 00:06:03,000
|
| 607 |
+
Okay, that's how you basically use
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:06:03,000 --> 00:06:04,000
|
| 611 |
+
asymmetric cryptographic here.
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:06:04,000 --> 00:06:06,000
|
| 615 |
+
Now, there are different algorithms available.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:06:06,000 --> 00:06:08,000
|
| 619 |
+
Now, the question arise,
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:06:08,000 --> 00:06:09,000
|
| 623 |
+
everyone in the network will have their own
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:06:09,000 --> 00:06:11,000
|
| 627 |
+
private key and public key, right?
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:06:11,000 --> 00:06:12,000
|
| 631 |
+
And they know their private key,
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:06:12,000 --> 00:06:13,000
|
| 635 |
+
and public key is known by everyone.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:06:13,000 --> 00:06:16,000
|
| 639 |
+
Now, when D want to send data to E,
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:06:16,000 --> 00:06:17,000
|
| 643 |
+
basically they will be,
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:06:17,000 --> 00:06:19,000
|
| 647 |
+
so let's say D want to send data to E.
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:06:19,000 --> 00:06:21,000
|
| 651 |
+
So D will use E's public key to encrypt
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:06:21,000 --> 00:06:24,000
|
| 655 |
+
and E will use E's private key to decrypt.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:06:24,000 --> 00:06:27,000
|
| 659 |
+
So that's basically the asymmetric box.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:06:27,000 --> 00:06:29,000
|
| 663 |
+
There are different algorithms available for symmetric key,
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:06:29,000 --> 00:06:32,000
|
| 667 |
+
or we have algorithm like AES or DES.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:06:32,000 --> 00:06:34,000
|
| 671 |
+
There are multiple algorithms available.
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:06:34,000 --> 00:06:37,000
|
| 675 |
+
Every algorithm have their own strength and weaknesses.
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:06:37,000 --> 00:06:41,000
|
| 679 |
+
Same goes for asymmetric key, where you have RSA, ECC.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:06:41,000 --> 00:06:44,000
|
| 683 |
+
So we have multiple algorithms available to use.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:06:44,000 --> 00:06:46,000
|
| 687 |
+
Now, depending upon different situation,
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:06:46,000 --> 00:06:47,000
|
| 691 |
+
we can use different algorithms,
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:06:47,000 --> 00:06:50,000
|
| 695 |
+
and some are faster, some are more secure.
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:06:50,000 --> 00:06:54,000
|
| 699 |
+
Some depending upon that, you can use any algorithm there.
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:06:54,000 --> 00:06:55,000
|
| 703 |
+
But now question arise.
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:06:55,000 --> 00:06:59,000
|
| 707 |
+
Let's say A is sending the data to B
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:06:59,000 --> 00:07:01,000
|
| 711 |
+
and say, "Hey, I want to meet at 5:00 PM,"
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:07:01,000 --> 00:07:04,000
|
| 715 |
+
and maybe there's nothing secret here, okay?
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:07:04,000 --> 00:07:06,000
|
| 719 |
+
So now let's say A want to send a message to B by saying,
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:07:06,000 --> 00:07:09,000
|
| 723 |
+
"Hey, let's meet at 5:00 PM,"
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:07:09,000 --> 00:07:11,000
|
| 727 |
+
and the message is going on the network.
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:07:11,000 --> 00:07:12,000
|
| 731 |
+
Now, C comes in between and say,
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:07:12,000 --> 00:07:14,000
|
| 735 |
+
"Hey, let me just hack that packet,
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:07:14,000 --> 00:07:17,000
|
| 739 |
+
and now let me send a new packet."
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:07:17,000 --> 00:07:20,000
|
| 743 |
+
And C says, "Let's meet at 6:00 PM."
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:07:20,000 --> 00:07:23,000
|
| 747 |
+
Now, how C will encrypt it?
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:07:23,000 --> 00:07:25,000
|
| 751 |
+
So what C will do is, so C will use B's public key,
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:07:25,000 --> 00:07:29,000
|
| 755 |
+
which A also did, and send that message to B,
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:07:29,000 --> 00:07:32,000
|
| 759 |
+
and B says, okay, I got a message and it is encrypted.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:07:32,000 --> 00:07:34,000
|
| 763 |
+
Let me use my private key to decrypt. Decryption done.
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:07:34,000 --> 00:07:36,000
|
| 767 |
+
So that means I have to meet at 6:00 PM.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:07:36,000 --> 00:07:39,000
|
| 771 |
+
Okay, so when you are using this cryptography,
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:07:39,000 --> 00:07:41,000
|
| 775 |
+
you are basically encrypting data and decrypting it,
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:07:41,000 --> 00:07:43,000
|
| 779 |
+
but there's no way to prove
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:07:43,000 --> 00:07:45,000
|
| 783 |
+
that the sender is the actual sender.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:07:45,000 --> 00:07:49,000
|
| 787 |
+
So, maybe B is thinking the message is sent by A,
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:07:49,000 --> 00:07:51,000
|
| 791 |
+
but it is actually sent by C.
|
| 792 |
+
|
| 793 |
+
199
|
| 794 |
+
00:07:51,000 --> 00:07:54,000
|
| 795 |
+
How do you maintain that identity here?
|
| 796 |
+
|
| 797 |
+
200
|
| 798 |
+
00:07:54,000 --> 00:07:56,000
|
| 799 |
+
Now, that's where you can use something
|
| 800 |
+
|
| 801 |
+
201
|
| 802 |
+
00:07:56,000 --> 00:07:58,000
|
| 803 |
+
called a digital signature.
|
| 804 |
+
|
| 805 |
+
202
|
| 806 |
+
00:07:58,000 --> 00:08:00,000
|
| 807 |
+
And let's talk about data signature in the next video.
|
| 808 |
+
|
22 - JWT (JSON Web Token) and OAuth2/002 Digital Signature_en.srt
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(gentle bright music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:05,000
|
| 7 |
+
-: Now we know about encryption/decryption,
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:05,000 --> 00:00:07,000
|
| 11 |
+
but then there was no way to prove that the person
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:07,000 --> 00:00:10,000
|
| 15 |
+
who is sending the message is actually that person.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:10,000 --> 00:00:11,000
|
| 19 |
+
Now the way you can do that
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:11,000 --> 00:00:13,000
|
| 23 |
+
is with the help of digital signature.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:13,000 --> 00:00:15,000
|
| 27 |
+
Now what we do here is
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:15,000 --> 00:00:17,000
|
| 31 |
+
what if we don't want to secure the information,
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:17,000 --> 00:00:21,000
|
| 35 |
+
but we want to prove that we are the real person?
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:21,000 --> 00:00:23,000
|
| 39 |
+
Now in that case, what A will do is,
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:23,000 --> 00:00:26,000
|
| 43 |
+
A will not encrypt the message with B's public key,
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:26,000 --> 00:00:28,000
|
| 47 |
+
which he was doing before.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:28,000 --> 00:00:31,000
|
| 51 |
+
Now what A will do is A will encrypt a message
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:31,000 --> 00:00:35,000
|
| 55 |
+
with its own private key.
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:35,000 --> 00:00:37,000
|
| 59 |
+
Remember that we are not using B's public key here.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:37,000 --> 00:00:39,000
|
| 63 |
+
We're using A's private key.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:39,000 --> 00:00:42,000
|
| 67 |
+
Now after encryption, the packet goes to B.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:42,000 --> 00:00:43,000
|
| 71 |
+
Now how B can decrypt it?
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:43,000 --> 00:00:46,000
|
| 75 |
+
Of course, can I use a B's private key?
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:46,000 --> 00:00:49,000
|
| 79 |
+
No, because it is encrypted by A's private key.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:49,000 --> 00:00:51,000
|
| 83 |
+
And the only way you can decrypt that
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:51,000 --> 00:00:53,000
|
| 87 |
+
is with the help of A's public key.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:53,000 --> 00:00:55,000
|
| 91 |
+
If the decryption is possible,
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:55,000 --> 00:00:59,000
|
| 95 |
+
that means that there's a proof that only A has sent it.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:59,000 --> 00:01:00,000
|
| 99 |
+
What if, let's try to attack here?
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:00,000 --> 00:01:03,000
|
| 103 |
+
What if C says, "I want to send this data."
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:03,000 --> 00:01:05,000
|
| 107 |
+
So when the message is going from A to B,
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:05,000 --> 00:01:08,000
|
| 111 |
+
C comes in between say, "Hey, let me hack this message."
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:08,000 --> 00:01:10,000
|
| 115 |
+
And message is gone.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:10,000 --> 00:01:12,000
|
| 119 |
+
Now C is sending a new message
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:12,000 --> 00:01:14,000
|
| 123 |
+
and which key C is going to use?
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:14,000 --> 00:01:17,000
|
| 127 |
+
C is going to use C's private key.
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:17,000 --> 00:01:19,000
|
| 131 |
+
And now when it goes to B,
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:19,000 --> 00:01:22,000
|
| 135 |
+
B is not able to decrypt that with A's public key.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:22,000 --> 00:01:24,000
|
| 139 |
+
It is only possible with the help of C's public key.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:24,000 --> 00:01:27,000
|
| 143 |
+
And now B knows something is wrong.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:27,000 --> 00:01:28,000
|
| 147 |
+
It's not coming from A.
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:28,000 --> 00:01:31,000
|
| 151 |
+
And that's how you prove that the data is not coming from A.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:31,000 --> 00:01:33,000
|
| 155 |
+
It came from someone else.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:33,000 --> 00:01:35,000
|
| 159 |
+
But what if it was possible to decrypt that
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:35,000 --> 00:01:36,000
|
| 163 |
+
with A's public key?
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:36,000 --> 00:01:38,000
|
| 167 |
+
That means we have a proof that A has sent it.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:38,000 --> 00:01:42,000
|
| 171 |
+
Now a cannot say later that, "Hey, I have not sent that."
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:42,000 --> 00:01:43,000
|
| 175 |
+
It's a proof, right?
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:43,000 --> 00:01:45,000
|
| 179 |
+
A has encrypted that with A's private key
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:45,000 --> 00:01:49,000
|
| 183 |
+
and only A knows its own private key.
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:49,000 --> 00:01:50,000
|
| 187 |
+
And that's important.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:50,000 --> 00:01:52,000
|
| 191 |
+
This is called digital signature.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:52,000 --> 00:01:53,000
|
| 195 |
+
But there's one problem here.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:53,000 --> 00:01:55,000
|
| 199 |
+
We don't have security.
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:55,000 --> 00:01:58,000
|
| 203 |
+
We do have a proof that who has sent it,
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:58,000 --> 00:01:59,000
|
| 207 |
+
but anyone can read data.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:59,000 --> 00:02:02,000
|
| 211 |
+
You know, C can also read that data.
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:02,000 --> 00:02:03,000
|
| 215 |
+
Because when C gets this packet,
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:03,000 --> 00:02:06,000
|
| 219 |
+
which says, "Let's meet at 5:00 PM,"
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:06,000 --> 00:02:08,000
|
| 223 |
+
C is able to decrypt it
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:08,000 --> 00:02:11,000
|
| 227 |
+
because A has signed it with a private key,
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:11,000 --> 00:02:15,000
|
| 231 |
+
and to decrypt it, C can use A's public key.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:15,000 --> 00:02:16,000
|
| 235 |
+
You're hacked.
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:16,000 --> 00:02:18,000
|
| 239 |
+
So how do we secure it?
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:18,000 --> 00:02:20,000
|
| 243 |
+
So that's why we have to do double encryption.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:20,000 --> 00:02:21,000
|
| 247 |
+
I mean think about this.
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:21,000 --> 00:02:24,000
|
| 251 |
+
What if you are basically first,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:24,000 --> 00:02:26,000
|
| 255 |
+
so let's say A want to send message to B.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:26,000 --> 00:02:30,000
|
| 259 |
+
First, A will use B's public key to encrypt.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:30,000 --> 00:02:31,000
|
| 263 |
+
So first layer done.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:31,000 --> 00:02:34,000
|
| 267 |
+
Then the same packet will be encrypted again
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:34,000 --> 00:02:36,000
|
| 271 |
+
with A's private key.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:36,000 --> 00:02:38,000
|
| 275 |
+
So double encryption.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:38,000 --> 00:02:39,000
|
| 279 |
+
Now when the packet goes to B,
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:39,000 --> 00:02:42,000
|
| 283 |
+
B says, "Okay, it is encrypted with A's private key.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:42,000 --> 00:02:45,000
|
| 287 |
+
Let me decrypt it with A's public key."
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:45,000 --> 00:02:45,000
|
| 291 |
+
Decryption done.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:45,000 --> 00:02:48,000
|
| 295 |
+
That means there's a proof that A has sent it,
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:48,000 --> 00:02:51,000
|
| 299 |
+
and then again the package is still encrypted.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:51,000 --> 00:02:54,000
|
| 303 |
+
So again, it will do decryption again with B's private key
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:55,000 --> 00:02:57,000
|
| 307 |
+
because no one knows the B's private key.
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:57,000 --> 00:02:59,000
|
| 311 |
+
And now, B got the message
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:59,000 --> 00:03:03,000
|
| 315 |
+
and we have achieved security as well as identity.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:03,000 --> 00:03:05,000
|
| 319 |
+
But what if, let's try to attack here?
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:05,000 --> 00:03:06,000
|
| 323 |
+
So let's say C comes in between
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:06,000 --> 00:03:08,000
|
| 327 |
+
and say, "Hey, I want to attack now."
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:08,000 --> 00:03:09,000
|
| 331 |
+
C receives a package
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:09,000 --> 00:03:13,000
|
| 335 |
+
and says, "Okay, it is encrypted with A's private key.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:13,000 --> 00:03:15,000
|
| 339 |
+
Let me decrypt it with A's public key."
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:15,000 --> 00:03:16,000
|
| 343 |
+
Decryption done.
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:16,000 --> 00:03:19,000
|
| 347 |
+
But now it is still encrypted with B's public key.
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:19,000 --> 00:03:20,000
|
| 351 |
+
Can C decrypt it?
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:20,000 --> 00:03:24,000
|
| 355 |
+
No, because C has no idea what's B's private key
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:24,000 --> 00:03:26,000
|
| 359 |
+
and you're safe, right?
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:26,000 --> 00:03:28,000
|
| 363 |
+
So this is how basically you achieve signature
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:28,000 --> 00:03:29,000
|
| 367 |
+
with encryption.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:29,000 --> 00:03:31,000
|
| 371 |
+
And this will be used in the upcoming session,
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:31,000 --> 00:03:34,000
|
| 375 |
+
so I hope you understood what is cryptography,
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:34,000 --> 00:03:38,000
|
| 379 |
+
what is encryption/decryption, and what is signature.
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:38,000 --> 00:03:39,000
|
| 383 |
+
See you in the next video.
|
| 384 |
+
|
22 - JWT (JSON Web Token) and OAuth2/003 Why JWT_en.srt
ADDED
|
@@ -0,0 +1,792 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(bright music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:06,000
|
| 7 |
+
-: In this video, we'll talk about JWT,
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:06,000 --> 00:00:08,000
|
| 11 |
+
which stands for JSON Web Tokens.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:08,000 --> 00:00:10,000
|
| 15 |
+
Now, before we go there, let's take an example.
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:10,000 --> 00:00:13,000
|
| 19 |
+
So let's say every day when I go to my office,
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:13,000 --> 00:00:14,000
|
| 23 |
+
so we have a cafe,
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:14,000 --> 00:00:16,000
|
| 27 |
+
which is just between my home and my office.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:16,000 --> 00:00:18,000
|
| 31 |
+
I go there to have a coffee,
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:18,000 --> 00:00:20,000
|
| 35 |
+
and then I go to my office.
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:20,000 --> 00:00:21,000
|
| 39 |
+
Of course, for every coffee,
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:21,000 --> 00:00:22,000
|
| 43 |
+
I have to pay some amount.
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:22,000 --> 00:00:25,000
|
| 47 |
+
Let's say I'm paying $1 per coffee every day.
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:25,000 --> 00:00:27,000
|
| 51 |
+
And then, I'm doing this every day, right?
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:27,000 --> 00:00:30,000
|
| 55 |
+
Now, what if I can talk to them by saying,
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:30,000 --> 00:00:32,000
|
| 59 |
+
"Hey, you know, I come there every day.
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:32,000 --> 00:00:35,000
|
| 63 |
+
Let me take a membership of a month."
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:35,000 --> 00:00:36,000
|
| 67 |
+
So maybe I can get a discount.
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:36,000 --> 00:00:38,000
|
| 71 |
+
I mean, I'm going there every day.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:38,000 --> 00:00:40,000
|
| 75 |
+
So what if I can get, let's say in $20,
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:40,000 --> 00:00:42,000
|
| 79 |
+
I can get for the entire month.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:42,000 --> 00:00:44,000
|
| 83 |
+
And now the person knows me.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:44,000 --> 00:00:46,000
|
| 87 |
+
So basically every day, we see each other.
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:46,000 --> 00:00:47,000
|
| 91 |
+
So now he knows who I am.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:47,000 --> 00:00:52,000
|
| 95 |
+
And then he says, "Okay, now we got $20 from you.
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:00:52,000 --> 00:00:54,000
|
| 99 |
+
You can come for the entire month and have a coffee."
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:00:54,000 --> 00:00:58,000
|
| 103 |
+
Now, I went there for first day, second day, third day,
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:00:58,000 --> 00:00:59,000
|
| 107 |
+
and then everything was working.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:00:59,000 --> 00:01:01,000
|
| 111 |
+
So he know my face.
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:01,000 --> 00:01:04,000
|
| 115 |
+
And the problem is, what if the person changes?
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:04,000 --> 00:01:06,000
|
| 119 |
+
Now, of course, we don't want that scenario, right?
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:06,000 --> 00:01:08,000
|
| 123 |
+
Where I go to a cafe after one week
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:08,000 --> 00:01:09,000
|
| 127 |
+
and I see another person,
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:09,000 --> 00:01:11,000
|
| 131 |
+
and then this person says, "Who are you?"
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:11,000 --> 00:01:12,000
|
| 135 |
+
We don't want that.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:12,000 --> 00:01:14,000
|
| 139 |
+
So maybe there should be some entry in a book
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:14,000 --> 00:01:17,000
|
| 143 |
+
where they can make an entry by saying:
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:17,000 --> 00:01:19,000
|
| 147 |
+
This person has taken a subscription of one month,
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:19,000 --> 00:01:22,000
|
| 151 |
+
and every time this person comes, we can give them a coffee.
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:22,000 --> 00:01:25,000
|
| 155 |
+
And now let's say we have an entry there.
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:25,000 --> 00:01:27,000
|
| 159 |
+
So I can go there, I can tell,
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:27,000 --> 00:01:29,000
|
| 163 |
+
"Hey, there should be my entry.
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:29,000 --> 00:01:32,000
|
| 167 |
+
And for the entry, I also got id. So it's my ID is 102.
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:32,000 --> 00:01:34,000
|
| 171 |
+
And every time I go there, I can say,
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:34,000 --> 00:01:36,000
|
| 175 |
+
this is my id, which is 102.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:36,000 --> 00:01:39,000
|
| 179 |
+
And they can refer in that book. Yeah.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:39,000 --> 00:01:40,000
|
| 183 |
+
So we have an id, which is 102,
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:40,000 --> 00:01:43,000
|
| 187 |
+
which says Navin Reddy subscription for one month.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:43,000 --> 00:01:46,000
|
| 191 |
+
That's great. So now I can get my coffee.
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:46,000 --> 00:01:49,000
|
| 195 |
+
So this, this model works better, right?
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:49,000 --> 00:01:50,000
|
| 199 |
+
Where I can get ID as well,
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:50,000 --> 00:01:52,000
|
| 203 |
+
not just person knows me with my face.
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:01:52,000 --> 00:01:54,000
|
| 207 |
+
Now there's one little problem.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:01:54,000 --> 00:01:57,000
|
| 211 |
+
So let's say with this cafe has multiple branches, okay?
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:01:57,000 --> 00:01:59,000
|
| 215 |
+
So it is there in my area,
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:01:59,000 --> 00:02:01,000
|
| 219 |
+
but let's say I go to go for some training
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:01,000 --> 00:02:02,000
|
| 223 |
+
in different cities.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:02,000 --> 00:02:06,000
|
| 227 |
+
I go to let's say Delhi or Bangalore or Mumbai,
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:06,000 --> 00:02:08,000
|
| 231 |
+
and maybe they have the branches.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:08,000 --> 00:02:10,000
|
| 235 |
+
Of course they have scaled out well
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:10,000 --> 00:02:12,000
|
| 239 |
+
and now they have branches in different cities.
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:12,000 --> 00:02:15,000
|
| 243 |
+
So let's say if one day I'm not in my hometown,
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:15,000 --> 00:02:17,000
|
| 247 |
+
I'm going to a different city
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:17,000 --> 00:02:20,000
|
| 251 |
+
and I see a cafe there, the question is,
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:20,000 --> 00:02:22,000
|
| 255 |
+
will I get the free coffee?
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:22,000 --> 00:02:24,000
|
| 259 |
+
I mean, not free, but I got the membership, right?
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:24,000 --> 00:02:26,000
|
| 263 |
+
I should not, I don't have to pay for it.
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:26,000 --> 00:02:28,000
|
| 267 |
+
But then when I go there by saying,
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:28,000 --> 00:02:30,000
|
| 271 |
+
hey, you know, I have id, which is 102,
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:30,000 --> 00:02:31,000
|
| 275 |
+
please check your book.
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:31,000 --> 00:02:32,000
|
| 279 |
+
That should be my entry.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:32,000 --> 00:02:34,000
|
| 283 |
+
What do you think?
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:34,000 --> 00:02:36,000
|
| 287 |
+
Will there be a coffee there or the entry there?
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:36,000 --> 00:02:39,000
|
| 291 |
+
Of course not, because the book is there in my hometown.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:39,000 --> 00:02:41,000
|
| 295 |
+
It's not there in every city.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:41,000 --> 00:02:43,000
|
| 299 |
+
So that's the problem of scaling, which I'm talking about.
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:43,000 --> 00:02:45,000
|
| 303 |
+
So what is the solution here?
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:02:45,000 --> 00:02:49,000
|
| 307 |
+
The solution could be one where instead of them
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:02:49,000 --> 00:02:51,000
|
| 311 |
+
making an entry on their book,
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:02:51,000 --> 00:02:54,000
|
| 315 |
+
what if they can give me a pass, a monthly pass, which says,
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:02:54,000 --> 00:02:58,000
|
| 319 |
+
Navin Reddy has already paid $20 for the entire month
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:02:58,000 --> 00:03:00,000
|
| 323 |
+
and from this date to this date,
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:00,000 --> 00:03:04,000
|
| 327 |
+
if the person has this pass, you can give them a coffee.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:04,000 --> 00:03:05,000
|
| 331 |
+
And that perfectly works, right?
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:05,000 --> 00:03:07,000
|
| 335 |
+
I can just go there in any of the branch,
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:07,000 --> 00:03:10,000
|
| 339 |
+
doesn't matter the location, I will get the coffee.
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:10,000 --> 00:03:12,000
|
| 343 |
+
Okay, that sounds good, right?
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:12,000 --> 00:03:15,000
|
| 347 |
+
And I shared this model with my friend
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:15,000 --> 00:03:17,000
|
| 351 |
+
and now he knows that if you have that pass,
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:17,000 --> 00:03:18,000
|
| 355 |
+
you will get a free coffee.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:18,000 --> 00:03:22,000
|
| 359 |
+
So what he did, he basically printed a coupon which says,
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:22,000 --> 00:03:26,000
|
| 363 |
+
let's say Harsh now also paid $20
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:26,000 --> 00:03:29,000
|
| 367 |
+
and he will get a subscription for the entire month.
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:29,000 --> 00:03:31,000
|
| 371 |
+
But Harsh has not done that.
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:31,000 --> 00:03:35,000
|
| 375 |
+
He is creating his own coupon just by copying my coupon.
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:35,000 --> 00:03:36,000
|
| 379 |
+
And anyone can do that, right?
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:36,000 --> 00:03:39,000
|
| 383 |
+
So they will go to a coffee shop and say, "Hey, I'm Harsh.
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:39,000 --> 00:03:42,000
|
| 387 |
+
I already paid for $20 for the coffee,"
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:42,000 --> 00:03:44,000
|
| 391 |
+
but that coupon is not valid.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:44,000 --> 00:03:45,000
|
| 395 |
+
How do I identify that?
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:45,000 --> 00:03:47,000
|
| 399 |
+
So one way this cafes can improve is
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:47,000 --> 00:03:51,000
|
| 403 |
+
what if with the coupon they also sign it,
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:03:51,000 --> 00:03:53,000
|
| 407 |
+
maybe a manager sign or maybe a company stamp
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:03:53,000 --> 00:03:56,000
|
| 411 |
+
or maybe a digital signature if it is online.
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:03:56,000 --> 00:03:59,000
|
| 415 |
+
And now that is something which can prove
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:03:59,000 --> 00:04:00,000
|
| 419 |
+
that this company coupon is valid.
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:04:00,000 --> 00:04:03,000
|
| 423 |
+
So we moved from having an entry on a book
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:04:03,000 --> 00:04:07,000
|
| 427 |
+
and giving you an ID instead of that give a pass itself,
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:07,000 --> 00:04:08,000
|
| 431 |
+
which which mentions everything.
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:08,000 --> 00:04:11,000
|
| 435 |
+
So in the pass itself, you have all the data,
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:11,000 --> 00:04:14,000
|
| 439 |
+
the person name, at what time this coupon was issued,
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:14,000 --> 00:04:15,000
|
| 443 |
+
what is the expression,
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:15,000 --> 00:04:17,000
|
| 447 |
+
expression, time, and the rules as well.
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:17,000 --> 00:04:19,000
|
| 451 |
+
So you are here just for the coffee,
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:19,000 --> 00:04:21,000
|
| 455 |
+
not for the entire things on the cafe.
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:21,000 --> 00:04:23,000
|
| 459 |
+
Maybe the cafe sells a lot of different stuff
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:23,000 --> 00:04:24,000
|
| 463 |
+
apart from coffee.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:24,000 --> 00:04:27,000
|
| 467 |
+
What I will get is only coffee, right?
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:27,000 --> 00:04:29,000
|
| 471 |
+
So those things will be mentioned on the pass.
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:29,000 --> 00:04:33,000
|
| 475 |
+
So which is better having an ID or this pass?
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:33,000 --> 00:04:35,000
|
| 479 |
+
Of course, both have their own advantages and drawbacks,
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:35,000 --> 00:04:39,000
|
| 483 |
+
but this is another way of having that session.
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:39,000 --> 00:04:41,000
|
| 487 |
+
Now, coming back to the IT world,
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:41,000 --> 00:04:43,000
|
| 491 |
+
we have client and server
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:43,000 --> 00:04:45,000
|
| 495 |
+
where client goes to the server by saying,
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:45,000 --> 00:04:46,000
|
| 499 |
+
"Hey, I want a resource."
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:04:46,000 --> 00:04:48,000
|
| 503 |
+
Now if it is static page,
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:04:48,000 --> 00:04:49,000
|
| 507 |
+
we don't have to verify who the user is.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:04:49,000 --> 00:04:51,000
|
| 511 |
+
I can simply turn a static page.
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:04:51,000 --> 00:04:53,000
|
| 515 |
+
But what if I want to change the data
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:04:53,000 --> 00:04:55,000
|
| 519 |
+
based on the user request?
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:04:55,000 --> 00:04:57,000
|
| 523 |
+
So let's say if I go to my social media app,
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:04:57,000 --> 00:04:58,000
|
| 527 |
+
maybe it can be Instagram, YouTube,
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:04:58,000 --> 00:05:00,000
|
| 531 |
+
and if I want to see the content,
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:05:00,000 --> 00:05:02,000
|
| 535 |
+
or maybe I go to Facebook to see my friend list,
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:05:02,000 --> 00:05:05,000
|
| 539 |
+
I want to see only my things, not others,
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:05,000 --> 00:05:08,000
|
| 543 |
+
other, other settings right?
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:08,000 --> 00:05:10,000
|
| 547 |
+
Now, in this case, the server should know who I am.
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:10,000 --> 00:05:12,000
|
| 551 |
+
I can of, of course I can claim
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:12,000 --> 00:05:14,000
|
| 555 |
+
I'm this person, but how do I verify that?
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:14,000 --> 00:05:16,000
|
| 559 |
+
That's right. You're thinking about login.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:05:16,000 --> 00:05:20,000
|
| 563 |
+
But after doing a login, the server is basically stateless.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:05:20,000 --> 00:05:22,000
|
| 567 |
+
How do you manage there?
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:05:22,000 --> 00:05:24,000
|
| 571 |
+
So one way you can do it on the server side,
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:05:24,000 --> 00:05:25,000
|
| 575 |
+
you can make an entry.
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:05:25,000 --> 00:05:29,000
|
| 579 |
+
So once I log in, the server says, okay, I know you,
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:05:29,000 --> 00:05:31,000
|
| 583 |
+
you are real Navin Reddy.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:05:31,000 --> 00:05:32,000
|
| 587 |
+
This is your session id.
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:05:32,000 --> 00:05:34,000
|
| 591 |
+
And that goes on with the session
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:05:34,000 --> 00:05:35,000
|
| 595 |
+
with the cookies in my machine.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:05:35,000 --> 00:05:38,000
|
| 599 |
+
And every time I go to a server, I can use that cookie.
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:05:38,000 --> 00:05:41,000
|
| 603 |
+
I don't have to basically log in every time for every page.
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:05:41,000 --> 00:05:43,000
|
| 607 |
+
Now that will be weird, right?
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:05:43,000 --> 00:05:44,000
|
| 611 |
+
You go to, let's say you go to Facebook,
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:05:44,000 --> 00:05:48,000
|
| 615 |
+
and every time you log in, not a good idea.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:05:48,000 --> 00:05:49,000
|
| 619 |
+
So what do you do?
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:05:49,000 --> 00:05:50,000
|
| 623 |
+
So basically you have a session ID,
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:05:50,000 --> 00:05:52,000
|
| 627 |
+
which you can use every time.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:05:52,000 --> 00:05:53,000
|
| 631 |
+
And in fact we have seen that
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:05:53,000 --> 00:05:55,000
|
| 635 |
+
when you were talking about this being security,
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:05:55,000 --> 00:05:58,000
|
| 639 |
+
we call it JSessionId and things were working out.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:05:58,000 --> 00:06:00,000
|
| 643 |
+
But what if you want to scale now?
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:06:00,000 --> 00:06:01,000
|
| 647 |
+
What if you don't have one server,
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:06:01,000 --> 00:06:03,000
|
| 651 |
+
you have multiple servers.
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:06:03,000 --> 00:06:06,000
|
| 655 |
+
In that case, JSessionID will not work.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:06:06,000 --> 00:06:08,000
|
| 659 |
+
It's because the session ID is there with one server.
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:06:08,000 --> 00:06:11,000
|
| 663 |
+
When you are scaling up, when you have a horizontal scaling,
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:06:11,000 --> 00:06:13,000
|
| 667 |
+
you have multiple machines now.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:06:13,000 --> 00:06:15,000
|
| 671 |
+
In this case, what we can do is we can,
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:06:15,000 --> 00:06:18,000
|
| 675 |
+
all these servers can share the same database
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:06:18,000 --> 00:06:21,000
|
| 679 |
+
or maybe a cache where you can say, okay,
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:06:21,000 --> 00:06:23,000
|
| 683 |
+
we have a session ID for this particular person.
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:06:23,000 --> 00:06:26,000
|
| 687 |
+
Every time you get a request check in the shared database,
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:06:26,000 --> 00:06:29,000
|
| 691 |
+
or maybe you can tell your load balances,
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:06:29,000 --> 00:06:30,000
|
| 695 |
+
which are between your,
|
| 696 |
+
|
| 697 |
+
175
|
| 698 |
+
00:06:30,000 --> 00:06:33,000
|
| 699 |
+
between you and your servers, that hey, you know,
|
| 700 |
+
|
| 701 |
+
176
|
| 702 |
+
00:06:33,000 --> 00:06:34,000
|
| 703 |
+
every time you get a request from Navin,
|
| 704 |
+
|
| 705 |
+
177
|
| 706 |
+
00:06:34,000 --> 00:06:37,000
|
| 707 |
+
send it to server one because server one knows who Navin is.
|
| 708 |
+
|
| 709 |
+
178
|
| 710 |
+
00:06:37,000 --> 00:06:39,000
|
| 711 |
+
That's one of the solution.
|
| 712 |
+
|
| 713 |
+
179
|
| 714 |
+
00:06:39,000 --> 00:06:41,000
|
| 715 |
+
But what if you don't do all those stuff
|
| 716 |
+
|
| 717 |
+
180
|
| 718 |
+
00:06:41,000 --> 00:06:44,000
|
| 719 |
+
and every time a client goes to the server
|
| 720 |
+
|
| 721 |
+
181
|
| 722 |
+
00:06:44,000 --> 00:06:45,000
|
| 723 |
+
and say login done,
|
| 724 |
+
|
| 725 |
+
182
|
| 726 |
+
00:06:45,000 --> 00:06:48,000
|
| 727 |
+
after that, what if server can give you a pass,
|
| 728 |
+
|
| 729 |
+
183
|
| 730 |
+
00:06:48,000 --> 00:06:50,000
|
| 731 |
+
the same pass, which I got in the coffee shop
|
| 732 |
+
|
| 733 |
+
184
|
| 734 |
+
00:06:50,000 --> 00:06:52,000
|
| 735 |
+
and now every time you go to a server,
|
| 736 |
+
|
| 737 |
+
185
|
| 738 |
+
00:06:52,000 --> 00:06:54,000
|
| 739 |
+
you can show this pass,
|
| 740 |
+
|
| 741 |
+
186
|
| 742 |
+
00:06:54,000 --> 00:06:56,000
|
| 743 |
+
hey, I already paid $20 for the coffee.
|
| 744 |
+
|
| 745 |
+
187
|
| 746 |
+
00:06:56,000 --> 00:06:57,000
|
| 747 |
+
Gimme my coffee for today.
|
| 748 |
+
|
| 749 |
+
188
|
| 750 |
+
00:06:57,000 --> 00:07:01,000
|
| 751 |
+
That's one thing a client can do with that pass.
|
| 752 |
+
|
| 753 |
+
189
|
| 754 |
+
00:07:01,000 --> 00:07:04,000
|
| 755 |
+
But of course we have to also sign the pass, right?
|
| 756 |
+
|
| 757 |
+
190
|
| 758 |
+
00:07:04,000 --> 00:07:07,000
|
| 759 |
+
You don't want unsigned pass where anyone can use it.
|
| 760 |
+
|
| 761 |
+
191
|
| 762 |
+
00:07:07,000 --> 00:07:10,000
|
| 763 |
+
And that's where to implement this coffee concept
|
| 764 |
+
|
| 765 |
+
192
|
| 766 |
+
00:07:10,000 --> 00:07:12,000
|
| 767 |
+
or the subscription concept.
|
| 768 |
+
|
| 769 |
+
193
|
| 770 |
+
00:07:12,000 --> 00:07:14,000
|
| 771 |
+
We have something called JWT,
|
| 772 |
+
|
| 773 |
+
194
|
| 774 |
+
00:07:14,000 --> 00:07:17,000
|
| 775 |
+
which stands for JSON web tokens.
|
| 776 |
+
|
| 777 |
+
195
|
| 778 |
+
00:07:17,000 --> 00:07:18,000
|
| 779 |
+
Basically the concept is about tokens
|
| 780 |
+
|
| 781 |
+
196
|
| 782 |
+
00:07:18,000 --> 00:07:21,000
|
| 783 |
+
and another one of the way to implement that is JWT.
|
| 784 |
+
|
| 785 |
+
197
|
| 786 |
+
00:07:21,000 --> 00:07:25,000
|
| 787 |
+
So what exactly JWT is and what are the options we have?
|
| 788 |
+
|
| 789 |
+
198
|
| 790 |
+
00:07:25,000 --> 00:07:27,000
|
| 791 |
+
We'll see in the next video.
|
| 792 |
+
|
22 - JWT (JSON Web Token) and OAuth2/004 What is JWT_en.srt
ADDED
|
@@ -0,0 +1,696 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1
|
| 2 |
+
00:00:00,000 --> 00:00:03,000
|
| 3 |
+
(gentle music)
|
| 4 |
+
|
| 5 |
+
2
|
| 6 |
+
00:00:03,000 --> 00:00:04,000
|
| 7 |
+
-: So what is JWT?
|
| 8 |
+
|
| 9 |
+
3
|
| 10 |
+
00:00:04,000 --> 00:00:07,000
|
| 11 |
+
So JWT stands for JSON Web Token.
|
| 12 |
+
|
| 13 |
+
4
|
| 14 |
+
00:00:07,000 --> 00:00:11,000
|
| 15 |
+
It's a open industry standard with RFC 7519,
|
| 16 |
+
|
| 17 |
+
5
|
| 18 |
+
00:00:11,000 --> 00:00:14,000
|
| 19 |
+
and basically it is a way to transfer data
|
| 20 |
+
|
| 21 |
+
6
|
| 22 |
+
00:00:14,000 --> 00:00:16,000
|
| 23 |
+
between two different parties, and that to securely.
|
| 24 |
+
|
| 25 |
+
7
|
| 26 |
+
00:00:16,000 --> 00:00:18,000
|
| 27 |
+
Okay, now how it looks like.
|
| 28 |
+
|
| 29 |
+
8
|
| 30 |
+
00:00:18,000 --> 00:00:22,000
|
| 31 |
+
See, whenever you send a token from a server to client,
|
| 32 |
+
|
| 33 |
+
9
|
| 34 |
+
00:00:22,000 --> 00:00:23,000
|
| 35 |
+
it can be a normal XML as well,
|
| 36 |
+
|
| 37 |
+
10
|
| 38 |
+
00:00:23,000 --> 00:00:26,000
|
| 39 |
+
so if you talk about technical world, not the coffee card.
|
| 40 |
+
|
| 41 |
+
11
|
| 42 |
+
00:00:26,000 --> 00:00:28,000
|
| 43 |
+
So let's say if in the technical world,
|
| 44 |
+
|
| 45 |
+
12
|
| 46 |
+
00:00:28,000 --> 00:00:33,000
|
| 47 |
+
you will be having this token a JSON data or XML data,
|
| 48 |
+
|
| 49 |
+
13
|
| 50 |
+
00:00:33,000 --> 00:00:36,000
|
| 51 |
+
but in XML, the length of the data will be lengthy, right?
|
| 52 |
+
|
| 53 |
+
14
|
| 54 |
+
00:00:36,000 --> 00:00:38,000
|
| 55 |
+
Even for the small amount of data,
|
| 56 |
+
|
| 57 |
+
15
|
| 58 |
+
00:00:38,000 --> 00:00:41,000
|
| 59 |
+
you'll be having multiple tags and stuff,
|
| 60 |
+
|
| 61 |
+
16
|
| 62 |
+
00:00:41,000 --> 00:00:43,000
|
| 63 |
+
plus encrypting it will be a different task.
|
| 64 |
+
|
| 65 |
+
17
|
| 66 |
+
00:00:43,000 --> 00:00:46,000
|
| 67 |
+
The other way is you can use normal JSON,
|
| 68 |
+
|
| 69 |
+
18
|
| 70 |
+
00:00:46,000 --> 00:00:47,000
|
| 71 |
+
but again, JSON will be lengthy as well.
|
| 72 |
+
|
| 73 |
+
19
|
| 74 |
+
00:00:47,000 --> 00:00:50,000
|
| 75 |
+
In that case, we can use some encoded format,
|
| 76 |
+
|
| 77 |
+
20
|
| 78 |
+
00:00:50,000 --> 00:00:53,000
|
| 79 |
+
and that's where the JSON web token comes to the picture.
|
| 80 |
+
|
| 81 |
+
21
|
| 82 |
+
00:00:53,000 --> 00:00:55,000
|
| 83 |
+
Now this is the format I'm talking about.
|
| 84 |
+
|
| 85 |
+
22
|
| 86 |
+
00:00:55,000 --> 00:00:57,000
|
| 87 |
+
So when you get a token from the server,
|
| 88 |
+
|
| 89 |
+
23
|
| 90 |
+
00:00:57,000 --> 00:00:58,000
|
| 91 |
+
this is what you will get.
|
| 92 |
+
|
| 93 |
+
24
|
| 94 |
+
00:00:58,000 --> 00:01:02,000
|
| 95 |
+
So this is alphanumeric values, but we can't read it
|
| 96 |
+
|
| 97 |
+
25
|
| 98 |
+
00:01:02,000 --> 00:01:04,000
|
| 99 |
+
because this is in the encoded format.
|
| 100 |
+
|
| 101 |
+
26
|
| 102 |
+
00:01:04,000 --> 00:01:07,000
|
| 103 |
+
So you can also decode this, and when you decode it,
|
| 104 |
+
|
| 105 |
+
27
|
| 106 |
+
00:01:07,000 --> 00:01:09,000
|
| 107 |
+
you can see we have three sections here.
|
| 108 |
+
|
| 109 |
+
28
|
| 110 |
+
00:01:09,000 --> 00:01:10,000
|
| 111 |
+
Now, before that,
|
| 112 |
+
|
| 113 |
+
29
|
| 114 |
+
00:01:10,000 --> 00:01:11,000
|
| 115 |
+
you can see there's a section of algorithms.
|
| 116 |
+
|
| 117 |
+
30
|
| 118 |
+
00:01:11,000 --> 00:01:15,000
|
| 119 |
+
So by the way, where I am now, I'm on jwt.io,
|
| 120 |
+
|
| 121 |
+
31
|
| 122 |
+
00:01:15,000 --> 00:01:17,000
|
| 123 |
+
and you can see we can use different algorithms here.
|
| 124 |
+
|
| 125 |
+
32
|
| 126 |
+
00:01:17,000 --> 00:01:19,000
|
| 127 |
+
Remember when I talked about the signature
|
| 128 |
+
|
| 129 |
+
33
|
| 130 |
+
00:01:19,000 --> 00:01:20,000
|
| 131 |
+
or the encryption?
|
| 132 |
+
|
| 133 |
+
34
|
| 134 |
+
00:01:20,000 --> 00:01:23,000
|
| 135 |
+
Basically we can use different algorithms here.
|
| 136 |
+
|
| 137 |
+
35
|
| 138 |
+
00:01:23,000 --> 00:01:23,000
|
| 139 |
+
We have different options.
|
| 140 |
+
|
| 141 |
+
36
|
| 142 |
+
00:01:23,000 --> 00:01:28,000
|
| 143 |
+
We got Hs, we got Rs, we got Es, and Ps.
|
| 144 |
+
|
| 145 |
+
37
|
| 146 |
+
00:01:28,000 --> 00:01:30,000
|
| 147 |
+
Now basically we have,
|
| 148 |
+
|
| 149 |
+
38
|
| 150 |
+
00:01:30,000 --> 00:01:32,000
|
| 151 |
+
remember when we talked about the asymmetric and symmetric?
|
| 152 |
+
|
| 153 |
+
39
|
| 154 |
+
00:01:32,000 --> 00:01:34,000
|
| 155 |
+
So basically we have Hs here,
|
| 156 |
+
|
| 157 |
+
40
|
| 158 |
+
00:01:34,000 --> 00:01:38,000
|
| 159 |
+
which is HMAC SHA-256, which is symmetric.
|
| 160 |
+
|
| 161 |
+
41
|
| 162 |
+
00:01:38,000 --> 00:01:41,000
|
| 163 |
+
If you want to use asymmetric, we can also use Rs here,
|
| 164 |
+
|
| 165 |
+
42
|
| 166 |
+
00:01:41,000 --> 00:01:44,000
|
| 167 |
+
and higher this numbers, it is better,
|
| 168 |
+
|
| 169 |
+
43
|
| 170 |
+
00:01:44,000 --> 00:01:45,000
|
| 171 |
+
because you'll be having a bigger key.
|
| 172 |
+
|
| 173 |
+
44
|
| 174 |
+
00:01:45,000 --> 00:01:47,000
|
| 175 |
+
Now here you can see we have three sections.
|
| 176 |
+
|
| 177 |
+
45
|
| 178 |
+
00:01:47,000 --> 00:01:49,000
|
| 179 |
+
So each token will have three sections.
|
| 180 |
+
|
| 181 |
+
46
|
| 182 |
+
00:01:49,000 --> 00:01:51,000
|
| 183 |
+
One is the header, one is a payload,
|
| 184 |
+
|
| 185 |
+
47
|
| 186 |
+
00:01:51,000 --> 00:01:53,000
|
| 187 |
+
and next is the signature.
|
| 188 |
+
|
| 189 |
+
48
|
| 190 |
+
00:01:53,000 --> 00:01:55,000
|
| 191 |
+
Now payload is very important here
|
| 192 |
+
|
| 193 |
+
49
|
| 194 |
+
00:01:55,000 --> 00:01:56,000
|
| 195 |
+
because this is where you send your data.
|
| 196 |
+
|
| 197 |
+
50
|
| 198 |
+
00:01:56,000 --> 00:01:59,000
|
| 199 |
+
So when you say a server's giving some token to the client,
|
| 200 |
+
|
| 201 |
+
51
|
| 202 |
+
00:01:59,000 --> 00:02:01,000
|
| 203 |
+
with the information,
|
| 204 |
+
|
| 205 |
+
52
|
| 206 |
+
00:02:01,000 --> 00:02:03,000
|
| 207 |
+
that information stays inside the payload.
|
| 208 |
+
|
| 209 |
+
53
|
| 210 |
+
00:02:03,000 --> 00:02:06,000
|
| 211 |
+
Example, we got, who is subject the person?
|
| 212 |
+
|
| 213 |
+
54
|
| 214 |
+
00:02:06,000 --> 00:02:08,000
|
| 215 |
+
So this is a subject,
|
| 216 |
+
|
| 217 |
+
55
|
| 218 |
+
00:02:08,000 --> 00:02:11,000
|
| 219 |
+
a name, this, and the issuance time is this.
|
| 220 |
+
|
| 221 |
+
56
|
| 222 |
+
00:02:11,000 --> 00:02:14,000
|
| 223 |
+
We can also set the expire time here if you want.
|
| 224 |
+
|
| 225 |
+
57
|
| 226 |
+
00:02:14,000 --> 00:02:19,000
|
| 227 |
+
You can give a comma and you can say expiry,
|
| 228 |
+
|
| 229 |
+
58
|
| 230 |
+
00:02:19,000 --> 00:02:21,000
|
| 231 |
+
and you can give a colon, and you can mention whatever time.
|
| 232 |
+
|
| 233 |
+
59
|
| 234 |
+
00:02:21,000 --> 00:02:24,000
|
| 235 |
+
So maybe I want to use this time,
|
| 236 |
+
|
| 237 |
+
60
|
| 238 |
+
00:02:24,000 --> 00:02:25,000
|
| 239 |
+
plus I want to change,
|
| 240 |
+
|
| 241 |
+
61
|
| 242 |
+
00:02:25,000 --> 00:02:28,000
|
| 243 |
+
let's say I want to make this as 41.
|
| 244 |
+
|
| 245 |
+
62
|
| 246 |
+
00:02:28,000 --> 00:02:29,000
|
| 247 |
+
So this is my expiration time,
|
| 248 |
+
|
| 249 |
+
63
|
| 250 |
+
00:02:29,000 --> 00:02:32,000
|
| 251 |
+
and this should result some values.
|
| 252 |
+
|
| 253 |
+
64
|
| 254 |
+
00:02:32,000 --> 00:02:33,000
|
| 255 |
+
So issuance is this.
|
| 256 |
+
|
| 257 |
+
65
|
| 258 |
+
00:02:33,000 --> 00:02:35,000
|
| 259 |
+
This is a date for today, not today.
|
| 260 |
+
|
| 261 |
+
66
|
| 262 |
+
00:02:35,000 --> 00:02:39,000
|
| 263 |
+
This is a date which is Jan 18th, 2018,
|
| 264 |
+
|
| 265 |
+
67
|
| 266 |
+
00:02:39,000 --> 00:02:42,000
|
| 267 |
+
and 7:00 AM, looks like.
|
| 268 |
+
|
| 269 |
+
68
|
| 270 |
+
00:02:42,000 --> 00:02:46,000
|
| 271 |
+
And if you look here, this is 7:30.
|
| 272 |
+
|
| 273 |
+
69
|
| 274 |
+
00:02:46,000 --> 00:02:48,000
|
| 275 |
+
So we got this for 30 minutes, right?
|
| 276 |
+
|
| 277 |
+
70
|
| 278 |
+
00:02:48,000 --> 00:02:49,000
|
| 279 |
+
The token.
|
| 280 |
+
|
| 281 |
+
71
|
| 282 |
+
00:02:49,000 --> 00:02:50,000
|
| 283 |
+
Of course, the token will expire.
|
| 284 |
+
|
| 285 |
+
72
|
| 286 |
+
00:02:50,000 --> 00:02:52,000
|
| 287 |
+
You can set the expire time here.
|
| 288 |
+
|
| 289 |
+
73
|
| 290 |
+
00:02:52,000 --> 00:02:54,000
|
| 291 |
+
So this is your payload and you can send multiple data here.
|
| 292 |
+
|
| 293 |
+
74
|
| 294 |
+
00:02:54,000 --> 00:02:56,000
|
| 295 |
+
It's not just you have to send only this.
|
| 296 |
+
|
| 297 |
+
75
|
| 298 |
+
00:02:56,000 --> 00:02:57,000
|
| 299 |
+
We can add more data,
|
| 300 |
+
|
| 301 |
+
76
|
| 302 |
+
00:02:57,000 --> 00:03:02,000
|
| 303 |
+
but trying to make payload as small as possible,
|
| 304 |
+
|
| 305 |
+
77
|
| 306 |
+
00:03:02,000 --> 00:03:03,000
|
| 307 |
+
because you'll be sending this in the header,
|
| 308 |
+
|
| 309 |
+
78
|
| 310 |
+
00:03:03,000 --> 00:03:04,000
|
| 311 |
+
and then there are some servers
|
| 312 |
+
|
| 313 |
+
79
|
| 314 |
+
00:03:04,000 --> 00:03:08,000
|
| 315 |
+
which will not accept a bigger chunk of header.
|
| 316 |
+
|
| 317 |
+
80
|
| 318 |
+
00:03:08,000 --> 00:03:11,000
|
| 319 |
+
So make sure that you don't put unnecessary stuff here.
|
| 320 |
+
|
| 321 |
+
81
|
| 322 |
+
00:03:11,000 --> 00:03:12,000
|
| 323 |
+
Okay, now this is algorithm which we are using here,
|
| 324 |
+
|
| 325 |
+
82
|
| 326 |
+
00:03:12,000 --> 00:03:14,000
|
| 327 |
+
which is HS226.
|
| 328 |
+
|
| 329 |
+
83
|
| 330 |
+
00:03:14,000 --> 00:03:15,000
|
| 331 |
+
This is what you'll be having in the header.
|
| 332 |
+
|
| 333 |
+
84
|
| 334 |
+
00:03:15,000 --> 00:03:17,000
|
| 335 |
+
You can change it and you can use some other algorithm.
|
| 336 |
+
|
| 337 |
+
85
|
| 338 |
+
00:03:17,000 --> 00:03:20,000
|
| 339 |
+
Let's say if I want to use R, I can use that,
|
| 340 |
+
|
| 341 |
+
86
|
| 342 |
+
00:03:20,000 --> 00:03:21,000
|
| 343 |
+
but let me stick to Hs here,
|
| 344 |
+
|
| 345 |
+
87
|
| 346 |
+
00:03:21,000 --> 00:03:25,000
|
| 347 |
+
and then we are specifying the type of token,
|
| 348 |
+
|
| 349 |
+
88
|
| 350 |
+
00:03:25,000 --> 00:03:27,000
|
| 351 |
+
which is JWT in this case.
|
| 352 |
+
|
| 353 |
+
89
|
| 354 |
+
00:03:27,000 --> 00:03:28,000
|
| 355 |
+
Next we have a signature.
|
| 356 |
+
|
| 357 |
+
90
|
| 358 |
+
00:03:28,000 --> 00:03:30,000
|
| 359 |
+
So when you say you want to sign it,
|
| 360 |
+
|
| 361 |
+
91
|
| 362 |
+
00:03:30,000 --> 00:03:31,000
|
| 363 |
+
you have to use some signature,
|
| 364 |
+
|
| 365 |
+
92
|
| 366 |
+
00:03:31,000 --> 00:03:34,000
|
| 367 |
+
and of course, you can use RSA
|
| 368 |
+
|
| 369 |
+
93
|
| 370 |
+
00:03:34,000 --> 00:03:34,000
|
| 371 |
+
where you get two different signatures,
|
| 372 |
+
|
| 373 |
+
94
|
| 374 |
+
00:03:34,000 --> 00:03:36,000
|
| 375 |
+
for private and public key,
|
| 376 |
+
|
| 377 |
+
95
|
| 378 |
+
00:03:36,000 --> 00:03:37,000
|
| 379 |
+
but when you're using Hs,
|
| 380 |
+
|
| 381 |
+
96
|
| 382 |
+
00:03:37,000 --> 00:03:38,000
|
| 383 |
+
you'll get only one secret key
|
| 384 |
+
|
| 385 |
+
97
|
| 386 |
+
00:03:38,000 --> 00:03:41,000
|
| 387 |
+
which will be shared by client and server,
|
| 388 |
+
|
| 389 |
+
98
|
| 390 |
+
00:03:41,000 --> 00:03:43,000
|
| 391 |
+
and you can encrypt it.
|
| 392 |
+
|
| 393 |
+
99
|
| 394 |
+
00:03:43,000 --> 00:03:45,000
|
| 395 |
+
The problem is when you say encryption,
|
| 396 |
+
|
| 397 |
+
100
|
| 398 |
+
00:03:45,000 --> 00:03:48,000
|
| 399 |
+
we are not achieving the actual encryption here.
|
| 400 |
+
|
| 401 |
+
101
|
| 402 |
+
00:03:48,000 --> 00:03:48,000
|
| 403 |
+
We are just saying
|
| 404 |
+
|
| 405 |
+
102
|
| 406 |
+
00:03:48,000 --> 00:03:52,000
|
| 407 |
+
that no one should be able to modify this token.
|
| 408 |
+
|
| 409 |
+
103
|
| 410 |
+
00:03:52,000 --> 00:03:54,000
|
| 411 |
+
So example, if I got a token from the server,
|
| 412 |
+
|
| 413 |
+
104
|
| 414 |
+
00:03:54,000 --> 00:03:57,000
|
| 415 |
+
no one else can hack my token and modify it,
|
| 416 |
+
|
| 417 |
+
105
|
| 418 |
+
00:03:57,000 --> 00:03:58,000
|
| 419 |
+
because it is signed, right?
|
| 420 |
+
|
| 421 |
+
106
|
| 422 |
+
00:03:58,000 --> 00:04:00,000
|
| 423 |
+
But what if you want to encrypt it?
|
| 424 |
+
|
| 425 |
+
107
|
| 426 |
+
00:04:00,000 --> 00:04:04,000
|
| 427 |
+
So we also have an option of encrypting your JWT,
|
| 428 |
+
|
| 429 |
+
108
|
| 430 |
+
00:04:04,000 --> 00:04:06,000
|
| 431 |
+
and by the default, we are not doing it here,
|
| 432 |
+
|
| 433 |
+
109
|
| 434 |
+
00:04:06,000 --> 00:04:08,000
|
| 435 |
+
but we can encrypt it, and that's where.
|
| 436 |
+
|
| 437 |
+
110
|
| 438 |
+
00:04:08,000 --> 00:04:11,000
|
| 439 |
+
When you are not encrypting your token,
|
| 440 |
+
|
| 441 |
+
111
|
| 442 |
+
00:04:11,000 --> 00:04:13,000
|
| 443 |
+
that means anyone can see that.
|
| 444 |
+
|
| 445 |
+
112
|
| 446 |
+
00:04:13,000 --> 00:04:15,000
|
| 447 |
+
That's right, anyone can see your data,
|
| 448 |
+
|
| 449 |
+
113
|
| 450 |
+
00:04:15,000 --> 00:04:19,000
|
| 451 |
+
and that's why don't put secret data on in the payload.
|
| 452 |
+
|
| 453 |
+
114
|
| 454 |
+
00:04:19,000 --> 00:04:22,000
|
| 455 |
+
Don't put your phone number or your Social Security number
|
| 456 |
+
|
| 457 |
+
115
|
| 458 |
+
00:04:22,000 --> 00:04:24,000
|
| 459 |
+
or your bank password.
|
| 460 |
+
|
| 461 |
+
116
|
| 462 |
+
00:04:24,000 --> 00:04:26,000
|
| 463 |
+
It should be only these details.
|
| 464 |
+
|
| 465 |
+
117
|
| 466 |
+
00:04:26,000 --> 00:04:28,000
|
| 467 |
+
So that's basically JWT.
|
| 468 |
+
|
| 469 |
+
118
|
| 470 |
+
00:04:28,000 --> 00:04:30,000
|
| 471 |
+
Now how we are going to implement this?
|
| 472 |
+
|
| 473 |
+
119
|
| 474 |
+
00:04:30,000 --> 00:04:32,000
|
| 475 |
+
So if you want to implement this in your application,
|
| 476 |
+
|
| 477 |
+
120
|
| 478 |
+
00:04:32,000 --> 00:04:34,000
|
| 479 |
+
so let's say we are going to build a very simple one
|
| 480 |
+
|
| 481 |
+
121
|
| 482 |
+
00:04:34,000 --> 00:04:37,000
|
| 483 |
+
where a user sends a request to the server by saying,
|
| 484 |
+
|
| 485 |
+
122
|
| 486 |
+
00:04:37,000 --> 00:04:39,000
|
| 487 |
+
I want to say hi,
|
| 488 |
+
|
| 489 |
+
123
|
| 490 |
+
00:04:39,000 --> 00:04:40,000
|
| 491 |
+
and the server will say, "Welcome to Telusko."
|
| 492 |
+
|
| 493 |
+
124
|
| 494 |
+
00:04:40,000 --> 00:04:43,000
|
| 495 |
+
That's it, a simple API, and I want to secure it.
|
| 496 |
+
|
| 497 |
+
125
|
| 498 |
+
00:04:43,000 --> 00:04:44,000
|
| 499 |
+
Now how we are gonna do this?
|
| 500 |
+
|
| 501 |
+
126
|
| 502 |
+
00:04:44,000 --> 00:04:46,000
|
| 503 |
+
First step,
|
| 504 |
+
|
| 505 |
+
127
|
| 506 |
+
00:04:46,000 --> 00:04:49,000
|
| 507 |
+
a client will send the username and password to the server.
|
| 508 |
+
|
| 509 |
+
128
|
| 510 |
+
00:04:49,000 --> 00:04:51,000
|
| 511 |
+
A server will say,
|
| 512 |
+
|
| 513 |
+
129
|
| 514 |
+
00:04:51,000 --> 00:04:52,000
|
| 515 |
+
"Okay, I'm verifying the username and password,
|
| 516 |
+
|
| 517 |
+
130
|
| 518 |
+
00:04:52,000 --> 00:04:55,000
|
| 519 |
+
which is correct, and now you are logged in."
|
| 520 |
+
|
| 521 |
+
131
|
| 522 |
+
00:04:55,000 --> 00:04:56,000
|
| 523 |
+
Now once you are logged in,
|
| 524 |
+
|
| 525 |
+
132
|
| 526 |
+
00:04:56,000 --> 00:05:00,000
|
| 527 |
+
the server will send a JWT token.
|
| 528 |
+
|
| 529 |
+
133
|
| 530 |
+
00:05:00,000 --> 00:05:02,000
|
| 531 |
+
Now this token goes to the client,
|
| 532 |
+
|
| 533 |
+
134
|
| 534 |
+
00:05:02,000 --> 00:05:04,000
|
| 535 |
+
and it's client's responsibility to save it now,
|
| 536 |
+
|
| 537 |
+
135
|
| 538 |
+
00:05:04,000 --> 00:05:07,000
|
| 539 |
+
and next time when a client goes to the server, by saying,
|
| 540 |
+
|
| 541 |
+
136
|
| 542 |
+
00:05:07,000 --> 00:05:09,000
|
| 543 |
+
"Hey, now I want sample predicted resource,"
|
| 544 |
+
|
| 545 |
+
137
|
| 546 |
+
00:05:09,000 --> 00:05:12,000
|
| 547 |
+
maybe I want to say hi, or maybe I want to add two numbers,
|
| 548 |
+
|
| 549 |
+
138
|
| 550 |
+
00:05:12,000 --> 00:05:15,000
|
| 551 |
+
whatever it can be, the server will say, "Who are you?"
|
| 552 |
+
|
| 553 |
+
139
|
| 554 |
+
00:05:15,000 --> 00:05:17,000
|
| 555 |
+
Then you can say, "Okay, hold on."
|
| 556 |
+
|
| 557 |
+
140
|
| 558 |
+
00:05:17,000 --> 00:05:20,000
|
| 559 |
+
When I'm sending a request, I have to also send the token.
|
| 560 |
+
|
| 561 |
+
141
|
| 562 |
+
00:05:20,000 --> 00:05:22,000
|
| 563 |
+
The token goes to a server.
|
| 564 |
+
|
| 565 |
+
142
|
| 566 |
+
00:05:22,000 --> 00:05:23,000
|
| 567 |
+
Server will say, "Okay, let me wait.
|
| 568 |
+
|
| 569 |
+
143
|
| 570 |
+
00:05:23,000 --> 00:05:25,000
|
| 571 |
+
Let me verify your token first,"
|
| 572 |
+
|
| 573 |
+
144
|
| 574 |
+
00:05:25,000 --> 00:05:27,000
|
| 575 |
+
and once the token is verified,
|
| 576 |
+
|
| 577 |
+
145
|
| 578 |
+
00:05:27,000 --> 00:05:31,000
|
| 579 |
+
a server will be able to call the API
|
| 580 |
+
|
| 581 |
+
146
|
| 582 |
+
00:05:31,000 --> 00:05:33,000
|
| 583 |
+
and send the response back.
|
| 584 |
+
|
| 585 |
+
147
|
| 586 |
+
00:05:33,000 --> 00:05:35,000
|
| 587 |
+
That means every time you go to the server,
|
| 588 |
+
|
| 589 |
+
148
|
| 590 |
+
00:05:35,000 --> 00:05:38,000
|
| 591 |
+
you have to take your token with you,
|
| 592 |
+
|
| 593 |
+
149
|
| 594 |
+
00:05:38,000 --> 00:05:41,000
|
| 595 |
+
and of course, it should be done before it expires.
|
| 596 |
+
|
| 597 |
+
150
|
| 598 |
+
00:05:41,000 --> 00:05:43,000
|
| 599 |
+
Now, if you want to implement this in your application,
|
| 600 |
+
|
| 601 |
+
151
|
| 602 |
+
00:05:43,000 --> 00:05:46,000
|
| 603 |
+
we have to use some library for JWT,
|
| 604 |
+
|
| 605 |
+
152
|
| 606 |
+
00:05:46,000 --> 00:05:47,000
|
| 607 |
+
and we are going to see that in the code.
|
| 608 |
+
|
| 609 |
+
153
|
| 610 |
+
00:05:47,000 --> 00:05:49,000
|
| 611 |
+
And most of the things,
|
| 612 |
+
|
| 613 |
+
154
|
| 614 |
+
00:05:49,000 --> 00:05:52,000
|
| 615 |
+
which will make sense in the code itself, don't worry.
|
| 616 |
+
|
| 617 |
+
155
|
| 618 |
+
00:05:52,000 --> 00:05:54,000
|
| 619 |
+
But we have to add multiple mechanisms here.
|
| 620 |
+
|
| 621 |
+
156
|
| 622 |
+
00:05:54,000 --> 00:05:56,000
|
| 623 |
+
First we have to have a library.
|
| 624 |
+
|
| 625 |
+
157
|
| 626 |
+
00:05:56,000 --> 00:05:59,000
|
| 627 |
+
Now, using this library, you will be creating a token.
|
| 628 |
+
|
| 629 |
+
158
|
| 630 |
+
00:05:59,000 --> 00:06:01,000
|
| 631 |
+
So of course, you have to do a login,
|
| 632 |
+
|
| 633 |
+
159
|
| 634 |
+
00:06:01,000 --> 00:06:03,000
|
| 635 |
+
and once it is logged in, you have to create a token.
|
| 636 |
+
|
| 637 |
+
160
|
| 638 |
+
00:06:03,000 --> 00:06:06,000
|
| 639 |
+
So you are responsible to create the token.
|
| 640 |
+
|
| 641 |
+
161
|
| 642 |
+
00:06:06,000 --> 00:06:08,000
|
| 643 |
+
Next, you have to send this token to the client,
|
| 644 |
+
|
| 645 |
+
162
|
| 646 |
+
00:06:08,000 --> 00:06:11,000
|
| 647 |
+
and when a client sends the next request,
|
| 648 |
+
|
| 649 |
+
163
|
| 650 |
+
00:06:11,000 --> 00:06:13,000
|
| 651 |
+
a client will send a token,
|
| 652 |
+
|
| 653 |
+
164
|
| 654 |
+
00:06:13,000 --> 00:06:15,000
|
| 655 |
+
and it is your job to verify the token.
|
| 656 |
+
|
| 657 |
+
165
|
| 658 |
+
00:06:15,000 --> 00:06:17,000
|
| 659 |
+
So you have multiple steps to do,
|
| 660 |
+
|
| 661 |
+
166
|
| 662 |
+
00:06:17,000 --> 00:06:19,000
|
| 663 |
+
and the upcoming code will not be that simple,
|
| 664 |
+
|
| 665 |
+
167
|
| 666 |
+
00:06:19,000 --> 00:06:20,000
|
| 667 |
+
so just be with me.
|
| 668 |
+
|
| 669 |
+
168
|
| 670 |
+
00:06:20,000 --> 00:06:22,000
|
| 671 |
+
I will try to make it simple,
|
| 672 |
+
|
| 673 |
+
169
|
| 674 |
+
00:06:22,000 --> 00:06:23,000
|
| 675 |
+
but once you complete the entire code,
|
| 676 |
+
|
| 677 |
+
170
|
| 678 |
+
00:06:23,000 --> 00:06:26,000
|
| 679 |
+
you can go through it and things will make sense.
|
| 680 |
+
|
| 681 |
+
171
|
| 682 |
+
00:06:26,000 --> 00:06:28,000
|
| 683 |
+
So yeah, we have, we just have two tasks here,
|
| 684 |
+
|
| 685 |
+
172
|
| 686 |
+
00:06:28,000 --> 00:06:30,000
|
| 687 |
+
create the token and verify the token,
|
| 688 |
+
|
| 689 |
+
173
|
| 690 |
+
00:06:30,000 --> 00:06:31,000
|
| 691 |
+
and how do we do that?
|
| 692 |
+
|
| 693 |
+
174
|
| 694 |
+
00:06:31,000 --> 00:06:33,000
|
| 695 |
+
That's in the practical videos.
|
| 696 |
+
|