0
votes

I needed to override portalLDAPImporterImpl.java addUser() method to perform some action after a user is imported from LDAP and added to Liferay. I followed these steps (Eclipse Environment):

  1. Created Ext plugin project name customLdap;
  2. In docroot/WEB-INF/ext-impl/src I created a package name com.liferay.portal.security.ldap
  3. There I create my CustomPortalLDAPImporterImpl.java class extending portalLDAPImporterImpl.java and override the method addUser

Code extract:

    @Override

    protected User addUser(long companyId, LDAPUser ldapUser, String password)
        throws Exception {

    if (_log.isDebugEnabled()) {
        _log.debug("Adding user " + ldapUser.getEmailAddress());
    }

    boolean autoPassword = ldapUser.isAutoPassword();

    if (!PropsValues.LDAP_IMPORT_USER_PASSWORD_ENABLED) {
        autoPassword = PropsValues.LDAP_IMPORT_USER_PASSWORD_AUTOGENERATED
                && !PropsValues.AUTH_PIPELINE_ENABLE_LIFERAY_CHECK;

        if (!autoPassword) {
            String defaultPassword = PropsValues.LDAP_IMPORT_USER_PASSWORD_DEFAULT;

            if (StringUtil.equalsIgnoreCase(defaultPassword,
                    _USER_PASSWORD_SCREEN_NAME)) {

                defaultPassword = ldapUser.getScreenName();
            }

            password = defaultPassword;
        }
    }

    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

    birthdayCal.setTime(ldapUser.getBirthday());

    int birthdayMonth = birthdayCal.get(Calendar.MONTH);
    int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
    int birthdayYear = birthdayCal.get(Calendar.YEAR);

    User user = UserLocalServiceUtil.addUser(ldapUser.getCreatorUserId(),
            companyId, autoPassword, password, password,
            ldapUser.isAutoScreenName(), ldapUser.getScreenName(),
            ldapUser.getEmailAddress(), 0, StringPool.BLANK,
            ldapUser.getLocale(), ldapUser.getFirstName(),
            ldapUser.getMiddleName(), ldapUser.getLastName(), 0, 0,
            ldapUser.isMale(), birthdayMonth, birthdayDay, birthdayYear,
            StringPool.BLANK, ldapUser.getGroupIds(),
            ldapUser.getOrganizationIds(), ldapUser.getRoleIds(),
            ldapUser.getUserGroupIds(), ldapUser.isSendEmail(),
            ldapUser.getServiceContext());
    _log.info("-----------------------------------------User||||Added----------------------------------------");

    if (ldapUser.isUpdatePortrait()) {
        byte[] portraitBytes = ldapUser.getPortraitBytes();

        if (ArrayUtil.isNotEmpty(portraitBytes)) {
            user = UserLocalServiceUtil.updatePortrait(user.getUserId(),
                    portraitBytes);
        }
    }

    return user;
}
  1. Created folder name META-INF in docroot/WEB-INF/ext-impl/src

  2. In META-INF created a file named ext-spring.xml with the following code:

enter image description here

  1. build and published my plugin
  2. copied the customLdap-ext.war file from dist folder and pasted it in my Tomcat deploy folder
  3. started my server the old configuration are loaded no log is printed while a new user is imported from ldap

Where am I going wrong in doing this?

Note: I am using liferay 6.2.0.1 CE-GA6

2
6.2.0.1 CE-GA6? Where did you get that - from original sources it doesn't exist. 6.2.5 would be the version matching "GA6", 6.2.0 is GA1. I've never heard of 6.2.0.1Olaf Kock

2 Answers

1
votes

I have also overriden PortalLDAPImporterImpl.java. You don't have to define ext-spring.xml. Just take the original class, copy it to docroot/WEB-INF/ext-impl/src in package com.liferay.portal.security.ldap and change it. Do not create CustomPortalLDAPImporterImpl.java

0
votes

Something in your description doesn't sound right - specifically the combination of an ext-plugin and

  1. build and pusblished my plugin
  2. copied the customLdap-ext.war file from dist folder and pasted it in my tomcat delpoy folder

While this is documented as the steps to deploy in production, you'll at least need to restart Liferay (ext is not hot-deployable).

Also, validate that the WAR file doesn't end up as a separate webapplication in tomcat. Instead it will be woven into Liferay, aka the ROOT web application. This is another thing that you can/should validate. And observe the documented steps for redeployment (different from first deployment), where you basically need to reinstall Liferay from scratch and your ext plugins.

I haven't validated if you can go without ext here, the documented steps are a prime reason to try to go without ext whenever possible.

If you follow Klimiuk's advice in the other answer to this question, note that you're depending on classloader order in that case: Some JVMs/appservers will pick up your implementation first, while others pick up the original one first. It's typically reproducible - e.g. if it works once, it'll always work. At least until an update to your environment changes the behavior any you suddenly wonder why your modification doesn't work any more (if you're lucky to find out quickly).