1

Is it possible to configure web.xml to prevent access to a specific context path?

ilovetolearn
  • 2,006
  • 5
  • 33
  • 64
  • 1
    Possible duplicate of [How to configure url mapping in web.xml to restrict access?](http://stackoverflow.com/questions/11259563/how-to-configure-url-mapping-in-web-xml-to-restrict-access) – Pankaj Saboo Oct 03 '15 at 12:58
  • @PankajSaboo No. The context path is the root path of an application, it's not a path within application itself. – BackSlash Oct 03 '15 at 13:00
  • For context path restriction you have to configure the paths web application server – Pankaj Saboo Oct 03 '15 at 13:01
  • http://stackoverflow.com/questions/5224106/tomcat-restrict-access-to-localhost-for-just-one-webapp this links help to do – Pankaj Saboo Oct 03 '15 at 13:08
  • http://stackoverflow.com/questions/5224106/tomcat-restrict-access-to-localhost-for-just-one-webapp http://stackoverflow.com/questions/3381531/tomcat-restrict-access-by-ip-address this links help to do – Pankaj Saboo Oct 03 '15 at 13:09

1 Answers1

1

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> 
Afsin Buyuksarac
  • 298
  • 1
  • 10
  • 2
    You cannot do it within the application itself. The **context path** is not something the application can control. You need to configure the server, not the application. – BackSlash Oct 03 '15 at 13:05