Issue
- Receiving the following error when trying to import User Groups from LDAP containing a comma "," or an asterisk "*":
2020-06-04 08:23:50.268 WARN [main][LDAPUserImporterImpl:1165] Unable to create user group test,users 2020-06-04 08:23:50.280 ERROR [main][LDAPUserImporterImpl:780] Unable to import group cn=test\,users,ou=groups: null:null:{cn=cn: test,users} java.lang.NullPointerException at com.liferay.portal.security.ldap.internal.exportimport.LDAPUserImporterImpl.getUsers(LDAPUserImporterImpl.java:720) at com.liferay.portal.security.ldap.internal.exportimport.LDAPUserImporterImpl.importFromLDAPByGroup(LDAPUserImporterImpl.java:763) at com.liferay.portal.security.ldap.internal.exportimport.LDAPUserImporterImpl.importUsers(LDAPUserImporterImpl.java:474) at com.liferay.portal.security.ldap.internal.exportimport.LDAPUserImporterImpl.importUsers(LDAPUserImporterImpl.java:415) ...
Environment
- Liferay Portal 6.0+
- Liferay DXP 7.0+
- LDAP
Resolution
- User Groups in Liferay can not contain "," and "*" in their names, therefore generates com.liferay.portal.kernel.exception.UserGroupNameException when trying to add the User Group based on the LDAP Group. The NullPointerException happens because later when #getUsers is invoked it receives "null" as User Group.
-
A possible workaround would be to:
- Create a custom
@Component
that implementscom.liferay.portal.security.ldap.exportimport.LDAPToPortalConverter
: in theimportLDAPGroup
method - Implement a custom logic that accounts the special characters in a way that is suitable (for example remove the comma)
- So when
ldapGroup.getGroupName()
will be used later as the name for the User Group to be created inLDAPUserImporterImpl.importUserGroup(long, Attributes, Properties)
it won't fail and the User Group will be created.
- Create a custom
Additional Information
- Please find the default implementation on this link.