在 Tomcat 中从 HttpServletRequest.getRemoteUser() 获取值而不修改应用程序
(使用Java 6和Tomcat 6。)
有没有办法让我在我的开发环境(即本地主机)中让HttpServletRequest.getRemoteUser()
返回一个值,而无需修改我的应用程序的web.xml文件?
我问的原因是应用程序部署到远程环境时的身份验证实现是由 Web 服务器和插件工具处理的。在本地运行我显然没有插件工具或单独的网络服务器;我只有 Tomcat 6。我试图避免仅仅为了支持本地主机上的开发而向我的应用程序添加代码。
我希望可以对 context.xml 或 server.xml 文件进行修改,让我设置远程用户 ID,或者尝试从 HTTP 标头或其他内容中提取它。
(Using Java 6 and Tomcat 6.)
Is there a way for me to get HttpServletRequest.getRemoteUser()
to return a value in my development environment (i.e. localhost) without needing to modify my application's web.xml file?
The reason I ask is that the authentication implementation when the app is deployed to a remote environment is handled by a web server and plugged-in tool. Running locally I obviously do not have the plugged-in tool or a separate web server; I just have Tomcat 6. I am trying to avoid adding code to my application merely to support development on my localhost.
I am hoping there is a modification I can make to the context.xml or server.xml files that will let me set the remote user ID or that will try to pull it from a HTTP header or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是一个概念验证
Valve
实现:(使用 Tomcat 7.0.21 进行测试。)
编译它,将其放入 jar 中并将该 jar 复制到
apache-tomcat-7.0 .21/lib
文件夹。您需要修改server.xml
:我想它也可以在
Engine
和Context
容器内工作。更多信息:
Here is a proof of concept
Valve
implementation which does it:(Tested with Tomcat 7.0.21.)
Compile it, put it inside a jar and copy the jar to the
apache-tomcat-7.0.21/lib
folder. You need to modify theserver.xml
:I suppose it works inside the
Engine
andContext
containers too.More information:
使用本地、基于文件的领域进行测试。检查您的
conf/tomcat-users.xml
并为您的应用程序创建角色和用户,并在 web.xml 中启用安全约束。tomcat-users.xml
中有很好的示例。Use a local, file-based realm for testing. Check your
conf/tomcat-users.xml
and create roles and users for your application and enable the security constraints in your web.xml. There are good examples in thetomcat-users.xml
.