繁体   English   中英

如何在保护Web请求中使用端口号

[英]How can I use port number in securing web request

我有一些使用Spring安全性并部署在Tomcat7中的Web应用程序。 在tomcat中,有两个连接器(8080、8081)。 我想共享我的应用程序的一部分,并允许访问$ {ip}:8080 / $ {servercontext} / resource之类的请求,并通过此端口保护其余应用程序的安全,即拒绝诸如$ {ip}:8080 / $ { ServerContext中} / otherresource。 但是,必须可以访问$ {ip}:8081 / $ {servercontext} / otherresource之类的请求(8081端口)。

我该怎么做 ?

根据Spring安全性文档 ,您可以在intercept-url标签中使用requires-channel属性:

<http>
  <intercept-url pattern="/resource/**" access="ROLE_USER" requires-channel="https"/>
  <intercept-url pattern="otherresource" access="ROLE_USER" requires-channel="any"/>
  ...
</http>

您还可以注意到,还有一种方法(非特定于Spring),在web.xml中添加以下代码:

<security-constraint>
      <web-resource-collection>
        <web-resource-name>HTTPSOnly Resources</web-resource-name>
        <url-pattern>/resources*</url-pattern>
    </web-resource-collection> 
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint> 
</security-constraint>

这将自动将用户重定向到HTTPS(您需要配置服务器以支持HTTPS,但似乎您已经做到了)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM