1
14
15 package com.liferay.portal.model;
16
17 import com.liferay.portal.ModelListenerException;
18 import com.liferay.portal.security.ldap.LDAPUserTransactionThreadLocal;
19 import com.liferay.portal.security.ldap.PortalLDAPExporterUtil;
20 import com.liferay.portal.service.ServiceContext;
21 import com.liferay.portal.service.ServiceContextThreadLocal;
22
23 import java.io.Serializable;
24
25 import java.util.Map;
26
27
34 public class UserListener extends BaseModelListener<User> {
35
36 public void onAfterCreate(User user) throws ModelListenerException {
37 try {
38 exportToLDAP(user);
39 }
40 catch (Exception e) {
41 throw new ModelListenerException(e);
42 }
43 }
44
45 public void onAfterUpdate(User user) throws ModelListenerException {
46 try {
47 exportToLDAP(user);
48 }
49 catch (Exception e) {
50 throw new ModelListenerException(e);
51 }
52 }
53
54 protected void exportToLDAP(User user) throws Exception {
55 if (user.isDefaultUser() ||
56 LDAPUserTransactionThreadLocal.isOriginatesFromLDAP()) {
57
58 return;
59 }
60
61 ServiceContext serviceContext =
62 ServiceContextThreadLocal.getServiceContext();
63
64 Map<String, Serializable> expandoBridgeAttributes = null;
65
66 if (serviceContext != null) {
67 expandoBridgeAttributes =
68 serviceContext.getExpandoBridgeAttributes();
69 }
70
71 PortalLDAPExporterUtil.exportToLDAP(user, expandoBridgeAttributes);
72 }
73
74 }