package org.broadleafcommerce.security;

import javax.servlet.http.HttpServletRequest;

import org.broadleafcommerce.profile.domain.Customer;
import org.springframework.security.context.SecurityContextHolder;

public class CustomerState {

	private final static String CUSTOMER_SESSION_ATTR_NAME = "broadleaf_commerce.customer";

    public static Customer getCustomer(HttpServletRequest request) {
    	return (Customer) request.getSession().getAttribute(CUSTOMER_SESSION_ATTR_NAME);
    }

    public static void setCustomer(Customer customer, HttpServletRequest request) {
        request.getSession().setAttribute(CUSTOMER_SESSION_ATTR_NAME, customer);
    }

    public static boolean isCustomerAuthenticated() {
    	if (SecurityContextHolder.getContext() != null && SecurityContextHolder.getContext().getAuthentication() != null) {
    		return SecurityContextHolder.getContext().getAuthentication().isAuthenticated();
    	}
    	return false;
    }

}

@@ -242,17 +242,20 @@
 te %7B%0D%0A%0D%0A
-%09
+    
 private 
@@ -407,25 +407,28 @@
 est) %7B%0D%0A    
-%09
+    
 return (Cust
@@ -674,32 +674,193 @@
 mer);%0D%0A    %7D%0D%0A%0D%0A
+    public static Long getCustomerId(HttpServletRequest request) %7B%0D%0A        return getCustomer(request) == null ? null : getCustomer(request).getId();%0D%0A    %7D%0D%0A%0D%0A
     public stati
@@ -902,17 +902,20 @@
  %7B%0D%0A    
+ 
-%09
+   
 if (Secu
@@ -1031,10 +1031,16 @@
     
-%09%09
+        
 retu
@@ -1125,17 +1125,23 @@
     
-%09
+    
 %7D%0D%0A    
-%09
+    
 retu

add getCustomerId to CustomerState for convenience