Thanks to @Michal Dudek in the comments below, at around 6:40 the code on the main class should be the below (it is updated on GitHub): Handler handler = new UserExistsHandler(database); handler.setNextHandler(new ValidPasswordHandler(database)) .setNextHandler(new RoleCheckHandler()); AuthService service = new AuthService(handler);
Hi! I have a question. At around 6:40 shouldn't it instead be Handler handler = new UserExistsHandler(database); handler.setNextHandler( new ValidPasswordHandler(database) .setNextHandler(new RoleCheckHandler()) ); After all we're defining a next handler to the UserExistsHandler, which is ValidPasswordHandler, but then we have to set a next Handler to ValidPasswordHandler, not UserExistsHandler. The way your code is, we're just overriding the value of the nextHandler on UserExistsHandler is it not?
Thanks for these clear explanations. I'm actually a programmer several years now (mobile game industry), but where I have been working, we haven't had any strict rules so everybody just implemented things as they saw fit. Now that I'm thinking of moving to another company, I realize I lack some fundamental programming skills and your lessons are quite helpful. Clearer than other tutorials I've seen. Thanks!
Great tutorial! But I think there is a little mistake in the main method in 6:40. Since the 'setNextHandler' method returns the handler that we passed in, so when creating an instance of the AuthService, we pass the last handler from the entire Chain (in this case RoleCheckHandler) to its constructor, so the entire authentication flow doesn't work properly, because it executes only RoleCheckHandler. I guess we should assign UserExistsHandler to the variable 'handler'. Then using this variable, we should set the next handlers using the 'setNextHandler' method, and pass the 'handler' variable to the AuthService constructor. Am I correct?
Very very nice! Well done bro! The code is updated on GitHub, however can't remember what happened at the time and why it figures this way in the video! xD Thanks man :)
Behavioral Patterns are concerned with communication and assignment of responsibilities between objects as the program is running, and the CoR is all about that! It creates several handlers each having a specific responsibility, and the behavior of each handler (execute, pass to next or stop) is determined by the request passed-in by the user at runtime. Hope this answers it!
I realize that this is outside the scope of the video; however, it's poor security protocol to tell a (possibly malicious) user weather or not the username exists. This gives the adversary extra information to use in the attack. If you send, "wrong password" the adversary now knows that the username exists and they should try more passwords. If you just send, "Invalid login information," the adversary doesn't know if the username is wrong or the password is wrong. This is particularly an issue when people reuse passwords and/or usernames (or variants thereof).
When creating an account the user needs an access to the information whether a certain username exists because if it does the user has to use a different one. So this just makes the information already public.
i am sorry but i try to implement your code , i understood everything but this setNextHandler is not right becouse you will always set the last handler in witch case you will have only one handler
Thanks to @Michal Dudek in the comments below, at around 6:40 the code on the main class should be the below (it is updated on GitHub):
Handler handler = new UserExistsHandler(database);
handler.setNextHandler(new ValidPasswordHandler(database))
.setNextHandler(new RoleCheckHandler());
AuthService service = new AuthService(handler);
Hi! I have a question. At around 6:40 shouldn't it instead be
Handler handler = new UserExistsHandler(database);
handler.setNextHandler(
new ValidPasswordHandler(database)
.setNextHandler(new RoleCheckHandler())
);
After all we're defining a next handler to the UserExistsHandler, which is ValidPasswordHandler, but then we have to set a next Handler to ValidPasswordHandler, not UserExistsHandler.
The way your code is, we're just overriding the value of the nextHandler on UserExistsHandler is it not?
@@danielfernandes1 4:35 ;)
you are the greatest man, made a module in university 10x easier, I love you man
Thanks for these clear explanations. I'm actually a programmer several years now (mobile game industry), but where I have been working, we haven't had any strict rules so everybody just implemented things as they saw fit. Now that I'm thinking of moving to another company, I realize I lack some fundamental programming skills and your lessons are quite helpful. Clearer than other tutorials I've seen. Thanks!
I am so glad I can be of help! Good luck with your new role :)
Great tutorial! But I think there is a little mistake in the main method in 6:40. Since the 'setNextHandler' method returns the handler that we passed in, so when creating an instance of the AuthService, we pass the last handler from the entire Chain (in this case RoleCheckHandler) to its constructor, so the entire authentication flow doesn't work properly, because it executes only RoleCheckHandler. I guess we should assign UserExistsHandler to the variable 'handler'. Then using this variable, we should set the next handlers using the 'setNextHandler' method, and pass the 'handler' variable to the AuthService constructor. Am I correct?
Very very nice! Well done bro! The code is updated on GitHub, however can't remember what happened at the time and why it figures this way in the video! xD Thanks man :)
I came here to say this.
I found the same issue, therefore I just declared the Handler at 1 line and chained the other handlers to it at a new one.
Great job! Thank you ❤
These videos are fantastic!
Thanks, for the effort creating those well explained videos and for the well choosen examples
nice content bro. I appreciate that !
Great video
It reminds me of the old Linked List in C++ where you had a serf referencing pointer [Node] that points to the Next->Node.
How do you insert, remove or reorder handlers dynamically? Each handler only has a reference to the next one
Thank you for the this amazing videos ! you are the best Sir !
My pleasure! Glad I can be of help :)
thank you
thank you😍😍
Why chain of responsibility is a behaviour design pattern? Plz ans me.
Behavioral Patterns are concerned with communication and assignment of responsibilities between objects as the program is running, and the CoR is all about that! It creates several handlers each having a specific responsibility, and the behavior of each handler (execute, pass to next or stop) is determined by the request passed-in by the user at runtime. Hope this answers it!
I realize that this is outside the scope of the video; however, it's poor security protocol to tell a (possibly malicious) user weather or not the username exists. This gives the adversary extra information to use in the attack. If you send, "wrong password" the adversary now knows that the username exists and they should try more passwords. If you just send, "Invalid login information," the adversary doesn't know if the username is wrong or the password is wrong. This is particularly an issue when people reuse passwords and/or usernames (or variants thereof).
In this video we are trying to focus on explaining and understanding the pattern in question, but yes you are right :)
When creating an account the user needs an access to the information whether a certain username exists because if it does the user has to use a different one. So this just makes the information already public.
i am sorry but i try to implement your code , i understood everything but this setNextHandler is not right becouse you will always set the last handler in witch case you will have only one handler
Yes, there is a pinned comment for it, and it is updated on GitHub :)
@@geekific sorry man , didnt thank you a lot for this tutorial 😁
pesu students thumbs up if here
# 1 night before isa
Hames Gosling