About Question enthuware.jwpv6.2.668 :

Moderator: admin

Post Reply
gurpreet_asrgndu
Posts: 55
Joined: Thu Jan 03, 2013 7:51 am
Contact:

About Question enthuware.jwpv6.2.668 :

Post 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 ?

admin
Site Admin
Posts: 8858
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.668 :

Post 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.
If you like our products and services, please help us by posting your review here.

djoshi24
Posts: 5
Joined: Tue Jul 08, 2014 4:27 am
Contact:

Re: About Question enthuware.jwpv6.2.668 :

Post 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() ?

admin
Site Admin
Posts: 8858
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.668 :

Post 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.
If you like our products and services, please help us by posting your review here.

djoshi24
Posts: 5
Joined: Tue Jul 08, 2014 4:27 am
Contact:

Re: About Question enthuware.jwpv6.2.668 :

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest