Transform LDAP attributes to be properly mapped to Liferay fields
Written By
Daniel Mijarra
How To articles are not official guidelines or officially
supporteddocumentation. They are community-contributed content and may
not alwaysreflect the latest updates to Liferay DXP. We welcome your
feedback toimprove How to articles!
While we make every effort to ensure this Knowledge Base is accurate,
itmay not always reflect the most recent updates or official
guidelines.We appreciate your understanding and encourage you to reach
out with anyfeedback or concerns.
Legacy Article
You are viewing an article from our legacy
"FastTrack"publication program, made available for
informational purposes. Articlesin this program were published without a
requirement for independentediting or verification and are provided
"as is" withoutguarantee.
Before using any information from this article, independently verify
itssuitability for your situation and project.
Issue
- I need to transform some attributes from my LDAP to be properly mapped with the Liferay fields.
Resolution
- We can define mappings from LDAP attributes to Liferay fields in the Liferay LDAP server configuration.
- Usually, these attributes can be mapped one by one from LDAP server to Liferay fields and the values are loaded directly. However, sometimes some values must be transformed to be imported properly.
- You can develop a module, based on the
DefaultAttributesTransformer
class, to create our own AttributesTransformer. Here is an example you can follow to do it:
- Create a new service module (Creating-a-Custom-OSGi-Service).
- Add a new class,
MyOwnAttributesTransformer
, for example.
- Copy the content of
DefaultAttributesTransformer
into your class, like this:
package myownattributestransformer;
import com.liferay.portal.kernel.security.ldap.AttributesTransformer;
import javax.naming.directory.Attributes;
import org.osgi.service.component.annotations.Component;
@Component(immediate = true, property = {"service.ranking:Integer=100"}, service = AttributesTransformer.class)
public class MyOwnAttributesTransformer implements AttributesTransformer {
@Override
public Attributes transformGroup(Attributes attributes) {
System.out.println("MyOwnAttributesTransformer > Here my attributes transformations for groups");
return attributes;
}
@Override
public Attributes transformUser(Attributes attributes) {
System.out.println("MyOwnAttributesTransformer > Here my attributes transformations for users");
return attributes;
}
}
- Define a higher Service Ranking (i.e.
service.ranking:Integer=100
) as the Creating-a-Custom-OSGi-Service article says.
- Add your attributes trasnformations inside of
transformGroup
or transformUser
, as needed.
- Compile and deploy your module.
Did this article resolve your issue ?