Interface VendorVisibilityHandler

  • All Superinterfaces:
    com.broadleafcommerce.common.extension.data.DataRoutePartitionAware, org.springframework.core.Ordered
    All Known Implementing Classes:
    CatalogDiscriminatedEntityVendorVisibilityHandler

    public interface VendorVisibilityHandler
    extends com.broadleafcommerce.common.extension.data.DataRoutePartitionAware, org.springframework.core.Ordered
    Certain entities can be "vendor discriminated", and may be associated to vendors in a variety of ways. Sometimes the entity may directly have a field describing its vendor association, and sometimes it may be indirectly associated to a vendor through a relationship with another entity.

    For example, in the pricing service, price list entities have a field directly stating which "vendorRef" they are associated with. Price data entities, however, have no such direct field. For price data entities, vendor discrimination implicitly applies through the price list the price data is associated to. Thus, for price data, accessibility would be determined by the set of "price list ids" that are associated with the provided "vendorRefs".

    A VendorVisibilityHandler implementation is responsible for understanding how a particular entity's vendor discrimination is applied and performing key related operations.

    Implementations declare which entities they support via canHandle(Class), and the VendorVisibilityManager will delegate to the first that can handle it.

    Consumers should almost always call on VendorVisibilityManager and not call any of the methods in this interface directly.

    See Also:
    VendorVisibilityManager
    • Field Summary

      • Fields inherited from interface com.broadleafcommerce.common.extension.data.DataRoutePartitionAware

        ALL_MATCH
      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Method Detail

      • canHandle

        boolean canHandle​(Class<?> persistedDomainEntityType)
        Reports whether the handler supports operations on the given type. If supported, the VendorVisibilityManager will delegate to it for various operations.
        Parameters:
        persistedDomainEntityType - the type to check support for
        Returns:
        true if the handler supports operations on the given type, false otherwise
      • isEntityMutableByVendorRestrictions

        boolean isEntityMutableByVendorRestrictions​(Object persistedDomainEntity,
                                                    Set<String> restrictedVendorRefs,
                                                    @Nullable
                                                    ContextInfo contextInfo)
        Given a persistedDomainEntity, report whether that entity is mutable by the given vendor restrictions.

        This is particularly useful to validate whether an entity can be inserted or updated by a vendor-restricted authentication.

        Parameters:
        persistedDomainEntity - the persisted-domain entity to validate mutability for. This is guaranteed to only be an entity for which canHandle(Class) returns true.
        restrictedVendorRefs - the "vendorRef" (typically a vendor ID or code) of all vendors that mutability should be restricted to. Will never be empty.
        contextInfo - context information surrounding sandboxing/multitenant state
        Returns:
        true if the entity is mutable by the given vendor restrictions, false otherwise
        See Also:
        VendorVisibilityManager.isEntityMutableByVendorRestrictions(Object, Set, ContextInfo)
      • createVendorNarrowingFilter

        String createVendorNarrowingFilter​(Set<String> restrictedVendorRefs,
                                           @Nullable
                                           ContextInfo contextInfo)
        For the persisted domain entity type(s) supported by this handler, build a Node filter string that can be used in queries for those entities that restricts results to only include data from the restrictedVendorRefs.

        This is particularly useful to prevent vendor-restricted authentications from accessing data outside of their allowed vendors.

        Note that if there is any caching enabled for queries on the vendor-discriminated entity, the cache key generation must account for the fact that each authentication's restrictions may lead to different query results. See VendorAwareCacheKeyEnhancer for more information.

        Parameters:
        restrictedVendorRefs - the "vendorRef" (typically a vendor ID or code) of all vendors that the results need to be restricted to. Will never be empty.
        contextInfo - context information surrounding sandboxing/multitenant state. Some implementations may inform their filtration decisions with this.
        Returns:
        a Node filter string that can be used to restrict results on supported entity type(s) to only include data from the restrictedVendorRefs. Cannot return null.
        See Also:
        VendorVisibilityManager.createVendorNarrowingFilter(Class, Set, ContextInfo)
      • getAssociatedVendorRef

        @Nullable
        String getAssociatedVendorRef​(Object persistedDomainEntity,
                                      @Nullable
                                      ContextInfo contextInfo)
        Given a persistedDomainEntity, determine what vendor it is associated to (if any).
        Parameters:
        persistedDomainEntity - the persisted-domain entity to determine the vendor association for
        contextInfo - context information surrounding multitenant state
        Returns:
        the vendorRef that the given entity is associated to, or null if not associated to a vendor
        See Also:
        VendorVisibilityManager.getAssociatedVendorRef(Object, ContextInfo)
      • getOrder

        default int getOrder()
        Specified by:
        getOrder in interface org.springframework.core.Ordered