LRP-614 practice question 2 of 25

In a JSP that includes the tag, the method to check permissions is:

Full set: 144 questions
Answer options
A: permissionChecker.hasPermissionO Correct answer
B: portalUtil.getPermissionChecker().hasPermission()
C: permissionUtil.hasPermission()
D: renderRequest.getPermissionChecker().hasPermission()
Correct Answer:
A. permissionChecker.hasPermissionO
Explanation

The tag makes several implicit scriptlet variables available within a JSP for convenience. One of these is permissionChecker, which is an instance of com.liferay.portal.kernel.security.permission.PermissionChecker. This object is exposed directly to allow for straightforward permission checks. Therefore, the most direct and standard method to check permissions in a JSP after including this tag is by calling the hasPermission() method on the readily available permissionChecker object.

Why Incorrect

B. portalUtil.getPermissionChecker().hasPermission() This is an indirect approach. The portalUtil.getPermissionChecker() static method requires a PortletRequest argument, which is unnecessary when the permissionChecker object is already in scope.
C. permissionUtil.hasPermission() PermissionUtil is not a standard Liferay utility class for invoking permission checks in this manner. The primary API for this is the PermissionChecker interface.
D. renderRequest.getPermissionChecker().hasPermission() While renderRequest is also made available and this call is technically valid, it is less direct than using the permissionChecker object that explicitly provides for this purpose.

References

1. Official Liferay Documentation: The Liferay Portal 6.2 Developer's Guide explains the objects made available by the tag. It lists permissionChecker as one of the key variables available for use in JSPs.

Source: Liferay, Inc. (2013). Liferay Portal 6.2 Developer's Guide. Section: "Accessing Objects from Your Theme", p. 103. It lists the available variables, including themeDisplay, user, and permissionChecker.

2. Liferay Taglib Definition: The implementation of the DefineObjectsTag class in the Liferay Portal source code confirms that it retrieves the PermissionChecker instance from ThemeDisplay and sets it as a page context attribute named permissionChecker.

Source: Liferay Portal 6.1/6.2 Source Code, portal-impl/src/com/liferay/taglib/theme/DefineObjectsTag.java. The doStartTag() method contains the logic: pageContext.setAttribute(WebKeys.PERMISSIONCHECKER, themeDisplay.getPermissionChecker());.

Scroll to Top