【问题标题】:Avoid direct access to static content in webapps避免直接访问 webapps 中的静态内容
【发布时间】:2016-09-25 07:02:08
【问题描述】:

出于安全原因,我已经集成了我的 Spring MVC 应用程序 Shiro。

我所有的网址都可以正常工作,但我有一些可以直接访问的 html 页面。

我如何保护这些页面,这意味着如果用户没有登录到应用程序并尝试打开 html 页面,他们应该被重定向到登录页面。

我在jetty和tomcat服务器上测试过。

码头

http://ip:port - works fine, redirects to login page

http://ip:port/html/ - opens html pages

雄猫

http://localhost:8070/my-app/html/myPage.html - opens html pages

基本上我不想在没有用户登录的情况下直接访问我的静态内容。

我的 html 文件与 Angular 代码集成在一起。是否有任何类型的 servlet 可以从中创建和返回 html。这意味着我将从其他特定位置读取 html,解析并返回 html 作为响应。

html 文件位置 - my-app\html\myPage.html

web.xml中的Shiro设置

filter>
        <filter-name>shiroFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
        <init-param>
            <param-name>targetFilterLifecycle</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>shiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

当我构建战争时,它也会复制 web-inf 之外的图像、html 文件夹。 如何避免使用maven在web-inf之外复制图片、html文件夹

【问题讨论】:

    标签: java html spring servlets shiro


    【解决方案1】:

    您可以通过将它们放在 WEB-INF 文件夹中来避免直接访问页面。

    【讨论】:

    • 当我创建war文件时,它会将我的html文件夹放在web-inf内部和外部,我该如何避免这种情况
    【解决方案2】:

    在 shiro ini 中尝试

    [url]
    
    /*.html = authc
    

    以下您可以使用但仍建议使用 shiro.ini,因为您永远不知道您的应用程序何时增长,并且从 web.xml 执行此操作将难以管理。它还使 web.xml 变胖,这是针对非 spring 的。您显示的配置仅用于 shiro 设置,而不用于保护 url。为了保护 url,您必须以编程方式或从 web.xml 制作它们

    <filter>
        <filter-name>ShiroFilter</filter-name>
        <filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
        <init-param><param-name>config</param-name><param-value>
    
        # INI Config Here
    
        [url]
    
        /*.html = authc
    
    
    
        </param-value></init-param>
    </filter>
    

    【讨论】:

    • 我从 web.xml 添加了我的 shiro url 模式
    猜你喜欢
    • 2015-12-14
    • 2013-09-06
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    相关资源
    最近更新 更多