栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Security 3.2 CSRF对多部分请求的支持

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Security 3.2 CSRF对多部分请求的支持

我能够在Spring Security团队的帮助下解决此问题。我已经更新了要点,以反映有效的配置。我必须按照下面给出的步骤进行操作,以使所有功能都能按预期工作。

1.常用步骤

添加一个

MultipartFilter
web.xml
以确保在Spring Security配置之前添加它:

<filter>    <display-name>springMultipartFilter</display-name>    <filter-name>springMultipartFilter</filter-name>    <filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class></filter><filter-mapping>    <filter-name>springMultipartFilter</filter-name>    <url-pattern>/*</url-pattern></filter-mapping><filter>    <display-name>springSecurityFilterChain</display-name>    <filter-name>springSecurityFilterChain</filter-name>    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class></filter><filter-mapping>    <filter-name>springSecurityFilterChain</filter-name>    <url-pattern>/*</url-pattern>    <dispatcher>ERROR</dispatcher>    <dispatcher>FORWARD</dispatcher>    <dispatcher>REQUEST</dispatcher></filter-mapping>

2.1。使用Apache Commons Multipart解析器

确保

filterMultipartResolver
在根Spring应用程序上下文中有一个名为Apache Commons Multipart Resolver的bean 。我将再次强调这一点,确保在Spring Spring根目录(通常称为applicationContext.xml)中声明了Multipart Resolver。例如,

web.xml

<context-param>    <param-name>contextConfigLocation</param-name>    <param-value>        classpath*:springWebMultipartContext.xml    </param-value></context-param>

springWebMultipartContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">    <bean id="filterMultipartResolver" >        <property name="maxUploadSize" value="100000000" />    </bean></beans>

确保该Bean称为

filterMultipartResolver
,因为在中未
MultipartFilter
配置任何其他Bean名称web.xml。我的初始配置无法正常工作,因为此bean名为
multipartResolver
。我什至尝试将Bean名称传递给MultipartFilterusing,
web.xml init-param
但这也不起作用。

2.2。使用Tomcat Multipart支持

Tomcat 7.0+具有内置的多部分支持,但必须明确启用它。

context.xml
如下更改全局Tomcat 文件,或
context.xml
在WAR文件中包括本地文件,以使该支持有效,而无需对应用程序进行任何其他更改。

<Context allowCasualMultipartParsing="true">    ...</Context>

在使用Apache Commons Multipart Resolver进行了这些更改之后,到目前为止,我们的应用程序可以在Tomcat,Jetty和Weblogic上运行。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/402493.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号