Message Boards

Custom attribute transformer for LDAP import

Kostas Ath, modified 4 Years ago.

Custom attribute transformer for LDAP import

New Member Posts: 7 Join Date: 9/18/14 Recent Posts
Hello.I'm currently installing and configuring a site for a client using Liferay CE 7.1.2 ga3. I have successfully imported users from Microsoft AD. One of the required fields to import is the user's status. Statuses in AD are different from those of Liferay. For example status 512 means i have a normal and active account.In order to "translate" the AD status to Liferay status, I have created a service module to implement com.liferay.portal.kernel.security.ldap.AttributesTransformer class and change the status there before the user is stored or updated. However this is not working. I've checked documentation and blade samples but I just can't make it work. Has anyone done something similar before? Any hint would be really helpful.

This is the class I've created.
@Component(
    immediate = true,
    property = {"key=ldap.attrs.transformer.impl"},
    service = AttributesTransformer.class
)
public class OpapIntranetExtTransformer implements AttributesTransformer {    
   @Override
    public Attributes transformGroup(Attributes attributes) {
        .....
    }    @Override
    public Attributes transformUser(Attributes attributes) {
       .....
    }
}
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: Custom attribute transformer for LDAP import

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey Kostas,
I haven't used this feature yet, but looking at the LDAPUserImporterImpl I can see that the service is wired in like so 


@Reference(policy = ReferencePolicy.DYNAMIC,    
           policyOption = ReferencePolicyOption.GREEDY 
) 
private volatile AttributesTransformer _attributesTransformer;


.. so it should pick up new services, but I think in order to make sure that YOUR service is ranked higher than the out of the box (DefaultAttributesTransformer), you might have to include a service.ranking:Integer=100 property in your component properities map

@Component(
    immediate = true,
    property = {
            "key=ldap.attrs.transformer.impl",
            "service.ranking:Integer=100"
    },
    service = AttributesTransformer.class
)


Can you try that out and let me know if it helps?
Kostas Ath, modified 4 Years ago.

RE: Custom attribute transformer for LDAP import

New Member Posts: 7 Join Date: 9/18/14 Recent Posts
Thank you very much!! It worked like a charm.
thumbnail
Andrew Jardine, modified 4 Years ago.

RE: Custom attribute transformer for LDAP import

Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Sweet -- gonna archive that one away on my side as well as I am sure that it will come in handy one day!Also note that YOU MIGHT have been able to get away without the service ranking if you deployed your module and restarted your server.  HOWEVER, this is a gamble because if Liferay loaded it's implementation first (which, being in PortalImpl I would probably assume it does) then it would wire the Default class. If by chance yours had loaded first though, then it would have picked up yours without the service ranking.  Just a little extra info in case you ever up in that scenario as it looks like a "bug" but it's not -- and the first time I came across it? almost cost me a head of hair emoticon