【发布时间】:2018-02-08 07:24:22
【问题描述】:
我需要覆盖portalLDAPImporterImpl.java addUser() 方法以在用户从LDAP 导入并添加到Liferay 后执行一些操作。我按照以下步骤(Eclipse 环境):
- 已创建 Ext 插件项目名称 customLdap;
- 在 docroot/WEB-INF/ext-impl/src 我创建了一个包名 com.liferay.portal.security.ldap
- 在那里我创建了我的 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;
}
在 docroot/WEB-INF/ext-impl/src
中创建文件夹名称 META-INF
在 META-INF 中创建了一个名为 ext-spring.xml 的文件,代码如下:
- 构建并发布我的插件
- 从 dist 文件夹复制 customLdap-ext.war 文件并将其粘贴到我的 Tomcat 部署文件夹中
- 启动我的服务器,加载旧配置,从 ldap 导入新用户时不打印日志
我在哪里做错了?
注意:我使用的是 liferay 6.2.0.1 CE-GA6
【问题讨论】:
-
6.2.0.1 CE-GA6?你从哪里得到的 - 从原始来源它不存在。 6.2.5 是匹配“GA6”的版本,6.2.0 是 GA1。我从没听说过 6.2.0.1
标签: java ldap liferay liferay-6