org.broadleafcommerce.profile.web.core.security
Class CustomerStateRequestProcessor

java.lang.Object
  extended by org.broadleafcommerce.common.web.AbstractBroadleafWebRequestProcessor
      extended by org.broadleafcommerce.profile.web.core.security.CustomerStateRequestProcessor
All Implemented Interfaces:
BroadleafWebRequestProcessor, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationEventPublisherAware

@Component(value="blCustomerStateRequestProcessor")
public class CustomerStateRequestProcessor
extends AbstractBroadleafWebRequestProcessor
implements org.springframework.context.ApplicationEventPublisherAware

Author:
Phillip Verheyden
See Also:
CustomerStateFilter}

Field Summary
static String ANONYMOUS_CUSTOMER_ID_SESSION_ATTRIBUTE_NAME
           
static String ANONYMOUS_CUSTOMER_SESSION_ATTRIBUTE_NAME
           
static String BLC_RULE_MAP_PARAM
           
protected static String customerRequestAttributeName
           
protected  CustomerService customerService
           
protected  org.springframework.context.ApplicationEventPublisher eventPublisher
           
protected  org.apache.commons.logging.Log logger
          Logger for this class and subclasses
 
Constructor Summary
CustomerStateRequestProcessor()
           
 
Method Summary
static String getAnonymousCustomerIdSessionAttributeName()
          Returns the session attribute to store the anonymous customer ID.
static String getAnonymousCustomerSessionAttributeName()
          Returns the session attribute to store the anonymous customer.
static String getCustomerRequestAttributeName()
          The request-scoped attribute that should store the Customer.
 void process(org.springframework.web.context.request.WebRequest request)
           
 Customer resolveAnonymousCustomer(org.springframework.web.context.request.WebRequest request)
          Implementors can subclass to change how anonymous customers are created.
 Customer resolveAuthenticatedCustomer(org.springframework.security.core.Authentication authentication)
          Subclasses can extend to resolve other types of Authentication tokens
 void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)
           
static void setCustomerRequestAttributeName(String customerRequestAttributeName)
           
 
Methods inherited from class org.broadleafcommerce.common.web.AbstractBroadleafWebRequestProcessor
postProcess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Logger for this class and subclasses


BLC_RULE_MAP_PARAM

public static final String BLC_RULE_MAP_PARAM
See Also:
Constant Field Values

customerService

protected CustomerService customerService

eventPublisher

protected org.springframework.context.ApplicationEventPublisher eventPublisher

customerRequestAttributeName

protected static String customerRequestAttributeName

ANONYMOUS_CUSTOMER_SESSION_ATTRIBUTE_NAME

public static final String ANONYMOUS_CUSTOMER_SESSION_ATTRIBUTE_NAME
See Also:
Constant Field Values

ANONYMOUS_CUSTOMER_ID_SESSION_ATTRIBUTE_NAME

public static final String ANONYMOUS_CUSTOMER_ID_SESSION_ATTRIBUTE_NAME
See Also:
Constant Field Values
Constructor Detail

CustomerStateRequestProcessor

public CustomerStateRequestProcessor()
Method Detail

process

public void process(org.springframework.web.context.request.WebRequest request)
Specified by:
process in interface BroadleafWebRequestProcessor

resolveAuthenticatedCustomer

public Customer resolveAuthenticatedCustomer(org.springframework.security.core.Authentication authentication)
Subclasses can extend to resolve other types of Authentication tokens

Parameters:
authentication -
Returns:

resolveAnonymousCustomer

public Customer resolveAnonymousCustomer(org.springframework.web.context.request.WebRequest request)
Implementors can subclass to change how anonymous customers are created. The intended behavior is as follows: 1. Look for a Customer on the session - If a customer is found in session, keep using the session-based customer - If a customer is not found in session - Look for a customer ID in session - If a customer ID is found in session: Look up the customer in the database - If no there is no customer ID in session (and thus no Customer) 1. Create a new customer 2. Put the newly-created Customer in session

Parameters:
request -
Returns:
See Also:
#getAnonymousCustomerAttributeName()}, #getAnonymousCustomerIdAttributeName()}

getAnonymousCustomerSessionAttributeName

public static String getAnonymousCustomerSessionAttributeName()
Returns the session attribute to store the anonymous customer. Some implementations may wish to have a different anonymous customer instance (and as a result a different cart). The entire Customer should be stored in session ONLY if that Customer has not already been persisted to the database. Once it has been persisted (like once the user has added something to the cart) then #getAnonymousCustomerIdAttributeName() should be used instead.

Returns:
the session attribute for an anonymous Customer that has not been persisted to the database yet

getAnonymousCustomerIdSessionAttributeName

public static String getAnonymousCustomerIdSessionAttributeName()
Returns the session attribute to store the anonymous customer ID. This session attribute should be used to track anonymous customers that have not registered but have state in the database. When users first visit the Broadleaf site, a new Customer is instantiated but is only saved in session and not persisted to the database. However, once that user adds something to the cart, that Customer is now saved in the database and it no longer makes sense to pull back a full Customer object from session, as any session-based Customer will be out of date in regards to Hibernate (specifically with lists). So, once Broadleaf detects that the session-based Customer has been persisted, it should remove the session-based Customer and then utilize just the customer ID from session.

See Also:
CustomerStateRefresher}

setApplicationEventPublisher

public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)
Specified by:
setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware

getCustomerRequestAttributeName

public static String getCustomerRequestAttributeName()
The request-scoped attribute that should store the Customer.
 Customer customer = (Customer) request.getAttribute(CustomerStateRequestProcessor.getCustomerRequestAttributeName());
 //this is equivalent to the above invocation
 Customer customer = CustomerState.getCustomer();
 

Returns:
See Also:
CustomerState}

setCustomerRequestAttributeName

public static void setCustomerRequestAttributeName(String customerRequestAttributeName)


Copyright © 2013. All Rights Reserved.