Question

How can I ovveride CustomerStateRequestProcessor#resolveAuthenticatedCustomer function in broadleaf?

I tried this:-

@Component("blCustomerStateRequestProcessor")
public class MyCustomerStateRequestProcessor extends
        CustomerStateRequestProcessor {

    @Resource(name = "blCustomerService")
    protected CustomerService customerService;

    @Override
    public Customer resolveAuthenticatedCustomer(Authentication authentication) {
        if (authentication instanceof OpenIDAuthenticationToken) {
            OpenIDAuthenticationToken openIDAuthenticationToken = (OpenIDAuthenticationToken) authentication;
            if (openIDAuthenticationToken.isAuthenticated()) {
                return (Customer) openIDAuthenticationToken.getPrincipal();
            } else {
                return null;
            }
        } else {
            return super.resolveAuthenticatedCustomer(authentication);
        }
    }

}

Added context component scan :-

<context:component-scan base-package="org.broadleafcommerce.common.web.security,com.mycompany.web.request.processor" />

This resulted in :-

 org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'blCustomerStateRequestProcessor' for bean class [org.broadleafcommerce.profile.web.core.security.CustomerStateRequestProcessor] conflicts with existing, non-compatible bean definition of same name and class [com.mycompany.web.request.processor.MyCustomerStateRequestProcessor]

I am trying to overrid resolveAuthenticatedCustomer method for OpenIdAuthenticationToken.

Thanks

Était-ce utile?

La solution

Rather than use component-scanning to redefine the bean, remove that annotation and do it via XML instead.

So your class definition would change to:

public class MyCustomerStateRequestProcessor extends
    CustomerStateRequestProcessor {

    ...

 }

And then in any of your applicationContext.xml files (except for the servlet one) add this:

<bean id="blCustomerStateRequestProcessor" class="com.yourcompany.site.web.MyCustomerStateRequestProcessor" />

Note that this pattern is the same for overriding any Broadleaf-defined beans.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top