2017-08-30 37 views
0

我需要覆蓋portalLDAPImporterImpl.javaaddUser()方法以在從LDAP導入用戶並將其添加到Liferay後執行某些操作。我遵循這些步驟(Eclipse環境):通過ext插件對源代碼進行的Liferay更改不會發生

  1. 創建Ext插件項目名稱customLdap;
  2. 文檔根目錄/ WEB-INF/EXT-IMPL/src目錄我創建了一個包名com.liferay.portal.security.ldap
  3. 在那裏,我創造我CustomPortalLDAPImporterImpl.java類擴展portalLDAPImporterImpl。的java並重寫方法ADDUSER

代碼提取物:

@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; 
} 
  • 創建文件夾名稱META-INF文檔根/ WEB-INF/EXT-IMPL/SRC

  • META-INF創建的文件命名爲EXT-spring.xml用下面的代碼:

  • enter image description here

  • 構建和發佈我的插件
  • 複製從DIST文件夾中的customLdap-ext.war文件,並在我的Tomcat粘貼它部署文件夾
  • 開始了我的服務器的舊配置加載任何日誌打印而新用戶從進口ldap
  • 我在哪裏做錯了?

    注:我使用的Liferay 6.2.0.1 CE-GA6

    +0

    6.2.0.1 CE-GA6?你從哪裏得到的 - 從原始資料來看,它不存在。 6.2.5將是匹配「GA6」的版本,6.2.0是GA1。我從來沒有聽說過6.2.0.1 –

    回答

    1

    我也重寫PortalLDAPImporterImpl.java。您不必定義ext-spring.xml。只需參加原班級,將其複製到docroot/WEB-INF/ext-impl/src的包com.liferay.portal.security.ldap並更改它。不要在你的描述中創建CustomPortalLDAPImporterImpl.java

    +0

    確實如你所說,但仍然沒有反映出 –

    +0

    而在ext部署後,你重新啓動服務器?還取消部署並刪除舊分機的剩菜。 –

    +0

    我也是這樣做的 –

    0

    東西不健全的權利 - 一個Ext-插件的具體組合和

  • 構建和pusblished我的插件
  • 複製從DIST文件夾中的customLdap-ext.war文件,並在我的tomcat粘貼它delpoy文件夾
  • 雖然這是documented as the steps to deploy in production,你至少需要重新啓動Liferay(ext不可熱部署)。

    此外,驗證WAR文件不是最終作爲tomcat中的一個單獨的web應用程序。相反,它將被編織成Liferay,即ROOT Web應用程序。這是你可以/應該驗證的另一件事。並觀察記錄的重新部署步驟(與第一次部署不同),您基本上需要重新安裝Liferay和您的ext插件。

    我還沒有驗證,如果你可以不用在這裏分機,記錄的步驟是儘可能沒有分機就去的主要原因。

    如果您在此問題的其他答案中關注Klimiuk的建議,請注意您在此情況下依賴於類加載器順序:有些JVM/appservers會首先獲取您的實現,而另一些則會首先獲取原始實現。它通常具有可再現性 - 例如如果它工作一次,它會一直工作。至少在你的環境更新改變行爲之前,你突然想知道爲什麼你的修改不再有效(如果你很幸運能迅速找到答案)。

    相關問題