1 /*******************************************************************************
2 * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
3 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
4 * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
6 * This file is part of the work and learning management system Pentila Nero.
8 * Pentila Nero is free software. You can redistribute it and/or modify since
9 * you respect the terms of either (at least one of the both license) :
10 * - under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 * - the CeCILL-C as published by CeCILL-C; either version 1 of the
14 * License, or any later version
15 * - the GNU Lesser General Public License as published by the
16 * Free Software Foundation, either version 3 of the license,
17 * or (at your option) any later version.
19 * There are special exceptions to the terms and conditions of the
20 * licenses as they are applied to this software. View the full text of
21 * the exception in file LICENSE-PROJECT.txt in the directory of this software
24 * Pentila Nero is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * Licenses for more details.
29 * You should have received a copy of the GNU Affero General Public License
30 * and the CeCILL-C and the GNU Lesser General Public License along with
31 * Pentila Nero. If not, see :
32 * <http://www.gnu.org/licenses/> and
33 * <http://www.cecill.info/licences.fr.html>.
34 ******************************************************************************/
35 package com.pentila.entSavoie.listeners;
37 import java.util.List;
39 import javax.naming.Binding;
40 import javax.naming.directory.Attributes;
41 import javax.naming.ldap.LdapContext;
43 import org.springframework.security.providers.ldap.authenticator.LdapShaPasswordEncoder;
45 import com.liferay.portal.ModelListenerException;
46 import com.liferay.portal.kernel.exception.PortalException;
47 import com.liferay.portal.kernel.exception.SystemException;
48 import com.liferay.portal.kernel.log.Log;
49 import com.liferay.portal.kernel.log.LogFactoryUtil;
50 import com.liferay.portal.model.ModelListener;
51 import com.liferay.portal.model.User;
52 import com.liferay.portal.security.ldap.PortalLDAPUtil;
53 import com.pentila.entSavoie.internalMessaging.model.InternalFolderMessage;
54 import com.pentila.entSavoie.internalMessaging.model.InternalMessage;
55 import com.pentila.entSavoie.internalMessaging.service.InternalFolderMessageLocalServiceUtil;
56 import com.pentila.entSavoie.internalMessaging.service.InternalMessageLocalServiceUtil;
57 import com.pentila.entSavoie.userProperties.NoSuchNotifyConfigException;
58 import com.pentila.entSavoie.userProperties.service.NotifyConfigLocalServiceUtil;
59 import com.pentila.entSavoie.userProperties.service.UserPropertiesLocalServiceUtil;
60 import com.pentila.entSavoie.utils.XmppUtil;
63 * @author Lancelot SIX
66 * Ce listener est destiné à être appelé après chaque modification d'un objet
67 * User. Si le mot de passe de cet utilisateur à été changé, alors, celui-ci
68 * est exporté vers la base LDAP pour pouvoir est utilisable lors de la prochaine
72 public class UserListener implements ModelListener<User> {
74 public void onAfterAddAssociation(Object arg0, String arg1, Object arg2)
75 throws ModelListenerException {}
77 public void onAfterCreate(User user) throws ModelListenerException {}
79 public void onAfterRemove(User user) throws ModelListenerException {}
81 public void onAfterRemoveAssociation(Object arg0, String arg1, Object arg2)
82 throws ModelListenerException {}
84 public void onAfterUpdate(User user) throws ModelListenerException {
88 // //If we can access the password on an unencrypted form, then we export
90 // if (user.getPasswordUnencrypted()!=null) {
92 // System.out.println("onAfterUpdate UserListener");
93 // System.out.println("user pwd reset: " + user.isPasswordReset());
95 // //Recupere l'user dans le lda
96 // Binding ldapUser = PortalLDAPUtil.getUser(user.getCompanyId(), user.getScreenName());
97 // System.out.println("+++++ after get user in LDAP1");
98 // final String userDN = PortalLDAPUtil.getNameInNamespace(user.getCompanyId(), ldapUser);
99 // System.out.println("+++++ after get user in LDAP2 : userDN = "+userDN);
101 // final LdapContext ctx = PortalLDAPUtil.getContext(user.getCompanyId());
102 // System.out.println("+++++ after get context");
104 // Attributes userAttrs = ctx.getAttributes(userDN);
105 // userAttrs.remove("userPassword");
106 // System.out.println("+++++ after removing userPassword attribute");
107 // System.out.println("+++++ unencrypted password = "+user.getPasswordUnencrypted());
108 // String encryptedPassword = encryptPassword(user.getPasswordUnencrypted());
109 // System.out.println("+++++ encrypted password = "+encryptedPassword);
111 // userAttrs.put("userPassword", encryptedPassword);
112 // ctx.rebind(userDN, null, userAttrs);
114 // if (ctx != null) {
119 // if (_log.isDebugEnabled()) {
120 // _log.debug("Exporting new password to ldap for user "+user.getScreenName());
124 // System.out.println("+++++ Exported password");
126 // } catch (Exception e) {
127 // e.printStackTrace();
128 // if (_log.isInfoEnabled()) {
131 // throw new ModelListenerException (e);
135 public void onBeforeAddAssociation(Object arg0, String arg1, Object arg2)
136 throws ModelListenerException {}
138 public void onBeforeCreate(User arg0) throws ModelListenerException {}
140 public void onBeforeRemove(User user) throws ModelListenerException {
142 // All this code is now included in the tool UserCleanup or the scheduled task UserPurgeImpl
146 public void onBeforeRemoveAssociation(Object arg0, String arg1, Object arg2)
147 throws ModelListenerException {}
149 public void onBeforeUpdate(User arg0) throws ModelListenerException {}
151 protected String encryptPassword(String pass) {
152 LdapShaPasswordEncoder encoder = new LdapShaPasswordEncoder();
153 return encoder.encodePassword(pass, null);
156 private Log _log = LogFactoryUtil.getLog(this.getClass());