Page 1 of 1

About Question enthuware.jwpv6.2.668 :

Posted: Tue Jan 15, 2013 3:48 pm
by gurpreet_asrgndu
not able to understnad the difference between boolean authenticate(HttpServletResponse) and void login(username, password). read the api docs still no help.

You call this method when you get the username and password from the user.my question is suppose i first make call to authenticate. what it will do ? it will send response and will ask the user , username and password depending upon the configured auth mechanism , say BASIC.now when the user supplies username and password how will i fetch them in the servlet and supply to login() method ?

Re: About Question enthuware.jwpv6.2.668 :

Posted: Thu Jan 17, 2013 8:30 pm
by admin
Once you call authenticate(), the code in your servlet will kind of stop right there and the user will get a login dialog. He will have to enter his userid/pwd. If his details are correct, method will return true and the code in your servlet will proceed beyond the call to authenticate(). You don't have to call login again.

The login() method is used when you don't want the login dialog to be shown to the user i.e. when you are not capturing the userid/pwd from the user. There may be a case where your code gets the userid/pwd from somewhere else and you want to use that to check if the user with that userid/pwd is authentic for your realm. OR you have already captured the userid and password in a form along with other parameters.

HTH,
Paul.

Re: About Question enthuware.jwpv6.2.668 :

Posted: Tue Jul 08, 2014 4:34 am
by djoshi24
So in which case to choose login() and when to authenticate() ?

In this particular question why the answer is not the call of authenticate() and is call to login() ?

Re: About Question enthuware.jwpv6.2.668 :

Posted: Tue Jul 08, 2014 5:03 am
by admin
authenticate() is not correct because you can't validate the userid and password yourself. You don't even get the userid and pwd in your code. The container does all that for you. login() is correct because the question requires you to validate a given userid/password yourself. It doesn't ask you to authenticate the user.

HTH,
Paul.

Re: About Question enthuware.jwpv6.2.668 :

Posted: Tue Jul 08, 2014 7:03 am
by djoshi24
admin wrote:authenticate() is not correct because you can't validate the userid and password yourself. You don't even get the userid and pwd in your code. The container does all that for you. login() is correct because the question requires you to validate a given userid/password yourself. It doesn't ask you to authenticate the user.

HTH,
Paul.

Yeah.. I got it. Thank you.