Saturday, September 24, 2011

Troubleshooting User log-in and organization relationship

CommerceSrvr E AccManager isAllowed CMN1501E: User 6002 does not have the authority to perform action "Display" on resource "com.ibm.commerce.user.beans.UserDataBean" for command "Logon".
 CommerceSrvr A DataBeanManager directActivate(DataBean,CommandContext) The user does not have the authority to run this command "com.ibm.commerce.user.beans.UserRegistrationDataBean".
t have the authority to perform action "Display" on resource "com.ibm.commerce.user.beans.OrganizationDataBean"

Troubleshooting: The above error was caused as there was a missing relationship in MBRREL to the parent organization.

DN should be lowercase and no spaces between orgs.

If you have Manually imported orgentity table through data load, The DN relationship is stored between the ancestor and descendant in MBRREL. If the tree has multiple parents, all the parent-child relationship should be defined in MBRREL.

A member_id from MEMBER table can be a ORGENTITY_ID, USERS_ID,MBRGRP_ID

 Some queries to help for debugging:

select * from mbrrel where descendant_id=;


select * from orgentity where orgentity_id in (
select ancestor_id from mbrrel where descendant_id=);



USERS:

 MBRREL; ( USER to all parent organization relationship as per dn is loaded here)

MBRROLE & ROLE; (Role for each user is assigned to an organization, e.g. -29 for registered customer)

SELECT DN FROM USERS (DN SHOULD BE THE CORRECT ORGENTITY)


Wednesday, September 21, 2011

Retrieving WCParam value from scriptlet



Using JSPHelper to retrieve WCParam values:

JSTL:
wcparam value AdddressId:<c:out value="${WCParam.addressId}"/>

 above example using JSP Scriptlet:
<%@ page import="com.ibm.commerce.server.JSPHelper" %>

<%
String addressId=(String)com.ibm.commerce.server.JSPHelper.getParameter(request, "addressId") ;
System.out.println("addressId: "+addressId);
 %>


<%
CommandContext jstlCommandContext = (CommandContext)request.getAttribute(ECConstants.EC_COMMANDCONTEXT );
System.out.println("JSTLEnvironmentSetup languageId: "+jstlCommandContext.getLanguageId());

 %>


Using PageContext to retrieve session values in a JSP page:

<c:set var="rsOrderId" value="${WCParam.orderId}"/>

System.out.println("RS OrderID: "+pageContext.getAttribute("rsOrderId"));


Sunday, September 11, 2011

Override Access authority from Commands

checkResourcePermission The user does not have the authority to run this command. CMN0410E: The system failed to retrieve the message with  key "_ERR_USER_AUTHORITY" from "com.ibm.commerce.ras.properties.ecServerMessages"
I am sure all of us working in commerce have seen the above error  a million times and some times it is because we didn't correctly define the access privileges when creating a new command and running ACPLoad but some times it is important to override the out of the box access policies.

I would not recommend returning plain null but also find below some more restricted overrides of getResources.


public AccessVector getResources() {
  return null;
}
public AccessVector getResources()
{          final String METHOD_NAME = "getResources";            
            java.util.Vector resourcesVector = new java.util.Vector();
            Long parentOrgId= null;
            UserAccessBean userAccessBean = getCommandContext().getUser();
            Long[] userAncestors = userAccessBean.getAncestors();
            if(userAncestors != null)   {      parentOrgId = userAncestors[0];   }   
            else   {   return null;     }            
            OrganizationAccessBean orgAccessBean = new OrganizationAccessBean();
            orgAccessBean.setInitKey_MemberId(parentOrgId.toString());
            orgAccessBean.refreshCopyHelper();
            resourcesVector.addElement(orgAccessBean.getEJBRef());
            return new AccessVector(resourcesVector);
   }  
public AccessVector getResources()
{     
 final String METHOD_NAME = "getResources";
        resources = new AccessVector();
        try {
            if (resources.isEmpty()) {
                orderId = getRequestProperties().getString(ORDER_ID,
                        null);
                OrderAccessBean orderAccessBean= new OrderAccessBean();
                oab.setInitKey_orderId(orderId);  
                oab.refreshCopyHelper();
                resources.addElement(
orderAccessBean);
            }
    return resources;
}



Saturday, September 3, 2011

Order & Login flow commands

This post was requested in the comments section last week and  I tried to cover if not all, most of the commands in these flows.

Order Flow:
.
Flow
Controller Commands
Task Commands
Add/Update Items to Cart
OrderItemAddCmdImpl
OrderItemUpdateCmdImpl

Display Cart:
OrderItemDisplayCmdImpl
CheckInventoryCmdImpl
OrderItemDeleteCmdImpl
DoInventoryActionCmdImpl
Checkout/
Review
OrderPrepareCmdImpl

Submit/Place Order
OrderProcessCmdImpl


Order Calculate Command: OrderCalculateCmdImpl, This command is very heavy and is used for calculations on promotions/taxes/shipping discounts. It could be called from Cart display page and Order checkout page, it depends on the requirements and also on cart merge during login. Make sure this command is called less frequently.

Login/Registration:


Flow
Controller Commands
Registration Add/Update
UserRegistrationAddCmdImpl/
UserRegistrationUpdateCmdImpl

Registration using Admin access
UserRegistrationAdminAddCmdImpl/
UserRegistrationUpdateCmdImpl
Login
LogonCmdImpl
Password Reset
ResetPasswordCmdImpl
Asynchronous event after Password Reset
SendPasswordNotificationCmdImpl
(This one’s a task command)
Log off
LogoffCmdImpl
The Asynchronous event after password reset, there is an event that triggers SendPasswordNotificationCmd.