Add a new relationship to an existing WebSphere Commerce entity bean

WebSphere Commerce entity beans that implement the Protectable interface are already protected under access control. The terms of the access control requirements are determined by the way that the bean is used in the out-of-the-box features and functions of WebSphere Commerce. You may encounter situations in which you need to add additional relationships to access control for such beans. For example, if we use an existing bean in some of our customized code, or if you modify an existing WebSphere Commerce public entity bean, you may need to add additional relationships to the bean.


Task info

The following list provides the high-level steps to add new relationships to an existing WebSphere Commerce entity bean that is already protected by access control:


Procedure

  1. Examine the existing fulfills method for the entity bean. This is located in the bean's access helper class. Do not modify this class, use it only to determine if you need to add one or more new relationships to this logic, or if you need to override this method. For example, the following fulfills method appears in the com.ibm.commerce.fulfillment.objsrc.FulfillmentCenterBeanAccessHelper class:

      public boolean fulfills(Object obj, Long member, String relationship) 
       throws Exception {
      
              FulfillmentCenterBean bean = (FulfillmentCenterBean) obj;
              
              if ("ShippingArrangementOrganizationalEntity".
       equalsIgnoreCase(relationship))
              {
        FulfillmentJDBCHelperAccessBean ffmJDBCAB = 
         new FulfillmentJDBCHelperAccessBean();
        int count = ffmJDBCAB.
         checkFulfillmentCenterByMemberIdAndFulfillmentCenterId(
         member,bean.getFulfillmentCenterId());
        if(count>0) 
         return true;
              }
              return false;
      }

  2. The next step is to create a new fulfills method in the bean class. For example, you could create a new fulfills method in the com.ibm.commerce.fulfillment.objects.FulfillmentBean.java class. The declaration for the method should appear as:

      public boolean fulfills(Long member, String relationship) 
       throws Exception {
        // Place holder for relationship information
              }

  3. If we are adding an additional relationship to the existing relationships, the first line in your method should be to call the fulfills method from the superclass. Then, if that method returns false, then check for our new relationships, as follows:

      public boolean fulfills(Long member, String relationship) 
       throws Exception {
        if (super.fulfills().equals(false))
        {
         // Check if new relationship is met
         return true;
        }
      
        return false;
              }

  4. If we are replacing the relationships from the original implementation entirely, you should not call the super.fulfills method, as follows:

      public boolean fulfills(Long member, String relationship) 
       throws Exception {
        // Check if new relationship is met
        // If it is, then return true;
        
        // If the relationship is not met, return false;
              }

  5. Save our changes. Regenerate the deployed and RMIC code for the bean, as well as the corresponding access bean.


Related concepts
Access control implications when a controller command is extended