001
014
015 package com.liferay.portal.model;
016
017 import com.liferay.portal.ModelListenerException;
018 import com.liferay.portal.security.ldap.LDAPOperation;
019 import com.liferay.portal.security.ldap.LDAPUserTransactionThreadLocal;
020 import com.liferay.portal.security.ldap.PortalLDAPExporterUtil;
021
022
025 public class UserGroupListener extends BaseModelListener<UserGroup> {
026
027 @Override
028 public void onAfterAddAssociation(
029 Object userGroupId, String associationClassName,
030 Object associationClassPK)
031 throws ModelListenerException {
032
033 try {
034 if (associationClassName.equals(User.class.getName())) {
035 exportToLDAP(
036 (Long)associationClassPK, (Long)userGroupId,
037 LDAPOperation.ADD);
038 }
039 }
040 catch (Exception e) {
041 throw new ModelListenerException(e);
042 }
043 }
044
045 @Override
046 public void onAfterRemoveAssociation(
047 Object userGroupId, String associationClassName,
048 Object associationClassPK)
049 throws ModelListenerException {
050
051 try {
052 if (associationClassName.equals(User.class.getName())) {
053 exportToLDAP(
054 (Long)associationClassPK, (Long)userGroupId,
055 LDAPOperation.REMOVE);
056 }
057 }
058 catch (Exception e) {
059 throw new ModelListenerException(e);
060 }
061 }
062
063 protected void exportToLDAP(
064 long userId, long userGroupId, LDAPOperation ldapOperation)
065 throws Exception {
066
067 if (LDAPUserTransactionThreadLocal.isOriginatesFromLDAP()) {
068 return;
069 }
070
071 PortalLDAPExporterUtil.exportToLDAP(userId, userGroupId, ldapOperation);
072 }
073
074 }