2010-11-12 170 views
1

我有一个Tomcat 5.5服务器,我在上面部署了一个应用程序。 我有类似的东西http://tocatServer:8088/MyApp 我想通过输入用户名和密码来限制这个地址的用户访问量,但我需要帮助。我知道我必须在web.xml上添加角色,我尝试了但没有成功。 如果可能的话我想给的网址这样 http://username:[email protected]:8088/MyApp 这个网址是从Java Swing应用程序发送从serlet获得许可 感谢在Tomcat 5.5应用程序上配置用户名和密码

回答

2

要限制访问Web应用程序(或文件夹在webapp URL)在Tomcat中:

webapps/MyApp/WEB-INF/web.xml添加

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name> 
      Entire webapp 
     </web-resource-name> 
     <url-pattern>/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>member</role-name> 
    </auth-constraint> 
</security-constraint> 
<login-config> 
    <!-- pay attention: BASIC in insecure, use it only for test, search for a more secure method --> 
    <auth-method>BASIC</auth-method> 
    <realm-name>Text reported when prompting the user for un and pw</realm-name> 
</login-config> 

conf/tomcat-users.xml添加

<role rolename="member"/> 
<user username="bubi" password="bubi" roles="member"/> 

然后重新加载webapp并可能重新启动Tomcat。

来源:O'Reilly's Top Ten Tomcat Configuration Tips - 5. Configuring Basic Authentication

关于第二个问题,我不知道如何去实现它。

相关问题