Hello LazyProgrammer thanks for you video, 1 question what is the function of the JwtAuthenticationFilter?? in your implementation, because you added/instantiate the class in the securityFilterChain method as a filter .addFilter(new JwtAuthenticationFilter(authenticationManager(httpSecurity.getSharedObject(AuthenticationConfiguration.class)), jwtUtil)) however there is no use case (at least that i was able to find) that actually makes use of the implementation 1 for login you created a controller and service that gets the userdetails using userdetailservice bean and then creates a jwt using jwtutil class 2 for secure routes the generated token is used in the JwtAuthorizationFilter class to validate the user 3 for register no authentication is applied
To generate JWT tokens without a REST endpoint? ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Q96jo3UVLoU.html You can checkout the usage of JwtAuthenticationFilter in this.
That's a really good point which you have highlighted Hridesh. For using hasRole we have to follow a naming convention like start the role name as "ROLE_". Because spring security expects this naming format. If you don't provide it then Spring will add it explicitly and then check it But this is not mandatory if you use hasAuthority. So, you can use the role names as per your choice and spring will not add prefixes.
Why using deprecated methods instead of latest 0.12.6v of jjwt ... If possible can you help me to get the latest Jwt Authorization token... I tried but can't access preAuthorize API has Role ADMIN....
@@LazzyProgrammer Thanks a lot for ur response....I tried it on all aspects of accessing RBAC, In DB role name is saved as ROLE_ADMIN ROLE_USER Also at SecurityConfig Giving @EnableMethodSecurity(prePostEnabled = true) For @preAuthorize("hasRole('ADMIN')") @DeleteMapping Admin role Jwt Authorization token can't access the above API... help me...
Hi Chetan, You can check the video below as I have covered the same problem in my recent video. RBAC JWT + SpringBoot 3 + Upgrade JWT + Fix Deprecated Method Usage: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-gfHsKST8hXs.html
Thank you for your feedback, Sure I can take a look into such series after completing Spring Security. In the mean time if you want you can check out few videos where such issues are discussed. Links are give below: Memory Leaks: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-1ksJpgk1HIc.html Working of Heap Memory: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HItOMv92MFA.html and few Garbage Collection related videos also.
Brother Your Scratch level Explanation on Core and Advance Java is NextLevel 🔥🔥🔥🔥Whatever you explain in between ~15 Minuit video is More than 3 day's classroom tutor .Thank's Brother for your Work God Bless You.
Thanks for your crystal clear explanation about JWT.. It's time to implement JWT in our application . Do you have any reference video , If yes , Please send me link . I will look into it ..
Thank You Praveen for your valuable feedback. Implementation of JWT is going to be our next video in this series. There we'll create an application from scratch and implement JWT End-to-End. Hopefully that will help you to understand in detail about the Implementation part as well. Once again Thank you so much and Keep Supporting
Really great video in terms of the information provided and the way you explained everything. It would be even better if you could work a bit on thumbnails for more reach. Looking forward to more of these videos-you're doing a fantastic job! Kudos!
Yes, it is better to pass the lock object to the constructor if you want to ensure that all instances share the same lock object. There is only one lock which is static thus shared across all the objects of the class.
00:02 A simple logical error caused the biggest IT outage in history. 00:50 CrowdStrike update caused system crash on Windows devices 01:37 Blue screen of death indicated system crash affecting Windows users worldwide 02:26 Global IT outage impacted various services and companies 03:09 Addressing the Windows outage through safe mode and deployment of fix. 03:53 Channel files were updated, impacting Windows users worldwide. 04:40 A configuration update led to a logical error causing operating system crashes. 05:25 Endpoint security tools help detect and respond to cyber threats.
can anyone please tell what is wrong with this code. output is not as expected. I am just counting by multiple threads using locking. I really did not understand what is the problem here. Expected and should be 10*100 => 1000 public class CountingProblem { private static int counter = 0; private static final ReentrantLock lock = new ReentrantLock(); public static void main(String[] args) { for (int i = 0 ; i < 10 ; i++) { // 10 thread are running new Thread(() -> { for (int j = 0 ; j < 100 ; j++) { // each thread should increase it to 100 lock.lock(); // lock the section try { // run the critical section counter++; // increase the counter } finally { // unlock the lock lock.unlock(); } } }).start(); } System.out.println(counter); } }
Multiple threads which you have created in the for loop are running in parallel to the main thread, but you are directly printing the value of counter after for loop, so there is a possibility that few of the threads might still be in execution when main thread gets the CPU and executed System.out.println(counter); which will result in incorrect output. So, before you print the final value of counter, please make sure that all the threads complete their execution. For that you can use a simple array of type Thread and add all newly created threads in that array during that for loop execution. And after that for loop, iterate through all the created Threads and using .join() make sure all threads have completed their execution. Once that is done only then print the final value of counter. I hope this is was helpful. Please do write your feedback :)
@@LazzyProgrammer aha got it so I need to print the counter value after end of all the threads has finished there job, thread.join(), that for the observation
Hey I am facing some problem while implementing readWriteLock. Can you please let me know what is the problem I am making here So there is a class which having some value [so it is a critical section], Now from our main class I am creating 5 read thread to read the data from that critical section 5 times and 5 write thread to update the data. so the expectation is I want to have same value for a particular thread for every iteration, and while updating the value another thread should read the value import java.util.concurrent.locks.ReentrantReadWriteLock; public class Node<T> extends ReentrantReadWriteLock { private T value; public Node(T value) { this.value = value; } public void setValue(T value) { this.value = value; } public T getValue() { return this.value; } } import java.util.concurrent.ThreadLocalRandom; public class ReadWriteLockDemo2 { private static Node<Integer> resource = new Node<>(5); public static void main(String[] args) { for (int i = 0 ; i < 5 ; i++) { new Thread(() -> { resource.readLock(); try { for (int j = 0 ; j < 5 ; j++) { System.out.println(Thread.currentThread().getName() + " is reading the data " + resource.getValue()); try { Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000)); } catch (InterruptedException e) { throw new RuntimeException(e); } } } finally { resource.readLock().unlock(); } }).start(); } for (int i = 0 ; i < 5 ; i++) { new Thread(() -> { resource.writeLock(); try { int value = ThreadLocalRandom.current().nextInt(1, 100); System.out.println(Thread.currentThread().getName() + " is writing the data with " + value); resource.setValue(value); try { Thread.sleep(ThreadLocalRandom.current().nextInt(1000, 5000)); } catch (InterruptedException e) { throw new RuntimeException(e); } } finally { resource.writeLock().unlock(); } }).start(); } } } I feel like locks are not working properly can you check I am getting first time iteration all read are working then all write are working and updating quickly [updating the value at the same time] where as they have to wait because that's a write lock but they are not waiting. Also I am getting this 2 error not sure where I am making this mistake, "attempt to unlock read lock, not locked by current thread"
Your current code can lead to a deadlock scenario, If a read thread holds the read lock and a write thread tries to acquire the write lock, they’ll block each other indefinitely. Additionally, You have extended ReentrantReadWriteLock in your Node class. This is not the correct way to use it. Instead, create an instance of ReentrantReadWriteLock within your Node class and use it for synchronization. Can you try below code: import java.util.concurrent.locks.ReentrantReadWriteLock; class Node<T> { private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); private T value; public Node(T value) { this.value = value; } public void setValue(T value) { lock.writeLock().lock(); try { this.value = value; } finally { lock.writeLock().unlock(); } } public T getValue() { lock.readLock().lock(); try { return value; } finally { lock.readLock().unlock(); } } } public class ReadWriteLockDemo { public static void main(String[] args) { Node<Integer> resource = new Node<>(5); // Create read threads for (int i = 0; i < 5; i++) { new Thread(() -> { for (int j = 0; j < 5; j++) { System.out.println(Thread.currentThread().getName() + " is reading the data: " + resource.getValue()); try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }).start(); } // Create write threads for (int i = 0; i < 5; i++) { new Thread(() -> { int value = (int) (Math.random() * 100); System.out.println(Thread.currentThread().getName() + " is writing the data with value: " + value); resource.setValue(value); try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }).start(); } } }
I have a question, if you closly the implementation using wait and notify method it is not exactly doing what blocking queue is doing, so I thing blocking queue is working Asynchronously where as wait and notify is working synchronously as we have added synchronized block over the shared resources, So basically I want to say if you look output of wait-notify method there always will be goring phase of the buffer sequaltially and once it reach the limit then shrinking phase of the buffer start sequentially and again growing phase vice-versa, but in the case of BlockingQueue the growing and shrinking phase of the queue is not sequential it is parallel. So how can we achieve that using wait and notify method approach, batter I would how BlockingQueue is achieving this kind of concurrent way of updatating the buffer.
Blocking Queue handles concurrent updates to the buffer by allowing multiple threads to interact with the queue simultaneously without the need for explicit synchronization. It internally handles synchronization. Using wait and notify it's sequential order within synchronized blocks, where one thread must wait for another to release the lock before proceeding.
I have one questino what if my size of the counting latch less then the number of thread I want to perform then what will happen? also what will happen if the size of the latch greater than the number of thread I want to perform?
If the size of the CountDownLatch is less than the number of threads, some threads will reach zero and proceed before all threads have completed their work. Secondly, If the size of the CountDownLatch is greater than the number of threads, the latch will never reach zero, causing the waiting threads to be blocked indefinitely.
@@LazzyProgrammer okay thanks I have checked the second scenario where size if the latch is greater than the number of threads calling the latch and it worked as expected, latch never gets to 0 and the main thread is blocked infinitely. But the first scenario I could not recreate not sure why, is the problem in my machine or what, can you please check form your too, I am posting the code snippet package threading.threadControl; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadLocalRandom; public class CountDownLatchDemo { public static void main(String[] args) throws InterruptedException { CountDownLatch countDownLatch = new CountDownLatch(1); System.out.println("let's start Hiking by main thread..."); Thread.sleep(ThreadLocalRandom.current().nextInt(500, 1000)); for (int i = 1 ; i <= 20 ; i++) { int finalI = i; new Thread(() -> { System.out.println("are you ready thread" + finalI); try { Thread.sleep(ThreadLocalRandom.current().nextInt(500, 1000)); } catch (InterruptedException e) { throw new RuntimeException(e); } System.out.println("Yes I am ready response by thread" + finalI); countDownLatch.countDown(); }).start(); } countDownLatch.await(); // it will start when it becomes 0 Thread.sleep(ThreadLocalRandom.current().nextInt(500, 1000)); System.out.println("Let's Hiking by main thread..."); } } I am getting this out put all the time (getting this last line [Let's Hiking by main thread...] at last all the time), technically I should not let's start Hiking by main thread... are you ready thread2 are you ready thread1 are you ready thread3 are you ready thread5 are you ready thread4 Yes I am ready response by thread1 Yes I am ready response by thread4 Yes I am ready response by thread2 Yes I am ready response by thread3 Yes I am ready response by thread5 Let's Hiking by main thread...
Thanks for you explaination honestly I am really learning something new about thread controlling, and these are very premium content, I bet no one will put this on internet for free, thanks for your selfless effort.
Very nice tutorial.. please some field more added like DOB male or female check box and capchta implementation in both registration ND login page with capchta validations please.. I need this type of form