如何在Tomcat中设置远程用户?
可能的重复:
在 Tomcat 中从 HttpServletRequest.getRemoteUser() 获取值,无需修改应用程序
简短版本:如何配置 Tomcat 使用特定名称(例如,“johndoe”
)作为远程用户名?
详细信息:我正在开发一个 Java Web 应用程序,该应用程序将使用 Tomcat 部署到生产环境中。生产服务器配置为在用户到达此应用程序之前提示用户进行身份验证,因此应用程序只需使用类似于 javax.servlet.http.HttpServletRequest 方法 getRemoteUser() 的内容 获取用户名。事实上,这非常有效。它已经被测试过了。
问题是在我的开发计算机上安装此身份验证过程是不切实际的(出于各种原因)。我还想避免仅仅为了适应我的本地测试而在应用程序中添加特殊用途的代码。我认为如果我可以将我想要测试的用户名强制到 Tomcat 的配置中,那将是最好的。然后 getRemoteUser()
每次都会返回 "johndoe"
。当然,在生产中,该用户名不会被强制进入环境,而是会运行实际的身份验证过程。
不过,我不知道如何将该用户名配置到 Tomcat 中。有什么建议吗?
Possible Duplicate:
Getting a value from HttpServletRequest.getRemoteUser() in Tomcat without modifying application
Short version: How can I configure Tomcat to use a specific name (say, "johndoe"
) as the remote user name?
The details: I'm working on a Java web application that will be deployed to production using Tomcat. The production server is configured to prompt the user for authentication before they ever reach this application, so the app will only need to use something like the javax.servlet.http.HttpServletRequest
method getRemoteUser()
to get the user's name. This works very well, in fact. It's already been tested.
The problem is that it's not practical (for various reasons) to install this authentication process on my development machine. I'd also like to avoid adding special-purpose code in the application just to accommodate my local testing. I thought that it would be best if I could just force the username I want to test with into Tomcat's configuration. Then the getRemoteUser()
would return "johndoe"
every time. Of course, in production, that username wouldn't be forced into the environment, the actual authentication process would run instead.
I can't figure out how to configure that username into Tomcat, though. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 HttpServletRequest.getRemoteUser 获取值( )在 Tomcat 中,无需修改应用程序 - 这个答案包含一个
Valve
,它正是执行此操作。它适用于 Tomcat,并在 Tomcat 6 和 Tomcat 7 上进行了测试。在不修改应用程序的情况下从 Tomcat 中的 HttpServletRequest.getRemoteUser() 获取值 - 这是另一个答案也可能有用。它是一个基于文件的领域,也需要一些 Tomcat 服务器配置,但不需要任何编码。
Getting a value from HttpServletRequest.getRemoteUser() in Tomcat without modifying application - This answer contains a
Valve
which does exactly this. It works with Tomcat, tested with Tomcat 6 and Tomcat 7.Getting a value from HttpServletRequest.getRemoteUser() in Tomcat without modifying application - This another answer also could be useful. It's about a file based realm which also requires some Tomcat server configuration but without any coding.
我首先想到的是实现你自己的 Valve 并在运行时修改请求以添加您想要进行身份验证的用户名。
您将仅在开发环境中使用此
Valve
进行测试。The first thing on top of my head is to implement your own Valve and modify the request at runtime to add the user name that you want for the authentication.
You will use this
Valve
only in your development environment for your testing.