将LDAP属性映射到Liferay用户显示语言

编程入门 行业动态 更新时间:2024-10-28 19:26:40
本文介绍了将LDAP属性映射到Liferay用户显示语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们正在使用Liferay 6.2 GA4,它允许您仅映射LDAP用户导入的一些基本属性: screenName, password, emailAddress, firstName, lastName, jobTitle和group.如果要映射一些自定义字段,则必须使用自定义映射.两种情况都可以正常工作,但是我们真正想要的是将LDAP属性preferredLanguage映射到用户languageId,因此Liferay中的用户语言是基于LDAP值设置的. 我们尝试过的:

We are using Liferay 6.2 GA4, which allows you to map only few basic attributes for LDAP user import: screenName, password, emailAddress, firstName, lastName, jobTitle and group. If you want to map some custom fields you have to use custom mapping. Both cases are working fine but what we really want is to map LDAP attribute preferredLanguage to user languageId so the user language in Liferay is set based on LDAP value. What we have tried:

  • 将preferredLanguage映射到标准ldap.user.mappings中的languageId,因此portalpreferences表条目中的条目如下所示:

  • Map preferredLanguage to languageId in standard ldap.user.mappings so the entry in portalpreferences table entry looks like this:

...<preference> <name>ldap.user.mappings.21597</name> <value>emailAddress=uid[$NEW_LINE$]firstName=givenName[$NEW_LINE$]group=memberOf[$NEW_LINE$]lastName=sn[$NEW_LINE$]languageId=preferredLanguage</value> </preference>...

  • 将其映射到ldap.user.custom.mappings中,因此portalpreferences表条目为:

  • Map it in ldap.user.custom.mappings so portalpreferences table entry is:

    ...<preference> <name>ldap.user.custom.mappings.21597</name> <value>...ourCustomAttributes...[$NEW_LINE$]languageId=preferredLanguage</value> </preference>...

  • 均无效.唯一有效的方法是在Liferay中创建自定义用户字段,例如custLanguage并将preferredLanguage映射到此字段.但是,然后我们不知道如何将值从custLanguage传递给用户显示设置languageId,因此该用户的语言会自动更改. 许多用户在使用Liferay语言LDAP导入时遇到问题,例如 issues.liferay/browse/LPS-23143 .我认为,如果您可以添加languageId来忽略列表,则也可以将其导入.

    Neither works. The only thing what is working is to create custom user field in Liferay e.g. custLanguage and map preferredLanguage to this field. But then we don't know how to pass value from custLanguage to users display settings languageId so the language for that user is changed automatically. Lot of users had problems with Liferay language LDAP import, e.g. issues.liferay/browse/LPS-23143. I assume that if you can add languageId to ignore list you can also import it.

    这个问题与我们的问题相对应,但是解决方案是使用自定义字段,我们不知道如何进一步阐述. 所以我们的问题是:

    This question corresponds with our problem but the solution is to use custom fields and we don't know how to elaborate on it further. So our questions are:

    • 是否可以将我们的自定义LDAP属性preferredLanguage直接映射到Liferay用户的languageId?
    • 如果以上操作无法实现,并且您必须使用自定义属性,我们应该如何将自定义用户语言属性的值传递给他的语言显示设置?
    • Is it possible to map our custom LDAP attribute preferredLanguage directly to languageId of Liferay user?
    • If the above is not possible and you have to use custom attributes how we should pass the value from custom user language attribute to his language display settings?
    推荐答案

    如注释中所述,我发现执行此任务的唯一方法是编写自定义LDAPImporterImpl并将其放入EXT插件中.这是我的代码段:

    As mentioned in comments, the only way I've found to perform such task is to write a custom LDAPImporterImpl and put it into an EXT plug-in. Here is a snippet of my code:

    import com.liferay.portal.security.ldap.PortalLDAPImporterImpl // other imports public class CustomPortalLDAPImporterImpl extends PortalLDAPImporterImpl { @Override public User importLDAPUser(long ldapServerId, long companyId, LdapContext ldapContext, Attributes attributes, String password) throws Exception { User user = super.importLDAPUser(ldapServerId, companyId, ldapContext, attributes, password); String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId); String baseDN = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_DN + postfix); Attributes completeUserAttributes = getUserLdapAttributes(ldapContext, user, baseDN); setUserAddress(user, completeUserAttributes); setUserPhones(user, completeUserAttributes); return user; } // ... private Attributes getUserLdapAttributes(LdapContext ctx, User user, String baseDN) { String searchFilter = "(&(objectClass=person)(sAMAccountName=" + user.getScreenName() + "))"; SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration<SearchResult> results; try { log.debug("Searching LDAP with the following filter: " + searchFilter); results = ctx.search(baseDN, searchFilter, searchControls); SearchResult searchResult = null; if(results.hasMoreElements()) { searchResult = (SearchResult) results.nextElement(); if(results.hasMoreElements()) { log.error("Matched multiple users for the user: " + user.getScreenName()); return null; } Attributes attributes = searchResult.getAttributes(); return attributes; } else { log.error("No LDAP record for username [" + user.getScreenName() + "] found."); } } catch (NamingException e) { log.error("Error getting attributes for user [" + user.getScreenName() + "]: " + e.getMessage()); } return null; } // ... }

    您还必须在EXT插件的META-INF/ext-spring.xml文件中定义此导入程序:

    You also have to define this importer in the META-INF/ext-spring.xml file of the EXT plug-in:

    <?xml version="1.0"?> <beans default-destroy-method="destroy" default-init-method="afterPropertiesSet" xmlns="www.springframework/schema/beans" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="www.springframework/schema/beans www.springframework/schema/beans/spring-beans-3.0.xsd" > <bean id="ldapToPortalConverter" class="com.liferay.portal.security.ldap.DefaultLDAPToPortalConverter" /> <bean id="portalToLDAPConverter" class="com.liferay.portal.security.ldap.DefaultPortalToLDAPConverter" /> <bean id="com.liferay.portal.security.ldap.PortalLDAPExporterUtil" class="com.liferay.portal.security.ldap.PortalLDAPExporterUtil"> <property name="portalLDAPExporter"> <bean class="com.liferay.portal.security.ldap.PortalLDAPExporterImpl"> <property name="portalToLDAPConverter" ref="portalToLDAPConverter" /> </bean> </property> </bean> <bean id="com.liferay.portal.security.ldap.PortalLDAPImporterUtil" class="com.liferay.portal.security.ldap.PortalLDAPImporterUtil"> <property name="portalLDAPImporter"> <bean class="ch.openinteractive.familea.security.ldap.CustomPortalLDAPImporterImpl"> <property name="LDAPToPortalConverter" ref="ldapToPortalConverter" /> </bean> </property> </bean> </beans>

    如果有人提供更好,侵入性较小的解决方案,我会很高兴.

    I'd be happy if someone come with a better, less invasive solution.

    更多推荐

    将LDAP属性映射到Liferay用户显示语言

    本文发布于:2023-11-17 05:42:53,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1609032.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:属性   语言   用户   LDAP   Liferay

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!