security - 在 Tomcat 5.5 应用程序上配置用户名和密码

标签 security web-applications tomcat web.xml tomcat5.5

我有一个 Tomcat 5.5 服务器,我在上面部署了一个应用程序。 我有这样的东西http://tocatServer:8088/MyApp 我想通过输入用户名和密码来限制用户对该地址的访问,但我需要帮助。我知道我必须在 web.xml 上添加角色,我试过了但没有成功。 如果可能的话,我想像这样发送 URL http://username:password@tocatServer:8088/MyApp 此 url 是从 java swing 应用程序发送的,用于从 serlet 获取许可证 谢谢

最佳答案

在 Tomcat 中限制对 webapp(或 webapp URL 中的文件夹)的访问:

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"/>

然后重新加载 web 应用程序,也可能重新启动 Tomcat。

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

关于第二个问题,我不知道怎么实现。

关于security - 在 Tomcat 5.5 应用程序上配置用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4163414/

相关文章:

java - 如何从 EJB 中获取 Web 资源的路径?

php - 为什么在使用 tomcat 6.0 运行 php 脚本时在浏览器上显示代码

security - 更改 server.xml 中的关闭字后如何停止 tomcat?

html - 最近使用网站截图导致的Firefox信息泄露

Java Spring 多个 ApplicationContext

java - 为什么 webapps 更喜欢/WEB-INF/lib 而不是/META-INF/MANIFEST.MF?

java - 输入中的错误值 - 没有正确的 UTF-8 编码? Tomcat ?

Java/TomCat BaseDao NoInitialContextException 异常

java - RMISecurityManager 与 SecurityManager

java - 在我的机器上更新 JRE 后小程序无法运行