简体   繁体   中英

Using web.xml/servlet filters to prevent viewing of specific context path

是否可以配置web.xml以阻止访问特定的上下文路径?

Yes of course you prevent access. Actually grant access with a specific role.

 <security-constraint>
    <web-resource-collection>
      <web-resource-name>DESC_OF_FOLDER</web-resource-name>
      <url-pattern>/users/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>REGISTERED_USER_ROLE</role-name>
    </auth-constraint>
  </security-constraint>

Or with a dummy implementation you can create a filter, filtering specific url pattern then you can just deny any request here.

  <filter> 
    <filter-name>prePost</filter-name>
    <display-name>prePost</display-name>
    <filter-class>com.acme.filter.PrePostFilter</filter-class> 
  </filter> 
  <filter-mapping> 
    <filter-name>prePost</filter-name>
    <url-pattern>/denial</url-pattern> 
  </filter-mapping> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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