LRP-614 practice question 8 of 25

The recommended way to validate a user against an external system when adding a user through the UI or a web service is to:

Full set: 144 questions
Answer options
A: Create a hook plug in to add a model listener to the User object
B: Create a service wrapper hook that modifies the User service Correct answer
C: Create a Struts action hook to perform validation when the user form is submitted
D: Create an Ext plugin to modify the core Spring configuration to override the User service
Correct Answer:
B. Create a service wrapper hook that modifies the User service
Explanation

The recommended approach is to create a service wrapper hook. This method intercepts calls to Liferay's core services, such as UserService. Since both the user interface (Control Panel) and web service endpoints ultimately invoke the UserService to add or update users, placing validation logic in a service wrapper ensures it is executed regardless of the entry point. This centralized approach is robust, maintainable, and aligns with Liferay's recommended development practices for modifying business logic. By wrapping the addUser or updateUser methods, you can perform the external validation before the original Liferay logic is executed.

Why Incorrect

A. A model listener acts at the persistence layer, just before the object is saved to the database. While it can be used for validation, the service layer is the more appropriate location for business logic.
C. A Struts action hook is specific to the UI layer. It would not be triggered when a user is created via a web service call, thus failing to meet the full requirements of the question.
D. An Ext plugin is a legacy and highly invasive method for customization. Liferay strongly recommends using hooks over Ext plugins due to their complexity and maintenance overhead.

References

1. Liferay Portal 6.2 Developer's Guide: In the "Hooks" chapter, the section "Overriding a Service with a Hook" describes using service wrappers to add custom logic. It states, "You can add custom logic before or after a call to any of Liferay’s services... For example, you could add a custom validation check to the addUser method of the User service." This directly supports using a service wrapper for validation that applies to all service callers. (See Chapter 7: Hooks -> Overriding a Service with a Hook).

2. Liferay University Courseware (LRP-614): The official training materials for the LRP-614 exam emphasize hooks as the primary mechanism for customization. The module on hooks explicitly contrasts the different types, highlighting that Struts action hooks are for the presentation layer, while service wrappers modify the business logic layer, making them suitable for universal validation logic. (See Module: Liferay Customization, Section: Hooks).

Scroll to Top