001
014
015 package com.liferay.portal.model;
016
017 import com.liferay.portal.ModelListenerException;
018 import com.liferay.portal.security.ldap.LDAPUserTransactionThreadLocal;
019 import com.liferay.portal.security.ldap.PortalLDAPExporterUtil;
020 import com.liferay.portal.service.ServiceContext;
021 import com.liferay.portal.service.ServiceContextThreadLocal;
022
023 import java.io.Serializable;
024
025 import java.util.Map;
026
027
032 public class UserListener extends BaseModelListener<User> {
033
034 public void onAfterCreate(User user) throws ModelListenerException {
035 try {
036 exportToLDAP(user);
037 }
038 catch (Exception e) {
039 throw new ModelListenerException(e);
040 }
041 }
042
043 public void onAfterUpdate(User user) throws ModelListenerException {
044 try {
045 exportToLDAP(user);
046 }
047 catch (Exception e) {
048 throw new ModelListenerException(e);
049 }
050 }
051
052 protected void exportToLDAP(User user) throws Exception {
053 if (user.isDefaultUser() ||
054 LDAPUserTransactionThreadLocal.isOriginatesFromLDAP()) {
055
056 return;
057 }
058
059 ServiceContext serviceContext =
060 ServiceContextThreadLocal.getServiceContext();
061
062 Map<String, Serializable> expandoBridgeAttributes = null;
063
064 if (serviceContext != null) {
065 expandoBridgeAttributes =
066 serviceContext.getExpandoBridgeAttributes();
067 }
068
069 PortalLDAPExporterUtil.exportToLDAP(user, expandoBridgeAttributes);
070 }
071
072 }