Liferay Portal provides many features that help users accomplish their tasks. Sometimes, however, you may find it necessary to customize a built-in feature. It’s easy to find an area you want to customize, but it may seem like a daunting task to figure out how to customize it. Liferay Portal was developed for easy customization, meaning it has many extension points you can use to add your own flavor.
There’s a process you can follow that makes finding an extension point a breeze.
- Locate the bundle (module) that provides the functionality you want to change.
- Find the components available in the module.
- Discover the extension points for the components you want to customize.
This tutorial demonstrates finding an extension point. It steps through a simple example that locates an extension point for importing LDAP users. The example includes using Liferay Portal’s Application Manager and Felix Gogo Shell.
Locate the Related Module and Component
First think of words that describe the application behavior you want to change. The right keywords can help you easily track down the desired module and its component. Consider the example for importing LDAP users. Some candidate keywords for finding the component are import, user, and LDAP.
The easiest way to discover the module responsible for a particular Liferay feature is to use the Application Manager. The Application Manager lists app suites and their included modules/components in an easy-to-use interface. It even lists third party apps! You’ll use your keywords to target the applicable component.
Open the App Manager by navigating to Control Panel → Apps → App Manager. The top level lists app suites, independent apps, and independent modules.
Navigate the app suites, apps, and modules, or use Search to find components that might provide your desired extension point. Remember to check for your keywords in element names and descriptions. The keyword LDAP is found in the Liferay Foundation app suite’s list of apps and features. Select the app suite.
Select the LDAP application from the app listing.
The LDAP application only has one module, but typically, applications have more than one module to inspect. Select the Liferay Portal Security LDAP module.
Search through the components, applying your keywords as a guide. Copy the component name you think best fits the functionality you want to customize; you’ll inspect it later using the Gogo shell.
Next, you’ll use the Gogo shell to inspect the component for extension points.
Finding Extension Points in a Component
Once you have the component that relates to the functionality you want to extend, you can use the Gogo shell’s Service Component Runtime (SCR) commands to inspect it. You can execute SCR commands using Liferay Blade CLI or in Gogo shell. This tutorial assumes you’re using the Gogo shell.
Execute the following command:
For the LDAP example component you copied previously, the command would look like this:
The output includes a lot of information. For this exercise, you’re interested in services the component references. They are extension points. For example, here’s the reference for the service that imports LDAP users:
... Reference: LdapUserImporter Interface Name: com.liferay.portal.security.ldap.exportimport.LDAPUserImporter Cardinality: 1..1 Policy: static Policy option: reluctant Reference Scope: bundle ...
LDAPUserImporter is the extension point for customizing the LDAP user import process! If none of the references satisfy what you’re looking for, search other components from the App Manager.
If you plan on overriding the referenced service, you’ll need to understand the reference’s policy and policy option. If the policy is
static and the policy option is
reluctant, binding a new higher ranking service in place of a bound service requires reactivating the component or changing the target. For information on the other policies and policy options, visit the OSGi specification, in particular, sections 112.3.5 and 112.3.6. If you want to learn how to override a component’s service reference, visit the tutorial here.
Important Not all Liferay extension points are available as referenced services. Service references are common in Declarative Services (DS) components, but extension points can be exposed in other ways too. Here’s a brief list of other potential extension points in Liferay Portal:
- Instances of
- Uses of Liferay’s
- Uses of Liferay’s
- Any other component framework or whiteboard implementation (e.g., HTTP, JAX-RS) that supports tracking services; Blueprint, Apache Dependency Manager, etc. could also introduce extension points.
There you have it! In the App Manager, you used keywords to find the module component whose behavior you wanted to change. Then you used Gogo shell to find the component extension point for implementing your customization.