简体   繁体   English

如何拒绝直接访问Jetty上的文件

[英]How to deny direct url access to files on Jetty

I'm running webapps on Jetty. 我在Jetty上运行webapp。 I have set "dirAllowed" to "false" to disable the directory browsing on the defined contextpath by webAppContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"). 我已将“ dirAllowed”设置为“ false”,以禁用通过webAppContext.setInitParameter(“ org.eclipse.jetty.servlet.Default.dirAllowed”,“ false”)在定义的上下文路径上进行目录浏览。

But, users can still access other files (not located on the contextpath) through url (eg. http://somehost.yahoo.com:8081/abc.xml ) and abc.xml is located under the root directory of the Jetty server. 但是,用户仍然可以通过url(例如http://somehost.yahoo.com:8081/abc.xml )访问其他文件(不在上下文路径中),并且abc.xml位于Jetty服务器的根目录下。

Is there a way to block/deny direct url access to files located on Jetty? 有没有一种方法可以阻止/拒绝直接访问位于Jetty上的文件的URL? Thanks! 谢谢!

Not without adding some functionality to your webapp, there isn't. 并非没有在Web应用程序中添加某些功能,而是没有。 A Java Webapp is essentially a standardized directory structure beginning at the context root (myWebApp in the sample below). Java Webapp本质上是从上下文根(以下示例中的myWebApp)开始的标准化目录结构。

myWebApp/
    index.jsp
    styles/
        mywebapp.css
    images/
        myimage.png
    WEB-INF/
        web.xml
        lib/
            MyLib.jar
        classes/
            MyPackage/
                MyServlet.class

Anything above WEB-INF is directly serve-able, anything below WEB-INF isn't. WEB-INF之上的任何内容都可以直接使用,WEB-INF之下的任何内容都不能直接使用。 You could dream up some authorization scheme using Servlet Filters ( http://www.oracle.com/technetwork/java/filters-137243.html ) and restrict access to content above WEB-INF. 您可以使用Servlet过滤器( http://www.oracle.com/technetwork/java/filters-137243.html )制定一些授权方案,并限制对WEB-INF之上内容的访问。 Alternatively, if Authentication/Authorization is what you are after, look into Http Authorization and how it can be implemented in Jetty ( http://www.eclipse.org/jetty/documentation/current/configuring-security-authentication.html ). 另外,如果您需要认证/授权,请查看Http授权以及如何在Jetty中实现它( http://www.eclipse.org/jetty/documentation/current/configuring-security-authentication.html )。 One way or another, you are going to be some coding or configuration to restrict access to the content above WEB-INF in a Java webapp. 一种或另一种方式,您将需要进行某种编码或配置,以限制对Java Webapp中WEB-INF上方内容的访问。

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

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