500 несоответствие токена XSRF (ноль). Сессия может быть истек

Я пытаюсь вызвать остальные API для создания корзины с /api/v1/cart методом POST. Я пытался с и без идентификатора клиента. Но все еще сталкиваюсь с ошибкой. Есть ли быть настроенным?? Любая помощь будет отличной. Ниже приведено описание стека сервера

HTTP ERROR 500

Проблема с доступом к /api/v1/cart. Причина:

 Несоответствие токена XSRF (ноль). Сессия может быть истек. 

Вызванный:

org.broadleafcommerce.common.exception.ServiceException: несоответствие маркера XSRF (пусто). Сессия может быть истек. по адресу org.broadleafcommerce.common.security.service.ExploitProtectionServiceImpl.compareToken(ExploitProtectionServiceImpl.java:122) по адресу org.broadleafcommerce.common.security.handler.CsrfFilter.doFilter(Csrf.f..FilterChainProxy. (FilterChainProxy.java:342) в org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) в org.springframework.security.web.FilterChainFoxFinFoxFoxFoxShaFF org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144) в org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterJhainProxy). по адресу org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) по адресу org.broadleafcommerce.common.web.filter.EstablishSessionFilter.doFilter(EstablishSessionFilter.wework.pr.FilterChainProxy.:107) в org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) в org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChain19.serg.rag.rag.web.FilterChainProxy.doFilter(FilterChainProxy.java:166) в org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) в org.springframework.FilterCweb.web. oFilterInternal(FilterChainProxy.java:192) по адресу org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) по адресу org.springframework.web.filter.DelegatingFilterProxy.invoing.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) в org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1302) в com.anvayin.webapp.CustomCORSFilter.doFilter(CustomCORSFilter.java:38) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1302) в org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncoding:pr.f).Orf. filter.OncePerRequestFilter. 448) на org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131) в org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524) в org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.j: SessionHandler.j) в org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1067) в org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:377) в org.eclipse.jetion.ser.SessionHandler.doScope(SessionHandler.java:192) в org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1001) в org.eclipse.jetty.server.handler.ScopedHandler.handle (Scoped:129) в org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250) в org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149) в org.eclse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111) в org.eclipse.jetty.server.Server.handle(Server.java:360) в org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454) в org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890) в org.eclipse.jetty.server.AbstractHttpConnectionHear в org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630) в org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230) в org.ynl (AsyncHttpConnection.java:77) в org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:622) в org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannel:nd) в org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603) в org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java.5) бежать (Thread.java:744)

-

Спасибо Снеха

1 ответ

Решение

Убедитесь, что на вашем сайте web.xml, applicationContext-rest-api.xml входит в список patchConfigLocations выше applicationContext-security.xml, Тот applicationContext-rest-api.xml исключает blCsrfFilteт для всех путей, которые начинаются с /api/:

<!-- 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 в цепочку фильтров безопасности, которая требуется для сайта, но должна быть исключена из 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>
Другие вопросы по тегам