我正在尝试调用其余API,以便在POST方法上使用/ api / v1 / cart创建购物车。我尝试了无客户ID。但仍面临错误。有配置??任何帮助都会很棒。 下面是jetty服务器的stackrace
访问/ api / v1 / cart时出现问题。原因:
XSRF token mismatch (null). Session may be expired.
-
谢谢, Sneha
答案 0 :(得分:1)
确保您网站的web.xml
,applicationContext-rest-api.xml
已包含在patchConfigLocations
上方 applicationContext-security.xml
的列表中。对于以applicationContext-rest-api.xml
开头的所有路径,blCsrfFilte
排除了/api/
r:
<!-- Set up Spring security for the RESTful API -->
<sec:http pattern="/api/**" create-session="stateless">
<sec:http-basic />
<sec:custom-filter ref="blRestPreSecurityFilterChain" before="CHANNEL_FILTER"/>
<sec:custom-filter ref="blRestCustomerStateFilter" after="REMEMBER_ME_FILTER"/>
<sec:custom-filter ref="blRestPostSecurityFilterChain" after="SWITCH_USER_FILTER"/>
</sec:http>
如果您没有该部分,则Spring Security会将blCsrfFilter放入安全过滤器链中,该安全过滤器链是该站点所必需的,但应在Rest API中排除。来自applicationContext-security.xml:
<sec:http auto-config="false" authentication-manager-ref="blAuthenticationManager" disable-url-rewriting="true">
<!-- We handle session fixation protection ourselves -->
<sec:session-management session-fixation-protection="none" />
<!-- .................................. -->
<!-- Other configuration excluded -->
<!-- .................................. -->
<!-- Specify our custom filters -->
<sec:custom-filter ref="blPreSecurityFilterChain" before="CHANNEL_FILTER"/>
<sec:custom-filter ref="blCsrfFilter" before="FORM_LOGIN_FILTER"/>
<sec:custom-filter ref="blSessionFixationProtectionFilter" before="SESSION_MANAGEMENT_FILTER"/>
<sec:custom-filter ref="blPostSecurityFilterChain" after="SWITCH_USER_FILTER"/>
</sec:http>