Class CartStateFilter

java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.broadleafcommerce.common.web.filter.AbstractIgnorableOncePerRequestFilter
org.broadleafcommerce.core.web.order.security.CartStateFilter
All Implemented Interfaces:
jakarta.servlet.Filter, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.EnvironmentAware, org.springframework.core.env.EnvironmentCapable, org.springframework.core.Ordered, org.springframework.web.context.ServletContextAware

@Component("blCartStateFilter") @ConditionalOnNotAdmin public class CartStateFilter extends AbstractIgnorableOncePerRequestFilter

This filter should be configured after the BroadleafCommerce CustomerStateFilter listener from Spring Security. Retrieves the cart for the current BroadleafCommerce Customer based using the authenticated user OR creates an empty non-modifiable cart and stores it in the request.

This filter is also responsible for establishing a session-wide lock for operations that require a lock, indicated by requestRequiresLock(ServletRequest). By default, this is configured for all POST requests. Requests that are marked as requiring a lock will execute strictly serially as defined by the configured OrderLockManager.

Author:
bpolster, Andre Azzolini (apazzolini)
  • Field Details

    • LOG

      protected static final org.apache.commons.logging.Log LOG
    • cartStateProcessor

      @Autowired @Qualifier("blCartStateRequestProcessor") protected CartStateRequestProcessor cartStateProcessor
    • orderLockManager

      @Autowired @Qualifier("blOrderLockManager") protected OrderLockManager orderLockManager
    • orderService

      @Autowired @Qualifier("blOrderService") protected OrderService orderService
    • excludedOrderLockRequestPatterns

      protected List<String> excludedOrderLockRequestPatterns
  • Constructor Details

    • CartStateFilter

      public CartStateFilter()
  • Method Details

    • doFilterInternalUnlessIgnored

      public void doFilterInternalUnlessIgnored(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException
      Specified by:
      doFilterInternalUnlessIgnored in class AbstractIgnorableOncePerRequestFilter
      Throws:
      IOException
      jakarta.servlet.ServletException
    • requestRequiresLock

      protected boolean requestRequiresLock(jakarta.servlet.ServletRequest req)
      By default, all POST requests that are not matched by the getExcludedOrderLockRequestPatterns() list (using the AntPathRequestMatcher) will be marked as requiring a lock on the Order.
      Parameters:
      req -
      Returns:
      whether or not the current request requires a lock on the order
    • getOrder

      public int getOrder()
    • getExcludedOrderLockRequestPatterns

      public List<String> getExcludedOrderLockRequestPatterns()
    • setExcludedOrderLockRequestPatterns

      public void setExcludedOrderLockRequestPatterns(List<String> excludedOrderLockRequestPatterns)
      This allows you to declaratively set a list of excluded Request Patterns /exclude-me/**
    • getErrorInsteadOfQueue

      protected boolean getErrorInsteadOfQueue()
    • shouldNotFilterErrorDispatch

      protected boolean shouldNotFilterErrorDispatch()
      Overrides:
      shouldNotFilterErrorDispatch in class org.springframework.web.filter.OncePerRequestFilter