tomcat 7 Form based authentification

我只是一个虾纸丫 提交于 2019-11-30 22:38:13

following to proposition of @pd40 I tried the examples/jsp/security/protected/ examples but not in the Eclipse IDE where Tomcat is usually embedded along with the other servers (Glassfish, JBoss, ect..) , rather I started the tomcat server as standalone (in its /bin directory) .. and there it works.

but when it's attemped to run security based Web-application in Tomcat within Eclipse, it failed again, even using the configuration described above.

I don't know if I am right but Web-Application Security is only supported when tomcat runs outside of eclipse..

The tomcat example web.xml includes the following section below <login-config>:

<!-- Security roles referenced by this web application -->
<security-role>
  <role-name>role1</role-name>
</security-role>
<security-role>
  <role-name>tomcat</role-name>
</security-role>

which you may need.


Tomcat includes an example war which contains an auth using tomcat-users.xml similar to what you are trying. If tomcat home/webapps/examples is deployed try accessing http://localhost/examples/jsp/security/protected/. Make sure the XML comments around the role/user section of tomcat-users.xml have been removed. They are commented out by default.

<!-- Un comment me 
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->

You can consider bumping up the logging to help diagnose the auth issue.

This is too late for me to answer but maybe someone coming here may find this useful.

Actually if you are facing the problem of not getting the tomcat configuration to work through eclipse and running outside it, then just delete the server from eclipse servers tab and add again. This should solve the problem.

You have restricted access to your content by defining secured pages in web.xml:

<url-pattern>/*</url-pattern>

that wildcard is refering to all pages in content path. So you obtain an infinitive loop of redirections to login page.

I discovered that if you change the configuration of users in the tomcat-users.xml that is embedded in eclipse you must restart eclipse not just the server for the new users to be recognised. I guess that eclipse caches the tomact-user.xml file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!