Tomcat:绕过指定 IP 地址的基本身份验证
我已经配置 tomcat 进行基本身份验证。 我不希望任何人访问我的 Web 应用程序,但该应用程序正在提供 Web 服务。 所以我想从基本身份验证中绕过特定的IP地址。(该IP不应该需要身份验证。)
tomcat-users.xml:
<tomcat-users>
<user username="user" password="password" roles="user"/>
</tomcat-users>
web.xml:
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>You must enter your login credentials to continue</realm-name>
</login-config>
<security-role>
<description>
The role that is required to log in to the Application
</description>
<role-name>user</role-name>
</security-role>
谢谢, 切坦。
I have configured tomcat for basic authentication.
I do not want anyone to have access to my web application but the app is serving web services.
So I want to bypass a specific ip address from basic authentication.( that ip should not require authentication.)
tomcat-users.xml :
<tomcat-users>
<user username="user" password="password" roles="user"/>
</tomcat-users>
web.xml :
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>You must enter your login credentials to continue</realm-name>
</login-config>
<security-role>
<description>
The role that is required to log in to the Application
</description>
<role-name>user</role-name>
</security-role>
Thanks,
Chetan.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想允许几个 IP 地址并禁止其他所有人,则 远程地址过滤阀正是您所需要的。
如果您希望来自未知 IP 地址的客户端看到基本登录对话框并可以登录,您需要一个自定义
阀门
。RemoteAddrValve
(它的父类RequestFilterValve
是一个很好的起点。看看我以前的答案也是。 ,下面是一个概念验证代码,如果客户端来自受信任的 IP,它会将填充的
Principal
放入Request
中。因此登录模块不会询问密码,否则它不会触及Request
对象,用户可以照常登录。以及
server.xml
的配置示例:If you would like to allow just only a few IP addresses and disallow everybody else the Remote Address Filter Valve is what you need.
If you want that the clients from unknown IP addresses see the basic login dialog and could login you need a custom
Valve
. The source of theRemoteAddrValve
(and it's parent classRequestFilterValve
is a good starting point. Take a look my former answer too.Anyway, below is a proof of concept code. It puts a filled
Principal
to theRequest
if the client is coming from a trusted IP so the login module will not ask for the password. Otherwise it does not touch theRequest
object and the user can log in as usual.And a config example for the
server.xml
: