Legacy Knowledge Base
Published Jun. 30, 2025

Checking Commerce Permissions in Fragments Always Returns True

Written By

Balázs Létai

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • When using Freemarker variables userPermission and permissionChecker in a fragment to check if a user has specific permissions for their commerce account, the check always returns true, even for non-existent permissions.
<#assign userPermission = serviceLocator.findService("com.liferay.portal.kernel.service.permission.UserPermission")>
<#assign permissionChecker = serviceLocator.findService("com.liferay.portal.kernel.security.permission.PermissionCheckerFactory").create(user)>

${user.screenName}
userPermission:${userPermission}
permissionChecker:${permissionChecker}
VIEW_OPEN_COMMERCE_ORDERS: ${userPermission.contains(permissionChecker, user.userId, "VIEW_OPEN_COMMERCE_ORDERS")?c}
ADD_COMMERCE_ORDER: ${userPermission.contains(permissionChecker, user.userId, "ADD_COMMERCE_ORDER")?c}
MANAGE_USERS: ${userPermission.contains(permissionChecker, user.userId, "MANAGE_USERS")?c}
NOT_FOUND_PERMISSION_0987654321: ${userPermission.contains(permissionChecker, user.userId, "NOT_FOUND_PERMISSION_0987654321")?c}

Environment

  • Liferay DXP 7.4+

Resolution

This approach is not feasible due to the following reasons:

  • The VIEW_OPEN_COMMERCE_ORDER and ADD_COMMERCE_ORDER permissions are portlet permissions, not user permissions. They require a specific target (not available in the fragment template) and the accountId (or the related groupId) to determine permission status.
  • The MANAGE_USERS permission is an account entry permission, not a user permission. It requires the accountId to determine permission status.
  • Checking for non-existent permissions returns true because the code checks if the user has permission on themselves (using user.userId as the target). There is a logic that if you check some permission on yourself it is always true.

 

Did this article resolve your issue ?

Legacy Knowledge Base