Liferay 7 self registration with LDAP & CAS does not export passwordLiferay 7 self registration with LDAP & CAS does not export passwordhttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=872505962024-03-28T20:16:49Z2024-03-28T20:16:49ZLiferay 7 self registration with LDAP & CAS does not export passwordAbre Chasehttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=872505952017-03-16T19:23:51Z2017-03-16T19:23:51Z<html><head></head><body>We have Liferay 7.02-ga3 CE setup and integrated with CAS and LDAP. When a new user is created using self registration, the password is not being exported to LDAP. I got the source and debugged and found where it is failing or at least a downstream problem.<br><br>com.liferay.portal.security.ldap.internal.exportimport.DefaultPortalToLDAPConverter.getEncryptedPasswordForLDAP(User, Properties)<br><br>There is a line in here that looks for the unencrypted password and returns null if this variable wasn't set.<br><br>String password = PasswordModificationThreadLocal.getPasswordUnencrypted();<br><br><pre><code> if (Validator.isNull(password)) {
return password;
}</code></pre><br><br>I guess this variable isn't being set during self registration.<br><br>Based on reading some other threads, I was able to create a listener to set the variable:<br><br><pre><code>public class SelfRegistrationModelListener extends BaseModelListener<user>
{
@Override
public void onAfterCreate(User model) throws ModelListenerException
{
if (model.getPassword() != null)
{
model.setPasswordModified(true);
model.setPasswordModifiedDate(Calendar.getInstance().getTime());
PasswordModificationThreadLocal.setPasswordUnencrypted(model.getPasswordUnencrypted());
try
{
exportToLDAP(model);
}
catch (Exception e)
{
throw new ModelListenerException(e);
}
}
}
protected void exportToLDAP(User user) throws Exception {
if (user.isDefaultUser())
{
return;
}
ServiceContext serviceContext =
ServiceContextThreadLocal.getServiceContext();
Map<string, serializable> expandoBridgeAttributes = null;
if (serviceContext != null) {
expandoBridgeAttributes =
serviceContext.getExpandoBridgeAttributes();
}
_userExporter.exportUser(user, expandoBridgeAttributes);
}
@Reference(policyOption = ReferencePolicyOption.GREEDY)
private UserExporter _userExporter;
}</string,></user></code></pre><br><br>The password is now being exported to LDAP during self registration, but it doesn't seem like the listener code above should be necessary.<br><br>Posting here in case others have run into the same problem and for some feedback about whether or not the observed behavior is a Liferay defect.</body>