• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Studying HeadFirst book: cannot make authentification

 
Dmitry Zhuravlev
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone!

I'm studying Servlets/JSP using famous HeadFirst book and now in the chapter about Authentication. The problem is that I cannot login to my web app. I dont know why. I use FORM authentication method and I have created the login form. But when I enter username and password nothing going on. It just redirects me to the error login page. I am using the login and password from tomcat-users.xml:


Exactly the same situation was when I was trying to use BASIC authentication method, except that it was not redirecting me to error page, but showing password dialog again. What should I do to fix this? I have forgotten to implement something, I guess....
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the security configuration that you are using in your web.xml...
 
Dmitry Zhuravlev
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sure.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you also show loginpage.html, and also which url you are accessing ?
 
Rajeev Rnair
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi, Since you have added <transport-guarantee> as CONFIDENTIAL, after login page container will redirect to an https page. If you haven't configured https in tomcat, it may redirect to login-error page. Please comment the <user-data-constraint> and see if it works!

 
Dmitry Zhuravlev
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe,
its simple:

But authentication doesn't work even if I use the BASIC type.

Rajeev,
unfortunately this doesn't help
 
Rajeev Rnair
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dmitry, when you change <auth-method> to BASIC, are you getting the default tomcat login page? If so, what happens when you submit?
Also please show the URL you are trying to access.

Thanks,
 
Dmitry Zhuravlev
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajeev, here are some news:

I am using NetBeans IDE under which my tomcat runs. It turned out that there is a SECOND tomcat-users.xml file located in my documents/netbeans/... folder. And it really works. I have added my users and roles to that file and now BASIC authentication WORKS! But FORM authentication still redirects me to the error page

I try to reach MYAPPNAME/newform.html

When I am using BASIC authentocation (which now works) I see a standart javascript dialog for entering login/password in Firefox and much more goodlooking Windows7 login screen dialog in IE.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2419
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dmitry,

You have identified the correct tomcat-users.xml.

Have you tried accessing the login page directly like:
MYAPPNAME/loginpage.html

Is that possible?

Regards,
Frits
 
Dmitry Zhuravlev
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits,
yes this is possible. Actually reaching login page never was a problem, but still I cannot login using FORM authentication method.

May be the reason is Netbeans. It has its own account called ide and probably user is logged in automatically while using NetBeans. What usually happens when the user that is logged in tries to log in second time via login form?
 
Rajeev Rnair
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dmitry, could you please deploy your code in a standalone Tomcat (ver 5.5) and see if it makes any difference?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2419
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What usually happens when the user that is logged in tries to log in second time via login form?

Nothing, a user only has to login once.

Does netbeans have an integrated browser? Otherwise try accessing the protected URL via another browser (different user, so should give you the login page). Or maybe netbeans hasn't implemented the FORM authentication... try tomcat as Rajeev was suggesting.

Regards,
Frits
 
Dmitry Zhuravlev
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frits,
actually I am using tomcat, as far as I understand netbeans is just an interface.

OK, I will try to deploy application on server though I was never doing this.. Now I have started the server without Netbeans, and copied my build folder from my documents to webapps. Now I can open every html form in my application, it looks like tomcat is not using my web.xml file. It is set properly: in the webapps/myapp/WEB-INF. What should I do after coping my build files to server webapp folder to deploy my application manually? At the moment my web.xml is out of the game.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2419
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dmitry,

Creating a war file manually is done like this (example from SCWCD Study Guide by David Bridgewater)

Set the classpath to include the servlet.jar of tomcat:
  • set classpath=.;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar

  • Compile your Servlet:
  • javac webcert\ch03\ex0304\MicroPaymentServlet.java -d ..\classes

  • Create a war file:
  • jar cvf0 ex0304.war .

  • Copying the war file to tomcat webapps folder:
  • C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\

  • Start tomcat
  • C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin\tomcat5.exe


  • Regards,
    Frits
     
    Dmitry Zhuravlev
    Ranch Hand
    Posts: 93
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Fixed!!!

    Guys, thank you all for the assistance. The problem was in the loginform file which had different quotas inside because of copy-pasting from the book. I often meet this type of error, I should have been more concentrated. Now I will proceed with the last chapter of the book. Thanks!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic