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.synchroLdap.impl;
37 import java.text.DateFormat;
38 import java.text.ParseException;
39 import java.text.SimpleDateFormat;
40 import java.util.ArrayList;
41 import java.util.Calendar;
42 import java.util.Date;
43 import java.util.GregorianCalendar;
44 import java.util.HashMap;
45 import java.util.HashSet;
46 import java.util.List;
48 import java.util.Properties;
51 import javax.mail.internet.InternetAddress;
52 import javax.naming.NameNotFoundException;
53 import javax.naming.NamingEnumeration;
54 import javax.naming.NamingException;
55 import javax.naming.directory.Attribute;
56 import javax.naming.directory.Attributes;
57 import javax.naming.directory.DirContext;
58 import javax.naming.directory.ModificationItem;
59 import javax.naming.directory.SearchResult;
61 import com.liferay.contacts.util.OrganizationConstants;
62 import org.apache.commons.collections.CollectionUtils;
63 import org.apache.commons.lang.math.RandomUtils;
64 import com.liferay.mail.service.MailServiceUtil;
65 import com.liferay.portal.DuplicateUserEmailAddressException;
66 import com.liferay.portal.NoSuchUserException;
67 import com.liferay.portal.NoSuchUserGroupException;
68 import com.liferay.portal.kernel.exception.PortalException;
69 import com.liferay.portal.kernel.exception.SystemException;
70 import com.liferay.portal.kernel.ldap.LDAPUtil;
71 import com.liferay.portal.kernel.log.Log;
72 import com.liferay.portal.kernel.log.LogFactoryUtil;
73 import com.liferay.portal.kernel.log.LogUtil;
74 import com.liferay.portal.kernel.mail.MailMessage;
75 import com.liferay.portal.kernel.util.InstancePool;
76 import com.liferay.portal.kernel.util.PrefsPropsUtil;
77 import com.liferay.portal.kernel.util.PropertiesUtil;
78 import com.liferay.portal.kernel.util.PropsKeys;
79 import com.liferay.portal.kernel.util.StringPool;
80 import com.liferay.portal.kernel.util.Validator;
81 import com.liferay.portal.kernel.workflow.WorkflowConstants;
82 import com.liferay.portal.model.Company;
83 import com.liferay.portal.model.CompanyConstants;
84 import com.liferay.portal.model.Contact;
85 import com.liferay.portal.model.Organization;
86 import com.liferay.portal.model.Role;
87 import com.liferay.portal.model.User;
88 import com.liferay.portal.model.UserGroup;
89 import com.liferay.portal.security.auth.ScreenNameGenerator;
90 import com.liferay.portal.security.ldap.ENTAttributesTransformer;
91 import com.liferay.portal.security.ldap.ENTAttributesTransformerFactory;
92 import com.liferay.portal.security.ldap.LDAPConstants;
93 import com.liferay.portal.security.ldap.PortalLDAPUtil;
94 import com.liferay.portal.service.CompanyLocalServiceUtil;
95 import com.liferay.portal.service.ContactLocalServiceUtil;
96 import com.liferay.portal.service.OrganizationLocalServiceUtil;
97 import com.liferay.portal.service.RoleLocalServiceUtil;
98 import com.liferay.portal.service.ServiceContext;
99 import com.liferay.portal.service.UserGroupLocalServiceUtil;
100 import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
101 import com.liferay.portal.service.UserLocalServiceUtil;
102 import com.liferay.portal.util.PropsValues;
103 import com.pentila.entSavoie.ENTRoleUtilFactory;
104 import com.pentila.entSavoie.ENTRolesConstants;
105 import com.pentila.entSavoie.ENTRolesUtil;
106 import com.pentila.entSavoie.carnetDAdresses.model.Fiche;
107 import com.pentila.entSavoie.carnetDAdresses.service.FicheLocalServiceUtil;
108 import com.pentila.entSavoie.communityInfos.model.OrganizationCiteScolaire;
109 import com.pentila.entSavoie.communityInfos.model.OrganizationMapping;
110 import com.pentila.entSavoie.communityInfos.service.OrganizationCiteScolaireLocalServiceUtil;
111 import com.pentila.entSavoie.communityInfos.service.OrganizationMappingLocalServiceUtil;
112 import com.pentila.entSavoie.synchroLdap.exceptions.UserSynchronizationException;
113 import com.pentila.entSavoie.userManagement.model.LDAPMapping;
114 import com.pentila.entSavoie.userManagement.service.LDAPMappingLocalServiceUtil;
115 import com.pentila.entSavoie.userProperties.model.NotifyConfig;
116 import com.pentila.entSavoie.userProperties.model.UserContact;
117 import com.pentila.entSavoie.userProperties.model.UserProperties;
118 import com.pentila.entSavoie.userProperties.model.UserRelationship;
119 import com.pentila.entSavoie.userProperties.service.NotifyConfigLocalServiceUtil;
120 import com.pentila.entSavoie.userProperties.service.UserContactLocalServiceUtil;
121 import com.pentila.entSavoie.userProperties.service.UserPropertiesLocalServiceUtil;
122 import com.pentila.entSavoie.userProperties.service.UserRelationshipLocalServiceUtil;
123 import com.pentila.entSavoie.userRelationship.UserRelationshipConstants;
124 import com.pentila.entSavoie.utils.ENTMainUtilsLocalServiceUtil;
125 import com.pentila.entSavoie.utils.ENTOrganizationsUtil;
128 * Main class for synchronization process
129 * @author Cedric Lecarpentier
132 public class SynchronizationManager {
134 static DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
136 private static Log _log = LogFactoryUtil.getLog(SynchronizationManager.class);
138 // The organization map <etabId - Organization>
139 private static Map<String, Organization> etabMap;
141 // The organization map <ou - ENTStructureUAI>
142 private static Map<String, String> etabOuMap;
144 // The user map <screenName - ENTPersonStructRattach>
145 private static Map<String, String> userRattachSchoolMap;
147 // The user map <screenName - LDAP attributes>
148 private static Map<String, Attributes> userAttributesMap;
150 // The user map <user DN - userId>
151 private static Map<String, Long> userEverImported;
153 private static long companyId;
155 // Is a synchronization already running ?
156 private static boolean synchronizationOnGoing;
158 // Used to generate report
159 private static List<User> createdUserList;
161 public static void runSynchronization() throws Exception {
162 runSynchronization(true);
166 * Run the synchronization
168 * @param forceSynchro
171 public static void runSynchronization(boolean force) throws Exception {
175 if (!isImportEnabled(companyId) && !force) {
176 _log.warn("Running synchronization is not possible because it is not allowed and not forced");
180 if (synchronizationOnGoing) {
181 _log.warn("Running synchronization is not possible because a synchronization is already on going.");
185 _log.info("Synchronization START");
187 Date startSynchroTime = new Date();
190 initSynchronization();
194 // Step 1 : user creation / update
195 runSynchroUserCreation();
197 // Step 2 : synchro groups
200 // Step 3 : update parent relationships for created users
201 updateParentRelations();
203 // Step 4 : Manage memberships
204 MembershipManager.manageMemberships(companyId);
206 // Send mail at synchronization's end
207 Date endSynchroTime = new Date();
208 sendSynchronizationEndMail(startSynchroTime, endSynchroTime);
210 // Prepare for reporting
211 processCreatedUsers();
213 SynchronizationReport.generateReportForSchoolManagers();
214 } catch (Exception e) {
215 _log.error("Error while synchronizing : ", e);
217 synchronizationOnGoing = false;
219 _log.info("Synchronization END");
225 * Initializes all variables for synchronization
227 private static void initSynchronization () {
229 synchronizationOnGoing = true;
230 SynchronizationReport.initReport(companyId);
232 createdUserList = new ArrayList<User>();
234 userRattachSchoolMap = new HashMap<String, String>();
235 userAttributesMap = new HashMap<String, Attributes>();
236 userEverImported = new HashMap<String, Long>();
239 initializeSchoolMaps();
240 initializeSchoolComplexes();
241 } catch (Exception e) {
242 _log.error("Error while initializing schools and school complexes");
248 * Entry point for user synchronization
252 public static void runSynchroUserCreation() {
254 long time0 = System.currentTimeMillis();
259 NamingEnumeration<SearchResult> enu2 = PortalLDAPUtil.getUsers(companyId, 0);
260 while (enu2.hasMoreElements()) {
265 _log.info("STARTING user synchronisation for "+count+" users ...");
266 NamingEnumeration<SearchResult> enu = PortalLDAPUtil.getUsers(companyId, 0);
268 // Loop through all LDAP users
270 while (enu.hasMoreElements()) {
272 long timeUser1 = System.currentTimeMillis();
273 SearchResult result = enu.nextElement();
274 String nameInNameSpace = PortalLDAPUtil.getNameInNamespace(companyId, result);
275 Attributes attrs = PortalLDAPUtil.getUserAttributes(companyId, nameInNameSpace);
276 synchronizeUser (companyId, attrs, StringPool.BLANK, false);
277 long timeUser2 = System.currentTimeMillis();
278 _log.info("User synchronization took "+(timeUser2 - timeUser1)+" ms : "+idx+"/"+count);
281 } catch (Exception e) {
282 _log.error("Error when synchronizing user");
286 } catch (Exception e) {
287 _log.error("Error when synchronizing users");
290 long time1 = System.currentTimeMillis();
291 int userSyncTime = (int)((time1 - time0)/60000);
292 SynchronizationReport.setUserSyncTime(userSyncTime);
293 _log.info(" Whole user synchronization took "+userSyncTime +" minutes");
303 * @param importGroupMembership
308 public static User synchronizeUser (long companyId, Attributes attrs, String password, boolean manualCreation)
311 _log.info("Synchronizing user ...");
313 // Set email default generated if not present
314 ENTAttributesTransformer attrsTransformer = ENTAttributesTransformerFactory.getInstance();
315 Attributes originalAttributes = attrs;
316 attrs = attrsTransformer.transformUser(attrs, companyId);
318 Properties userMappings = PropertiesUtil.load(PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_USER_MAPPINGS));
320 User defaultUser = UserLocalServiceUtil.getDefaultUser(companyId);
322 boolean autoPassword = password.equals(StringPool.BLANK);
323 boolean autoScreenName = false;
324 ServiceContext serviceContext = new ServiceContext();
327 String screenName = LDAPUtil.getAttributeString(attrs, userMappings.getProperty("screenName")).toLowerCase();
328 String emailAddress = LDAPUtil.getAttributeString(attrs, userMappings.getProperty("emailAddress"));
329 String firstName = LDAPUtil.getAttributeString(attrs, userMappings.getProperty("firstName"));
330 String middleName = LDAPUtil.getAttributeString(attrs, userMappings.getProperty("middleName"));
331 String lastName = LDAPUtil.getAttributeString(attrs, userMappings.getProperty("lastName"));
332 String jobTitle = LDAPUtil.getAttributeString(attrs, userMappings.getProperty("jobTitle"));
333 boolean male = ((jobTitle.equals("M.") || jobTitle.equals("Mr"))?true:false);
336 if (Validator.isNull(firstName) || Validator.isNull(lastName)) {
337 String fullName = LDAPUtil.getAttributeString(attrs, userMappings.getProperty("fullName"));
338 String[] names = PortalLDAPUtil.splitFullName(fullName);
339 firstName = names[0];
340 middleName = names[1];
344 String birthDay = LDAPUtil.getAttributeString(attrs, userMappings.getProperty("birthDate"));
349 if(!birthDay.equals("")) {
350 birthdayMonth = Integer.valueOf(birthDay.substring(4, 6))-1;
351 birthdayDay =Integer.valueOf(birthDay.substring(6, 8));
352 birthdayYear = Integer.valueOf(birthDay.substring(0, 4));
354 birthdayMonth = Calendar.JANUARY;
359 if (Validator.isNull(screenName) || Validator.isNull(emailAddress)) {
360 _log.warn("Cannot add user because screen name and email address are required");
365 Date ldapUserModifiedDate = null;
369 // Find corresponding portal user : search by screenName or email
371 String authType = PrefsPropsUtil.getString(companyId, PropsKeys.COMPANY_SECURITY_AUTH_TYPE, PropsValues.COMPANY_SECURITY_AUTH_TYPE);
372 if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
373 user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName);
375 user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);
378 // Skip if default user
379 if (user.isDefaultUser()) {
383 // detect users with firstname and lastname different from ldap
385 if (!firstName.equals(user.getFirstName()) || !lastName.equals(user.getLastName())) {
386 _log.info("+++++ Difference in names for userId "+user.getUserId()+" (screenName "+user.getScreenName()+") : LDAP is "+firstName + " "+lastName+", DB is "+user.getFirstName()+" "+user.getLastName()+", creation date="+new SimpleDateFormat("yyyy-MM-dd").format(user.getCreateDate()));
387 //user.setFirstName(firstName);
388 //user.setLastName(lastName);
389 //user.setGreeting("Bienvenue "+firstName+" "+lastName+" !");
390 //UserLocalServiceUtil.updateUser(user);
391 //Contact contact = user.getContact();
392 //contact.setFirstName(firstName);
393 //contact.setLastName(lastName);
394 //ContactLocalServiceUtil.updateContact(contact);
398 // User already exists in the Liferay database. Skip import if user
399 // fields have been already synced, if import is part of a scheduled
400 // import, or if the LDAP entry has never been modified.
402 String modifiedDate = LDAPUtil.getAttributeString(attrs, "modifyTimestamp");
404 if (Validator.isNull(modifiedDate)) {
405 _log.info("LDAP entry never modified, skipping user " + user.getEmailAddress());
408 ldapUserModifiedDate = dateFormat.parse(modifiedDate);
411 if (ldapUserModifiedDate.equals(user.getModifiedDate())
412 && autoPassword && ENTMainUtilsLocalServiceUtil.isLDAPImportModifyDate(companyId)) {
413 _log.info("User is already synchronized, skipping user " + user.getEmailAddress());
417 } catch (ParseException pe) {
418 _log.error("Unable to parse LDAP modify timestamp " + modifiedDate, pe);
421 // Generate screenName
422 if (Validator.isNull(screenName)) {
423 autoScreenName = true;
424 ScreenNameGenerator screenNameGenerator = (ScreenNameGenerator) InstancePool.get(PropsValues.USERS_SCREEN_NAME_GENERATOR);
425 screenName = screenNameGenerator.generate(companyId, user.getUserId(), emailAddress);
428 _log.info("User "+firstName+" "+lastName+" exists in DB");
430 } catch (NoSuchUserException nsue) {
431 _log.error("User does not exist so create it");
433 } catch (DuplicateUserEmailAddressException dueae) {
434 _log.warn("Duplicate email adress for user "+screenName+" : "+ emailAddress);
437 } catch (Exception e) {
438 _log.error("Error updating user with screen name " + screenName + " and email address " + emailAddress, e);
443 // User creation (except for those with ENTValidAccount = 2)
444 String entValidAccount = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTVALIDACCOUNT);
445 if (user == null && entValidAccount.equals("1")) {
446 _log.info("+++++ Error : user has ENTValicAccount to 1 but does not exist");
448 if (user == null && !entValidAccount.equals("2")) {
451 _log.info("Adding user "+firstName+" "+lastName+ " to portal.");
452 user = UserLocalServiceUtil.addUser(0, companyId,
453 autoPassword, password, password, autoScreenName,
454 screenName, emailAddress, 0, StringPool.BLANK, defaultUser.getLocale(), firstName,
455 middleName, lastName, 0, 0, male,
456 birthdayMonth, birthdayDay, birthdayYear, jobTitle,
457 null, null, null, null,
458 false, serviceContext);
460 if (createdUserList == null) {
461 createdUserList = new ArrayList<User>();
463 createdUserList.add(user);
465 Date today = new Date();
466 user.setLastLoginDate(today);
467 user.setModifiedDate(today);
469 user.setPasswordModified(true);
470 // If user created in ENT
471 if (manualCreation) {
472 user.setPasswordReset(true);
475 user.setPasswordReset(false);
477 user.setReminderQueryQuestion("@new@");
478 user.setReminderQueryAnswer("@new@");
479 UserLocalServiceUtil.updateUser(user);
481 // Create the user fiche
482 Fiche fiche = FicheLocalServiceUtil.createUserFiche(user, user);
483 _log.debug("create fiche : " + fiche.getFicheId() + " for user " + user.getUserId());
485 // Create default user properties
486 UserProperties up = UserPropertiesLocalServiceUtil.addUserProperties(user, false);
487 _log.debug("create user_properties : " + up.getUserPropertiesId() + " for user " + user.getUserId());
489 // Create default user notifications
490 NotifyConfig userNotificationConfig = NotifyConfigLocalServiceUtil.getOrCreateNotifyConfig(user.getUserId());
491 _log.debug("create user notification config : " + userNotificationConfig.getNotifyConfigId() + " for user " + user.getUserId());
493 } catch (DuplicateUserEmailAddressException dueae) {
495 _log.warn("Duplicate email adress for user "+screenName+" : "+ emailAddress);
498 // In this case we create the account with a generated email and set the user's email in his preferences
499 String newEmail = screenName + ENTMainUtilsLocalServiceUtil.getENTOrgRootSuffixeMail(companyId);
500 _log.info("Adding user "+firstName+" "+lastName+ " to portal with changed email "+newEmail);
501 user = UserLocalServiceUtil.addUser(0, companyId,
502 autoPassword, password, password, autoScreenName,
503 screenName, newEmail, 0, StringPool.BLANK, defaultUser.getLocale(), firstName,
504 middleName, lastName, 0, 0, male,
505 birthdayMonth, birthdayDay, birthdayYear, jobTitle,
506 null, null, null, null,
507 false, serviceContext);
509 if (createdUserList == null) {
510 createdUserList = new ArrayList<User>();
512 createdUserList.add(user);
514 Date today = new Date();
515 user.setLastLoginDate(today);
516 user.setModifiedDate(today);
518 user.setPasswordModified(true);
519 // If user created in ENT
520 if (manualCreation) {
521 user.setPasswordReset(true);
524 user.setPasswordReset(false);
526 user.setReminderQueryQuestion("@new@");
527 user.setReminderQueryAnswer("@new@");
528 UserLocalServiceUtil.updateUser(user);
530 // Create the user fiche
531 Fiche fiche = FicheLocalServiceUtil.createUserFiche(user, user);
532 _log.debug("create fiche : " + fiche.getFicheId() + " for user " + user.getUserId());
534 // Create default user properties
535 UserProperties up = UserPropertiesLocalServiceUtil.addUserProperties(user, false);
536 _log.debug("create user_properties : " + up.getUserPropertiesId()+ " for user " + user.getUserId());
538 // Create default user notifications
539 NotifyConfig userNotificationConfig = NotifyConfigLocalServiceUtil.getOrCreateNotifyConfig(user.getUserId());
540 _log.debug("create user notification config : " + userNotificationConfig.getNotifyConfigId() + " for user " + user.getUserId());
541 } catch (Exception e) {
542 _log.error("Error while creating user "+user.getUserId() + " with new email", e);
545 } catch (Exception e) {
546 _log.error("Problem adding user with screen name " + screenName + " and email address " + emailAddress, e);
552 // Store the UID in the DB (LDAPMapping)
553 String uid = LDAPUtil.getAttributeString(attrs, "uid");
554 LDAPMapping ldapMapping = LDAPMappingLocalServiceUtil.fetchLDAPMapping(user.getUserId());
555 if (ldapMapping == null) {
556 ldapMapping = LDAPMappingLocalServiceUtil.createLDAPMapping(user.getUserId());
557 ldapMapping.setUID(uid);
558 LDAPMappingLocalServiceUtil.updateLDAPMapping(ldapMapping);
562 RoleEnum roleEnum = synchronizeRoles(user, attrs);
564 Organization rattachSchool = null;
565 if (manualCreation) {
566 // Get 'ENTPersonStructRattach' attribute
567 String entPersonStructRattach = attrs.get("ENTPersonStructRattach").get().toString();
568 _log.info("Manual creation : entPersonStructRattach="+entPersonStructRattach);
569 rattachSchool = SynchronizationUtils.getSchoolFromClassName(entPersonStructRattach);
572 rattachSchool = getRattachSchool(user);
574 if (rattachSchool == null) {
575 _log.error("Error : No rattach school found for user "+user.getFullName());
579 // Update user status
580 updateUserActivation(user, attrs, rattachSchool, roleEnum);
582 //Synchronize school-level organizations
583 synchronizeSchoolLevelOrganizations(companyId, user, attrs, manualCreation);
585 // Update modified date
586 Date today = new Date();
587 UserLocalServiceUtil.updateModifiedDate(user.getUserId(), (ldapUserModifiedDate != null) ? ldapUserModifiedDate : today);
589 // Update birth date if needed
590 Date userBirthDay = user.getBirthday();
591 Calendar cal = new GregorianCalendar();
592 cal.setTime(userBirthDay);
593 if (cal.get(Calendar.YEAR) != birthdayYear || cal.get(Calendar.MONTH) != birthdayMonth || cal.get(Calendar.DATE) != birthdayDay) {
594 cal.set(Calendar.YEAR, birthdayYear);
595 cal.set(Calendar.MONTH, birthdayMonth);
596 cal.set(Calendar.DATE, birthdayDay);
597 Date newBirthDay = cal.getTime();
598 _log.info("Updating bithday in contact for user "+user.getFullName()+" (id "+user.getUserId()+") to "+dateFormat.format(newBirthDay));
599 Contact contact = user.getContact();
600 contact.setBirthday(newBirthDay);
601 ContactLocalServiceUtil.updateContact(contact);
604 // Update email if changed
606 if (!user.getEmailAddress().equals(emailAddress)) {
607 _log.info("About to update email for user "+user.getFullName()+" : "+emailAddress);
608 user.setEmailAddress(emailAddress);
609 UserLocalServiceUtil.updateUser(user);
610 _log.info("Updated email for user "+user.getFullName()+" : "+emailAddress);
612 } catch (Exception e) {
613 _log.error("Error while updating user email from "+user.getEmailAddress()+" to "+emailAddress+" (maybe duplicate account)");
616 // Update user properties
617 updateUserProperties(user, attrs);
618 updateContactProperties(user, originalAttributes);
619 updateServiceNotifications(user);
621 synchronizeParents(user, attrs);
628 * Update UserProperties table
632 private static void updateUserProperties(User user, Attributes attrs) {
635 String ENTEleveBoursier = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTELEVEBOURSIER);
636 String ENTEleveTransport = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTELEVETRANSPORT);
637 String ENTEleveRegime = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTELEVEREGIME);
639 UserProperties up = UserPropertiesLocalServiceUtil.getUserPropertiesByUserId(user.getUserId());
640 up.setGrantHolder(ENTEleveBoursier != null && ENTEleveBoursier.equals("O"));
641 up.setTransported(ENTEleveTransport != null && ENTEleveTransport.equals("O"));
642 up.setStatus((ENTEleveRegime != null) ? ENTEleveRegime : "");
644 UserPropertiesLocalServiceUtil.updateUserProperties(up);
646 } catch (Exception e) {
647 _log.error("Error while updating user properties for user "+user.getUserId());
653 * Update UserContact table
657 private static void updateContactProperties(User user, Attributes attrs) {
660 String ENTPersonAdresse = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONADRESSE);
661 String ENTPersonAdresseDiffusion = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONADRESSEDIFFUSION);
662 String mail = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_MAIL);
663 String ENTPersonMailDiffusion = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONMAILDIFFUSION);
664 String homePhone = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_HOMEPHONE);
665 String proPhone = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_TELEPHONENUMBER);
666 String mobile = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_MOBILE);
667 String mobileSMS = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONMOBILESMS);
669 String suffixe = ENTMainUtilsLocalServiceUtil.getENTOrgRootSuffixeMail(user.getCompanyId());
670 boolean isMailValid = !user.getEmailAddress().equals(user.getScreenName()+suffixe);
676 UserContact uc = UserContactLocalServiceUtil.getUserContactByUserId(user.getUserId());
677 uc.setAddress((ENTPersonAdresse != null)? ENTPersonAdresse : "");
678 uc.setIsAddressAuthorized(ENTPersonAdresseDiffusion != null && ENTPersonAdresseDiffusion.equals("O"));
679 uc.setMail((mail != null) ? mail : "");
680 uc.setIsMailAuthorized(ENTPersonMailDiffusion != null && ENTPersonMailDiffusion.equals("O"));
681 uc.setMobilePhone((mobile != null) ? mobile: "");
682 uc.setMobilePhoneSMS((mobileSMS != null)? mobileSMS : "");
683 uc.setProPhone((proPhone != null)? proPhone : "");
684 uc.setHomePhone((homePhone != null)? homePhone : "");
685 UserContactLocalServiceUtil.updateUserContact(uc);
687 } catch(Exception e) {
688 _log.error("Error while updating user contact properties for user "+user.getUserId());
694 * Update NotifyConfig table
698 private static void updateServiceNotifications(User user) {
701 // Force notifications to enable
702 if (ENTMainUtilsLocalServiceUtil.isEnableServicesNotifications(user.getCompanyId())) {
703 NotifyConfig userNotificationConfig = NotifyConfigLocalServiceUtil.getOrCreateNotifyConfig(user.getUserId());
705 userNotificationConfig.setNotifyCasier(true);
706 userNotificationConfig.setNotifyActu(true);
707 userNotificationConfig.setNotifyGrpDoc(true);
708 userNotificationConfig.setNotifyForum(true);
709 userNotificationConfig.setNotifyAgenda(true);
710 userNotificationConfig.setDigestPeriod(1);
711 userNotificationConfig.setUserId(user.getUserId());
713 userNotificationConfig.setActivate(true);
715 NotifyConfigLocalServiceUtil.updateNotifyConfig(userNotificationConfig);
717 } catch(Exception e) {
718 _log.error("Error while updating user notify config for user "+user.getUserId());
724 * Create parent relationships for students
728 private static void synchronizeParents(User user, Attributes attrs) {
730 _log.info("Synchronizing parents for user "+user.getFullName());
732 ENTRolesUtil entRolesUtil = ENTRoleUtilFactory.getInstance(user.getCompanyId());
734 // Get user academic code
735 // - if uid and entPersonJointure are equal, then there is no academic code used
736 // - else the uid is entPersonJointure + academic code
737 String uid = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_UID);
738 String entPersonJointure = LDAPUtil.getAttributeString(attrs, LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONJOINTURE);
739 String academicCode = "";
740 if (!uid.equals(entPersonJointure)) {
741 academicCode = uid.substring(uid.length() - 3);
745 // Get previous user roles
746 Set<Role> userRoles = new HashSet<Role>();
747 CollectionUtils.addAll(userRoles, entRolesUtil.getENTRoles(user));
749 if (attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONPROFILS) != null){
750 for (int i=0; i<attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONPROFILS).size(); i++) {
752 Role profileRole = entRolesUtil.getRole(attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONPROFILS).get(i).toString());
754 // Student case : update parents
755 if (profileRole.getName().equals(ENTRolesConstants.NATIONAL_1)){
757 List<UserRelationship> existingRelations = UserRelationshipLocalServiceUtil.getUserRelationshipByFromUserIdRelationType(user.getUserId(), UserRelationshipConstants.PARENT_RELATION);
758 List<UserRelationship> copyeExistingRelations = new ArrayList<UserRelationship>(existingRelations);
760 // Get ENTElevePersRelEleve attributes
761 // New field in ENT2D format. Old fields are still provided in XML files but are not parsed here.
762 if (attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTELEVEPERSRELELEVE) != null) {
765 for (int k=0; k<attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTELEVEPERSRELELEVE).size(); k++) {
766 String parentDN = attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTELEVEPERSRELELEVE).get(k).toString();
768 // ENTElevePersRelEleve is the new parent format : for example uid=5841069$5$1$1$0$0,ou=people,dc=ent,dc=pentila,dc=com
769 // Build newParentDn in this format: uid=5841069024,ou=people,dc=ent,dc=pentila,dc=com
770 String newParentDn = "";
771 String[] parentDnTab = parentDN.split(",");
772 if (parentDnTab != null && parentDnTab.length > 0) {
773 String[] parentUidTab = parentDnTab[0].split("\\$");
774 if (parentUidTab != null && parentUidTab.length > 0) {
775 newParentDn = parentUidTab[0] + academicCode + parentDN.substring(parentDnTab[0].length());
779 if (newParentDn.equals("")) {
780 _log.error("Error : ENTElevePersRelEleve attribute has an incorrect value : "+parentDN);
785 // Check if existing relation. If not => create it with 'toUserId=0'
786 _log.info("Checking for student "+user.getUserId()+" if parent "+newParentDn+" exists");
787 UserRelationship rel = UserRelationshipLocalServiceUtil.checkUserRelationshipByFromUserIdToUserSconetIdRelationType(user.getUserId(), newParentDn, UserRelationshipConstants.PARENT_RELATION);
788 if (copyeExistingRelations.contains(rel)) {
789 copyeExistingRelations.remove(rel);
791 } catch (Exception e) {
792 _log.error("Error when updating relations for user "+user.getFullName(), e);
798 // Delete obsolete relations
799 for (UserRelationship oldRelation: copyeExistingRelations) {
800 UserRelationshipLocalServiceUtil.deleteUserRelationship(oldRelation);
803 } // End student case
808 } catch (Exception e) {
809 _log.error("Error when synchronizing parents for user "+user.getFullName(), e);
815 * Update user activation
820 * @throws NamingException
821 * @throws PortalException
822 * @throws SystemException
824 public static void updateUserActivation(User user, Attributes attrs, Organization school, RoleEnum roleEnum) throws NamingException, PortalException, SystemException {
827 Boolean active = null;
829 String entValidAccount = LDAPUtil.getAttributeString(attrs, "ENTValidAccount");
830 active = !entValidAccount.equals("1") && !entValidAccount.equals("2");
833 if (user.isActive()) {
834 UserLocalServiceUtil.updateStatus(user.getUserId(), WorkflowConstants.STATUS_INACTIVE);
835 SynchronizationReport.notifyDeactivation(school, user, roleEnum);
839 if (!user.isActive()) {
840 UserLocalServiceUtil.updateStatus(user.getUserId(), WorkflowConstants.STATUS_APPROVED);
841 SynchronizationReport.notifyReactivation(school, user, roleEnum);
844 } catch (Exception e) {
845 _log.error("Error when updating activation for user "+user.getFullName());
852 * Synchronizes user roles
856 * @throws UserSynchronizationException
857 * @throws PortalException
858 * @throws SystemException
859 * @throws NamingException
861 private static RoleEnum synchronizeRoles(final User user, final Attributes attrs) {
866 ENTRolesUtil entRolesUtil = ENTRoleUtilFactory.getInstance(user.getCompanyId());
868 // Get previous user roles
869 Set<Role> userRoles = new HashSet<Role>();
870 CollectionUtils.addAll(userRoles, entRolesUtil.getENTRoles(user));
872 // Loop over LDAP attributes 'ENTPersonProfils'
873 if (attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONPROFILS) != null){
874 for (int i=0; i<attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONPROFILS).size(); i++) {
876 Role profileRole = entRolesUtil.getRole(attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONPROFILS).get(i).toString());
877 if (userRoles.contains(profileRole)) {
878 userRoles.remove(profileRole);
880 long rId[] = {profileRole.getRoleId()};
881 RoleLocalServiceUtil.addUserRoles(user.getUserId(), rId);
884 if (profileRole.getName().equals(ENTRolesConstants.NATIONAL_1)) {
885 res = RoleEnum.STUDENT_ROLE;
886 } else if (profileRole.getName().equals(ENTRolesConstants.NATIONAL_2)) {
887 res = RoleEnum.PARENT_ROLE;
888 } else if (profileRole.getName().equals(ENTRolesConstants.NATIONAL_3) || profileRole.getName().equals(ENTRolesConstants.NATIONAL_26)) {
889 res = RoleEnum.TEACHER_ROLE;
893 } // End loop over ENTPersonProfils
895 // Loop over 'ENTPersonFonctions' attributes
896 if (attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONFONCTIONS)!=null){
897 for (int i=0; i<attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONFONCTIONS).size(); i++) {
898 String[] roleDescription = entRolesUtil.translateENTPersonFonctionsToRoleName(attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONFONCTIONS).get(i).toString());
899 if (roleDescription!= null) {
900 Role profileRole = entRolesUtil.getRole(roleDescription[0], roleDescription[1]);
902 if (userRoles.contains(profileRole)) {
903 userRoles.remove(profileRole);
905 long rId[] = {profileRole.getRoleId()};
906 RoleLocalServiceUtil.addUserRoles(user.getUserId(), rId);
912 // If user has role Nat_23, add role Nat_4
913 Role nat23Role = RoleLocalServiceUtil.getRole(user.getCompanyId(), ENTRolesConstants.NATIONAL_23);
914 Role nat4Role = RoleLocalServiceUtil.getRole(user.getCompanyId(), ENTRolesConstants.NATIONAL_4);
915 if (RoleLocalServiceUtil.hasUserRole(user.getUserId(), nat23Role.getRoleId())) {
916 if (userRoles.contains(nat4Role)) {
917 userRoles.remove(nat4Role);
919 long roleIds[] = {nat4Role.getRoleId()};
920 RoleLocalServiceUtil.addUserRoles(user.getUserId(), roleIds);
921 _log.info("Add role Nat4 to user "+user.getFullName());
925 // If user is National_4 => add it to GROUP_ADMIN
926 if (RoleLocalServiceUtil.hasUserRole(user.getUserId(), nat4Role.getRoleId())) {
928 Role grpAdminRole = entRolesUtil.getRole("Group_admin");
929 if (userRoles.contains(grpAdminRole)) {
930 userRoles.remove(grpAdminRole);
932 long roleIds[] = {grpAdminRole.getRoleId()};
933 RoleLocalServiceUtil.addUserRoles(user.getUserId(), roleIds);
934 _log.info("Add role Group_admin to user "+user.getFullName());
938 // Remove obsolete roles
939 for (Role r : userRoles) {
940 RoleLocalServiceUtil.unsetUserRoles(user.getUserId(), new long[]{r.getRoleId()});
944 // Add default role if user has no role
945 Role[] endedRoles = entRolesUtil.getENTRoles(user);
946 if (endedRoles.length == 0) {
947 // on ajoute le role par defaut si possible
948 String default_role = ENTMainUtilsLocalServiceUtil.getENTSynchroDefaultRole(user.getCompanyId());
949 if (!default_role.equals("")) {
951 Role defaultRole = entRolesUtil.getRole(default_role);
952 long rId[] = {defaultRole.getRoleId()};
953 RoleLocalServiceUtil.addUserRoles(user.getUserId(), rId);
955 catch(Exception exc) {
956 _log.error("Error when adding default role to user "+user.getFullName());
960 } catch (Exception e) {
961 _log.error("Error when synchronizing roles for user "+user.getFullName()+" (id "+user.getUserId()+")", e);
964 // Default RoleEnum is OTHER_ROLE
966 res = RoleEnum.OTHER_ROLE;
976 public static UserGroup synchronizeGroup(long companyId, Attributes attrs, String fullGroupDn) throws Exception {
978 ENTAttributesTransformer attrsTransformer = ENTAttributesTransformerFactory.getInstance();
980 attrs = attrsTransformer.transformGroup(attrs);
982 Properties groupMappings = PortalLDAPUtil.getGroupMappings(companyId);
984 LogUtil.debug(_log, groupMappings);
986 String groupName = LDAPUtil.getAttributeString(attrs, groupMappings.getProperty("groupName")).toLowerCase();
987 String description = LDAPUtil.getAttributeString(attrs, groupMappings.getProperty("description"));
989 // Check if empty LDAP group
990 Boolean emptyLDAPGrp = PortalLDAPUtil.isEmptyENTLDAPGroup(groupMappings, attrs);
993 //removeEmptyLdapGroup(companyId, groupName);
996 Date ldapGroupModifiedDate = null;
997 String modifiedDate = LDAPUtil.getAttributeString(attrs, "modifyTimestamp");
999 if (!Validator.isNull(modifiedDate)) {
1000 ldapGroupModifiedDate = dateFormat.parse(modifiedDate);
1002 } catch (ParseException pe) {
1005 // Get or create user group
1006 UserGroup userGroup = getOrCreateUserGroup(companyId, groupName, description);
1009 // Import users and membership
1010 if (userGroup != null) {
1011 // Get'member' user list
1012 Attribute memberList = attrs.get(groupMappings.getProperty("user"));
1014 if (memberList != null) {
1015 List<String> membersToRemoveFromGroup = getExpiredUsers(companyId, userGroup.getUserGroupId(), memberList, ldapGroupModifiedDate);
1017 // Previous method returned the list of members of the group that do not exist anymore in people branch
1018 // Let's remove these members from the current group
1020 if (membersToRemoveFromGroup != null && membersToRemoveFromGroup.size() > 0) {
1022 Attribute memberListCopy = (Attribute) memberList.clone();
1023 int countUser = memberList.size();
1025 // Loop over existing members
1026 boolean isMemberListChanged = false;
1027 for (int i = 0; i < countUser; i++) {
1028 String attrValue = (String) memberList.get(i);
1030 // Check if the current member belong to the 'toRemove' list
1031 for (String memberToRemove : membersToRemoveFromGroup) {
1032 if (memberToRemove.equals(attrValue)) {
1033 _log.info("Removing user : "+memberToRemove + " from group "+fullGroupDn);
1034 isMemberListChanged = true;
1035 memberListCopy.remove(attrValue);
1039 if (isMemberListChanged) {
1040 ModificationItem[] modifItemArray = new ModificationItem[1];
1041 ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, memberListCopy);
1042 modifItemArray[0] = item;
1043 _log.info("Modifying attribute 'members' for group "+fullGroupDn);
1045 PortalLDAPUtil.getContext(companyId).modifyAttributes(fullGroupDn, modifItemArray);
1048 } catch (Exception e) {
1049 _log.error("An error occured during member deletion in group "+fullGroupDn+" (group must not have 0 members)");
1057 private static UserGroup getOrCreateUserGroup(long companyId, String groupName, String description) {
1059 UserGroup userGroup = null;
1062 userGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, groupName);
1063 UserGroupLocalServiceUtil.updateUserGroup(companyId, userGroup.getUserGroupId(), groupName, description);
1065 } catch (NoSuchUserGroupException nsuge) {
1066 _log.info("Adding user group to portal " + groupName);
1069 long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
1070 userGroup = UserGroupLocalServiceUtil.addUserGroup(defaultUserId, companyId, groupName, description);
1071 } catch (Exception e) {
1072 _log.warn("Could not create user group " + groupName);
1074 } catch (Exception e) {
1075 _log.error("Error when getting or creating usergroup with groupName="+groupName);
1081 * Remove an empty LDAP group, remove its associated UserGroup and Organization, by previoulsy removing users from them
1085 private static void removeEmptyLdapGroup(long companyId, String groupName) {
1087 System.out.println("Remove empty LDAP group "+groupName);
1088 long time0 = System.currentTimeMillis();
1089 SynchronizationReport.addEmptyGroup();
1090 UserGroup userGroupToDelete = null;
1091 String orgNameToDelete = "";
1093 // le groupe est vide donc on supprime
1094 userGroupToDelete = UserGroupLocalServiceUtil.getUserGroup(companyId, groupName);
1096 orgNameToDelete = SynchronizationUtils.getOrgName(userGroupToDelete);
1097 System.out.println("Delete group cause empty LDAP: org name is " + orgNameToDelete);
1099 // Remove users from this usergroup in DB
1100 System.out.println("Deleting all users belonging to obsolete user group "+userGroupToDelete.getName());
1101 UserLocalServiceUtil.clearUserGroupUsers(userGroupToDelete.getUserGroupId());
1103 // Remove the usergroup itself
1104 System.out.println("Deleting obsolete user group "+userGroupToDelete.getName());
1105 UserGroupLocalServiceUtil.deleteUserGroup(userGroupToDelete);
1107 } catch (NoSuchUserGroupException nsuge) {
1109 } catch (Exception e) {
1110 _log.error("Error when deleting user group "+groupName);
1113 if (orgNameToDelete.isEmpty()) {
1117 long time1 = System.currentTimeMillis();
1118 System.out.println("Delete user group took "+(time1 - time0)+" ms");
1119 System.out.println("About to delete organization "+orgNameToDelete);
1120 Organization org = null;
1122 org = OrganizationLocalServiceUtil.getOrganization(companyId, orgNameToDelete);
1123 long[] userIdsToRemoveFromOrg = UserLocalServiceUtil.getOrganizationUserIds(org.getOrganizationId());
1124 _log.info("This organization has "+userIdsToRemoveFromOrg.length +" members that we remove first");
1125 UserLocalServiceUtil.unsetOrganizationUsers(org.getOrganizationId(), userIdsToRemoveFromOrg);
1126 OrganizationLocalServiceUtil.deleteOrganization(org);
1127 _log.info("Organization deleted : "+orgNameToDelete);
1129 } catch (Exception e) {
1132 _log.info("About to delete organization " + orgNameToDelete + OrganizationConstants.ORG_SUFFIX_PARENTS);
1133 Organization orgParent = null;
1135 orgParent = OrganizationLocalServiceUtil.getOrganization(companyId, orgNameToDelete + OrganizationConstants.ORG_SUFFIX_PARENTS);
1136 long[] userIdsToRemoveFromOrg = UserLocalServiceUtil.getOrganizationUserIds(orgParent.getOrganizationId());
1137 _log.info("This parent organization has "+userIdsToRemoveFromOrg.length +" members that we remove first");
1138 UserLocalServiceUtil.unsetOrganizationUsers(orgParent.getOrganizationId(), userIdsToRemoveFromOrg);
1139 OrganizationLocalServiceUtil.deleteOrganization(orgParent);
1140 _log.info("Organization parent deleted : " + orgNameToDelete + OrganizationConstants.ORG_SUFFIX_PARENTS);
1142 } catch (Exception e) {
1144 long time2 = System.currentTimeMillis();
1145 System.out.println("Delete organization took "+(time2 - time1)+" ms");
1152 private static List<String> getExpiredUsers(long companyId, long userGroupId, Attribute memberList, Date ldapGroupModifiedDate) throws Exception {
1154 List<String> membersToRemoveFromGroup = new ArrayList<String>();
1156 long time0 = System.currentTimeMillis();
1157 int nbUsersProcessed = 0;
1158 int countUser = memberList.size();
1160 // Loop over member list
1161 for (int i = 0; i < countUser; i++) {
1163 if (nbUsersProcessed%1000==0) {
1164 _log.info("Processed "+nbUsersProcessed + "/" + countUser + " users in this group");
1167 // Find user in LDAP
1168 String fullUserDN = (String) memberList.get(i);
1171 // Empty group (with fake_user only)
1172 if (fullUserDN.equals("uid=system_fake_user") ) {
1176 // Get user if he was already imported during this sync process
1177 if (userEverImported.containsKey(fullUserDN)) {
1178 Long userTmpId = userEverImported.get(fullUserDN);
1179 if (userTmpId == null) {
1182 user = UserLocalServiceUtil.getUser(userTmpId);
1187 // Get user attributes
1189 PortalLDAPUtil.getUserAttributes(companyId, fullUserDN);
1190 } catch (NameNotFoundException nnfe) {
1192 _log.info("LDAP user not found with fullUserDN " + fullUserDN + " : adding it to deletion list from current group");
1194 // Delete 'member' attribute from the group in LDAP if the user does not exist anymore (deleted because ENTValidAccount=2)
1195 membersToRemoveFromGroup.add(fullUserDN);
1196 SynchronizationReport.addExpiredUser();
1199 } catch (Exception ioexc) {
1200 _log.error("Error with LDAP connection");
1204 userEverImported.put(fullUserDN, (user==null?null:user.getUserId()));
1209 long time1 = System.currentTimeMillis();
1210 _log.info("Group synchronization for usergroupid "+userGroupId+ " took "+(time1 - time0)+" ms");
1211 return membersToRemoveFromGroup;
1218 * Initializes static variables etabMap and etabOuMap
1222 public static void initializeSchoolMaps() {
1224 etabMap = new HashMap<String, Organization>();
1225 etabOuMap = new HashMap<String, String>();
1228 String[] attrs2fetchForEtab = {LDAPConstants.LDAP_ATTRIBUTE_ENTSTRUCTURENOMCOURANT, "l", LDAPConstants.LDAP_ATTRIBUTE_ENTSTRUCTUREUAI, "ou"};
1230 NamingEnumeration<SearchResult> ldapEtabs = PortalLDAPUtil.getAllEtabs(companyId, attrs2fetchForEtab);
1231 while (ldapEtabs.hasMoreElements()) {
1233 SearchResult result = ldapEtabs.nextElement();
1234 Attributes schoolAttributes = result.getAttributes();
1237 String etabDn = "ou=" + schoolAttributes.get("ou").get().toString() + ",ou=etablissements,"+PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_DN);
1238 etabOuMap.put(schoolAttributes.get("ou").get().toString(), schoolAttributes.get(LDAPConstants.LDAP_ATTRIBUTE_ENTSTRUCTUREUAI).get().toString());
1239 _log.info("Building etabOuMap : adding ou="+schoolAttributes.get("ou").get().toString()+" mapped to ENTStructureUAI="+schoolAttributes.get(LDAPConstants.LDAP_ATTRIBUTE_ENTSTRUCTUREUAI).get().toString());
1241 OrganizationMapping orgMapping = null;
1242 Organization etabOrg = null;
1244 orgMapping = OrganizationMappingLocalServiceUtil.getOrganizationMapping(schoolAttributes.get(LDAPConstants.LDAP_ATTRIBUTE_ENTSTRUCTUREUAI).get().toString());
1245 etabOrg = OrganizationLocalServiceUtil.getOrganization(orgMapping.getOrganizationId());
1246 if (etabOrg != null) {
1247 etabMap.put(etabDn, etabOrg);
1248 _log.info("Building etabMap : adding etabDn="+etabDn+" mapped to etabOrg="+etabOrg.getName());
1250 } catch (Exception e) {
1251 _log.error("Organization mapping not existing for UAI="+schoolAttributes.get(LDAPConstants.LDAP_ATTRIBUTE_ENTSTRUCTUREUAI).get().toString());
1255 // Create school if needed
1256 if (etabOrg == null) {
1257 String newSchoolName = schoolAttributes.get(LDAPConstants.LDAP_ATTRIBUTE_ENTSTRUCTURENOMCOURANT).get().toString();
1259 _log.info("About to create new school named "+newSchoolName);
1260 etabOrg = ENTOrganizationsUtil.getOrCreateSchool(companyId, newSchoolName);
1261 } catch (Exception e) {
1262 _log.error("Error when creating school named "+newSchoolName, e);
1265 // Create org mapping
1266 OrganizationMappingLocalServiceUtil.addOrganizationMapping(etabOrg, schoolAttributes.get(LDAPConstants.LDAP_ATTRIBUTE_ENTSTRUCTUREUAI).get().toString());
1268 _log.info("Added dn "+etabDn+" to school "+etabOrg.getName()+" in etabMap.");
1269 etabMap.put(etabDn, etabOrg);
1274 catch (Exception exc) {
1275 _log.error("Error in initializeSchoolMaps for o", exc);
1282 * Add the given user to the '-Parent' or '- Personnels' or '- Enseignants' sub-orgs
1286 private static void synchronizeSchoolLevelOrganizations (long companyId, User user, Attributes attrs, boolean manualCreation) {
1288 // Skip inactive users
1289 if (user.getStatus() == WorkflowConstants.STATUS_INACTIVE) {
1293 Boolean hasTeacherGrp = false;
1294 Boolean hasPersonnelGrp = false;
1295 Boolean hasParentGrp = false;
1296 Boolean isParentUser = false;
1297 Boolean analyzeSchoolComplex = false;
1299 long userId = user.getUserId();
1302 // Add user to root organization
1303 Organization rootOrg = ENTOrganizationsUtil.getOrCreateRootOrg(user.getCompanyId());
1304 if (!UserLocalServiceUtil.hasOrganizationUser(rootOrg.getOrganizationId(), user.getUserId()) ) {
1305 UserLocalServiceUtil.addOrganizationUsers(rootOrg.getOrganizationId(), new long[]{user.getUserId()});
1308 Organization rattachSchool = null;
1309 if (manualCreation) {
1310 // Get 'ENTPersonStructRattach' attribute
1311 String entPersonStructRattach = attrs.get("ENTPersonStructRattach").get().toString();
1312 _log.info("Manual creation : entPersonStructRattach="+entPersonStructRattach);
1313 rattachSchool = SynchronizationUtils.getSchoolFromClassName(entPersonStructRattach);
1316 rattachSchool = getRattachSchool(user);
1318 if (rattachSchool == null) {
1319 _log.error("No rattach school found for user "+user.getFullName());
1324 // Add user to this etab if not present
1325 boolean addRattachSchool = false;
1326 if (!OrganizationLocalServiceUtil.hasUserOrganization(user.getUserId(), rattachSchool.getOrganizationId())) {
1327 _log.info("synchronizeSchoolLevelOrganizations : adding user "+user.getFullName()+" to school "+rattachSchool.getName());
1328 UserLocalServiceUtil.addOrganizationUsers(rattachSchool.getOrganizationId(), new long[]{user.getUserId()});
1329 addRattachSchool = true;
1332 // Update rattach school in user properties
1333 UserProperties userProp = UserPropertiesLocalServiceUtil.getUserPropertiesByUserId(user.getUserId());
1334 userProp.setEtabId(rattachSchool.getOrganizationId());
1335 UserPropertiesLocalServiceUtil.updateUserProperties(userProp);
1338 List<Role> userRolesList = RoleLocalServiceUtil.getUserRoles(userId);
1340 // Loop over the user's roles to detect school-level orgs
1341 for (Role userRole : userRolesList) {
1343 if (userRole.getName().equals(ENTRolesConstants.NATIONAL_1)) {
1344 if (addRattachSchool) {
1345 SynchronizationReport.notifyStudentMembershipCreation(user, rattachSchool);
1350 if (userRole.getName().equals(ENTRolesConstants.NATIONAL_2)
1351 || userRole.getName().equals(ENTRolesConstants.NATIONAL_4)
1352 || userRole.getName().equals(ENTRolesConstants.NATIONAL_25)) {
1353 hasParentGrp = true;
1357 if (userRole.getName().equals(ENTRolesConstants.NATIONAL_3)
1358 || userRole.getName().equals(ENTRolesConstants.NATIONAL_24)
1359 || userRole.getName().equals(ENTRolesConstants.NATIONAL_25)) {
1360 if (addRattachSchool) {
1361 SynchronizationReport.notifyTeacherMembershipCreation(user, rattachSchool);
1363 hasTeacherGrp = true;
1367 if (userRole.getName().equals(ENTRolesConstants.NATIONAL_3)
1368 || userRole.getName().equals(ENTRolesConstants.NATIONAL_4)
1369 || userRole.getName().equals(ENTRolesConstants.NATIONAL_5)
1370 || userRole.getName().equals(ENTRolesConstants.NATIONAL_6)
1371 || userRole.getName().equals(ENTRolesConstants.NATIONAL_7)
1372 || userRole.getName().equals(ENTRolesConstants.NATIONAL_25)) {
1373 hasPersonnelGrp = true;
1374 // Add membership to school except for Nat_3 (done before)
1375 if (addRattachSchool && !userRole.getName().equals(ENTRolesConstants.NATIONAL_3)) {
1376 SynchronizationReport.notifyOtherMembershipCreation(user, rattachSchool);
1381 if (userRole.getName().equals(ENTRolesConstants.NATIONAL_4)
1382 || userRole.getName().equals(ENTRolesConstants.NATIONAL_5)
1383 || userRole.getName().equals(ENTRolesConstants.NATIONAL_6)
1384 || userRole.getName().equals(ENTRolesConstants.NATIONAL_7)) {
1385 analyzeSchoolComplex = true;
1390 // Add parents to org
1391 SynchronizationUtils.addOrRemoveUserFromOrg(user, rattachSchool, hasParentGrp, OrganizationConstants.ORG_SUFFIX_PARENTS);
1396 // Add teachers to orgs
1397 SynchronizationUtils.addOrRemoveUserFromOrg(user, rattachSchool, hasTeacherGrp, OrganizationConstants.ORG_SUFFIX_TEACHERS);
1399 // Add personnel to orgs
1400 SynchronizationUtils.addOrRemoveUserFromOrg(user, rattachSchool, hasPersonnelGrp, OrganizationConstants.ORG_SUFFIX_PERSONNELS);
1402 // If school complex => add user into other etabs from the school complex
1403 if (analyzeSchoolComplex) {
1404 List<Long> etabIdList = getSchoolComplexAttachedEtabs(rattachSchool.getOrganizationId());
1405 for (Long etabIdToAttach : etabIdList) {
1406 _log.info("Adding user "+user.getFullName()+" to complex school "+etabIdToAttach);
1407 Organization org = OrganizationLocalServiceUtil.getOrganization(etabIdToAttach);
1408 SynchronizationUtils.addOrRemoveUserFromOrg(user, org, true, "");
1412 // If the user is etab manager, add it to principal organization
1413 if (attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONFONCTIONS) != null && attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONFONCTIONS).toString().endsWith("CHEF D'ETABLISSEMENT")) {
1414 long groupId = rattachSchool.getGroup().getGroupId();
1415 long[] roleIds = {RoleLocalServiceUtil.getRole(user.getCompanyId(), ENTRolesConstants.SCHOOL_MANAGER).getRoleId()};
1416 UserGroupRoleLocalServiceUtil.addUserGroupRoles(userId, groupId, roleIds);
1420 } catch (Exception e) {
1421 _log.error("Error when synchronizing school-level organizations for user "+user.getFullName()+ "(id "+user.getUserId()+")", e);
1427 private static void synchronizeGroups() {
1429 long groupSyncAll0 = System.currentTimeMillis();
1431 String importMethod = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_IMPORT_METHOD);
1433 if (importMethod.equals(OrganizationConstants.IMPORT_BY_USER)) {
1436 } else if (importMethod.equals(OrganizationConstants.IMPORT_BY_GROUP)) {
1438 // Build the group list
1439 Set<String> grpProcessed = new HashSet<String>();
1440 NamingEnumeration<SearchResult> enu = PortalLDAPUtil.getGroups(companyId, 0);
1441 while (enu.hasMoreElements()) {
1442 SearchResult result = enu.nextElement();
1443 grpProcessed.add(PortalLDAPUtil.getNameInNamespace(companyId, result));
1447 int totalGrp = grpProcessed.size();
1449 // Loop through all LDAP groups
1450 for (String grpDN: grpProcessed){
1453 _log.info("Importing GRP: " + count + "/" + totalGrp + " : "+grpDN);
1455 // Run the sync for 1 given group
1457 Attributes attrs = PortalLDAPUtil.getGroupAttributes(companyId, grpDN, true);
1458 synchronizeGroup(companyId, attrs, grpDN);
1460 } catch(Exception grpImportExcept) {
1461 _log.error("Error during import group "+ grpDN);
1465 } catch (Exception e) {
1466 _log.error("Error importing LDAP users and groups", e);
1468 long groupSyncAll1 = System.currentTimeMillis();
1469 int groupSyncTime = (int)((groupSyncAll1 - groupSyncAll0)/60000);
1470 SynchronizationReport.setGroupSyncTime(groupSyncTime);
1476 * Update parent relationships for just created users
1477 * Previously created relationships have toUserId set to 0 because the parent may not exist yet when the relationship is created
1479 private static void updateParentRelations() {
1481 List<UserRelationship> relationsToComplete = UserRelationshipLocalServiceUtil.getUserRelationshipByToUserIdRelationType(0, UserRelationshipConstants.PARENT_RELATION);
1482 if (relationsToComplete != null) {
1483 for (UserRelationship relation : relationsToComplete) {
1486 // Extract uid from 'toUserSconetId' field (Example uid=123456,ou=people,dc=cartabledesavoie,dc=com)
1487 String[] sconetIdTab = relation.getToUserSconetId().split(",");
1488 if (sconetIdTab != null && sconetIdTab.length > 0) {
1489 String uid = sconetIdTab[0].substring(4);
1490 _log.info("updateParentRelations : trying to map uid="+uid+" with existing userId");
1491 User parentUser = LDAPMappingLocalServiceUtil.getUserFromUID(uid);
1492 relation.setToUserId(parentUser.getUserId());
1493 UserRelationshipLocalServiceUtil.updateUserRelationship(relation);
1494 _log.info("updateParentRelations : updated relationship with uid="+uid+" with parent userId = "+parentUser.getUserId());
1495 User child = UserLocalServiceUtil.getUser(relation.getFromUserId());
1496 SynchronizationReport.addChildParentLink(child, parentUser);
1498 } catch (Exception e) {
1499 _log.error("Error when updating parent relationship for relation with fromId="+relation.getFromUserId(), e);
1503 } catch (SystemException e) {
1504 _log.error("Error when updating parent relationships", e);
1509 * Returns the list of schools related to the given school id through a school complex
1511 * @return the list of related school ids
1513 public static List<Long> getSchoolComplexAttachedEtabs(long etabId) {
1514 List<Long> result = new ArrayList<Long>();
1515 List<OrganizationCiteScolaire> orgaCiteScolaireList;
1518 // Get ENTStructureUAI of etabId (orgId)
1519 String entStructureUAI = "";
1520 List<OrganizationMapping> orgMappingList = OrganizationMappingLocalServiceUtil.getOrganizationMappings(-1, -1);
1521 for (OrganizationMapping orgMapping : orgMappingList) {
1522 if (orgMapping.getOrganizationId() == etabId) {
1523 entStructureUAI = orgMapping.getEntStructureUAI();
1527 // Get parent ENTStructureUAI
1528 String parentENTStructureUAI = "";
1529 orgaCiteScolaireList = OrganizationCiteScolaireLocalServiceUtil.getOrganizationCiteScolaires(-1, -1);
1530 if (orgaCiteScolaireList != null) {
1531 for (OrganizationCiteScolaire orgaCiteScolaire : orgaCiteScolaireList) {
1532 if (orgaCiteScolaire.getParentENTStructureUAI().equals(entStructureUAI)) {
1533 parentENTStructureUAI = entStructureUAI;
1535 if (orgaCiteScolaire.getChildENTStructureUAI().equals(entStructureUAI)) {
1536 parentENTStructureUAI = orgaCiteScolaire.getParentENTStructureUAI();
1541 // Get child organizations of the found parent
1542 if (!parentENTStructureUAI.equals("") && orgaCiteScolaireList != null) {
1543 for (OrganizationCiteScolaire orgaCiteScolaire : orgaCiteScolaireList) {
1544 if (orgaCiteScolaire.getParentENTStructureUAI().equals(parentENTStructureUAI)) {
1545 // Get etabId associated to the child entStructureUAI
1546 long childId = OrganizationMappingLocalServiceUtil.getOrganizationMapping(orgaCiteScolaire.getChildENTStructureUAI()).getOrganizationId();
1547 if (childId != etabId) {
1548 _log.warn("School complex : adding child "+childId);
1549 result.add(new Long(childId));
1551 // Get etabId associated to the parent entStructureUAI
1552 long parentId = OrganizationMappingLocalServiceUtil.getOrganizationMapping(orgaCiteScolaire.getParentENTStructureUAI()).getOrganizationId();
1553 if (parentId != etabId && !result.contains(new Long(parentId))) {
1554 _log.warn("School complex : adding parent "+parentId);
1555 result.add(new Long(parentId));
1562 } catch (SystemException e) {
1563 } catch (PortalException e) {
1569 * Initialize the scolar cities
1573 private static void initializeSchoolComplexes() throws Exception {
1575 _log.info("Initializing school complexes ...");
1577 String[] attrs2fetchForEtab = {"ENTStructureNomCourant", "l", "ENTStructureUAI", "ou", "ENTStructureJointure", "ENTEtablissementStructRattachFctl"};
1578 NamingEnumeration<SearchResult> ldapEtabs = PortalLDAPUtil.getAllEtabs(companyId, attrs2fetchForEtab);
1579 while (ldapEtabs.hasMoreElements()) {
1580 SearchResult result = ldapEtabs.nextElement();
1581 Attributes attrs = result.getAttributes();
1584 // Get 'ENTEtablissementStructRattachFctl' attribute to get school complexes
1585 if (attrs.get("ENTEtablissementStructRattachFctl") != null && attrs.get("ENTStructureJointure") != null) {
1586 String entStructureUAIStr1 = attrs.get("ENTStructureUAI").get().toString();
1587 //String entStructureJointureStr1 = attrs.get("ENTStructureJointure").get().toString();
1588 String etabStructRattachFctlStr = attrs.get("ENTEtablissementStructRattachFctl").get().toString();
1590 // Format is ou=xxxx,ou=etablissements,dc=ent,dc=pentila,dc=com. We want to get xxxx
1591 String entStructureJointureCiteScolaire = "";
1592 String[] etabStructRattachFctlTab = etabStructRattachFctlStr.split(",");
1593 if (etabStructRattachFctlTab != null && etabStructRattachFctlTab.length > 1) {
1594 String ouCite = etabStructRattachFctlTab[0];
1595 entStructureJointureCiteScolaire = ouCite.substring(3);
1598 String mappedEntStructureUAI = "";
1600 // Loop again over etabs to get the ENTStructureUAI of the given ENTStructureJointure
1601 NamingEnumeration<SearchResult> ldapEtabs2 = PortalLDAPUtil.getAllEtabs(companyId, attrs2fetchForEtab);
1602 while (ldapEtabs2.hasMoreElements()) {
1603 SearchResult result2 = ldapEtabs2.nextElement();
1604 Attributes attrs2 = result2.getAttributes();
1607 // Get 'ENTEtablissementStructRattachFctl' attribute to get scolar cities
1608 if (attrs2.get("ENTStructureUAI") != null && attrs2.get("ENTStructureJointure") != null) {
1609 String entStructureJointureStr2 = attrs2.get("ENTStructureJointure").get().toString();
1610 String entStructureUAIStr2 = attrs2.get("ENTStructureUAI").get().toString();
1612 if (entStructureJointureStr2.equals(entStructureJointureCiteScolaire)) {
1613 mappedEntStructureUAI = entStructureUAIStr2;
1617 catch (Exception exc) {
1618 _log.error("error in initializeCiteScolaire");
1622 // Cite scolaire does not have parent and child ENTStructureUAI equal
1623 if (!mappedEntStructureUAI.equals("0") && !mappedEntStructureUAI.equals("") && !mappedEntStructureUAI.equals(entStructureUAIStr1)) {
1625 OrganizationCiteScolaireLocalServiceUtil.addOrganizationCiteScolaire(mappedEntStructureUAI, entStructureUAIStr1);
1626 _log.info("Added cite scolaire between "+mappedEntStructureUAI+" and "+entStructureUAIStr1+".");
1631 catch (Exception exc) {
1632 _log.error("error in initializeCiteScolaire");
1640 * Build the static maps that contain user infos
1642 private static void buildUserMaps() {
1644 _log.info("Building user map ...");
1646 String[] attrs2fetch = {LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONSTRUCTRATTACH, LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONLOGIN, LDAPConstants.LDAP_ATTRIBUTE_ENTELEVECLASSES, LDAPConstants.LDAP_ATTRIBUTE_ENTELEVEGROUPES, LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONFONCTIONS, LDAPConstants.LDAP_ATTRIBUTE_ENTAUXENSCLASSES, LDAPConstants.LDAP_ATTRIBUTE_ENTAUXENSGROUPES, LDAPConstants.LDAP_ATTRIBUTE_ENTAUXENSCLASSESPRINCIPAL, LDAPConstants.LDAP_ATTRIBUTE_ENTAUXENSMATIEREENSEIGNETAB};
1648 // Loop over all users in LDAP
1649 NamingEnumeration<SearchResult> ldapUsers = PortalLDAPUtil.getUsers(companyId, 0, attrs2fetch);
1650 while (ldapUsers.hasMoreElements()) {
1652 SearchResult result = ldapUsers.nextElement();
1653 Attributes attrs = result.getAttributes();
1655 // Build the user map
1656 if (attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONLOGIN) == null) {
1657 _log.error("User has no ENTPersonLogin");
1660 if (attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONSTRUCTRATTACH) == null) {
1661 _log.error("User "+attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONLOGIN).get().toString()+" has no ENTPersonStructRattach");
1664 userRattachSchoolMap.put(attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONLOGIN).get().toString(), attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONSTRUCTRATTACH).get().toString());
1665 userAttributesMap.put(attrs.get(LDAPConstants.LDAP_ATTRIBUTE_ENTPERSONLOGIN).get().toString(), attrs);
1668 } catch (Exception e) {
1669 _log.error("Error while building user map", e);
1671 _log.info("Built user map with "+userRattachSchoolMap.size()+" users.");
1676 * Get the rattach school based on the global maps
1680 public static Organization getRattachSchool(User user) {
1682 //_log.info("In getRattachSchool : userRattachSchoolMap has "+userRattachSchoolMap.size()+" entries and etabMap has "+etabMap.keySet().size()+" entries");
1684 // Get rattach school
1685 Organization etabRattachement = null;
1687 if (!userRattachSchoolMap.containsKey(user.getScreenName())) {
1688 _log.error("User "+user.getScreenName()+" is not in the user map");
1691 String etabUserDn = userRattachSchoolMap.get(user.getScreenName());
1692 etabRattachement = etabMap.get(etabUserDn);
1694 catch (Exception e) {
1695 _log.error("No attached school in LDAP for user "+ user.getFullName(), e);
1698 if (etabRattachement == null) {
1699 _log.error("No attached school in LDAP for user " + user.getFullName());
1701 return etabRattachement;
1707 * Send email to technical team at synchronization's end
1709 private static void sendSynchronizationEndMail(Date startSynchroTime, Date endSynchroTime) {
1711 _log.info("Sending synchronization END email ...");
1714 // Get mail source and target
1715 String synchroEndMail = ENTMainUtilsLocalServiceUtil.getSupportMail();
1717 // Get platform name
1718 String platformName = ENTMainUtilsLocalServiceUtil.getPlatform();
1719 if (platformName == null || platformName.equals("")) {
1723 // Format synchro duration
1724 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
1725 long durationMillis = endSynchroTime.getTime() - startSynchroTime.getTime();
1726 int durationMinutes = (int)Math.floor(durationMillis / (60 * 1000) % 60);
1727 int durationHours = (int)Math.floor(durationMillis / (60 * 60 * 1000));
1729 String duration = durationHours + " hours and " + durationMinutes + " minutes";
1730 String report = SynchronizationReport.generateSynchroReport();
1732 String synchroEndMailSubject = "Synchronization ended on "+platformName;
1733 String synchroEndMailContent = "Hello,</br></br>The synchronization process has ended on platform "+platformName+".</br></br>"
1734 + "Start time : "+sdf.format(startSynchroTime)+"</br>"
1735 + "End time : "+sdf.format(endSynchroTime)+"</br>"
1736 + "Duration : "+duration+"</br></br>"
1737 + report+"</br></br>"
1738 + "The technical team</br>";
1740 // Build and send mail
1741 MailMessage mailMessage = new MailMessage();
1742 mailMessage.setHTMLFormat(true);
1743 mailMessage.setFrom(new InternetAddress(synchroEndMail));
1744 mailMessage.setTo(new InternetAddress(synchroEndMail));
1745 mailMessage.setSubject(synchroEndMailSubject);
1746 mailMessage.setBody(synchroEndMailContent);
1748 MailServiceUtil.sendEmail(mailMessage);
1750 } catch (Exception e) {
1751 _log.error("Error while sending end synchronization mail");
1753 _log.info("Sent synchronization END email ...");
1757 * Is the import enabled in the portal-ext.properties file ?
1760 * @throws SystemException
1762 private static boolean isImportEnabled(long companyId) throws SystemException {
1763 return PrefsPropsUtil.getBoolean(companyId, PropsKeys.LDAP_IMPORT_ENABLED, PropsValues.LDAP_IMPORT_ENABLED);
1766 private static void initCompanyId () {
1768 List<Company> companies = CompanyLocalServiceUtil.getCompanies(false);
1769 for (Company company : companies) {
1770 companyId = company.getCompanyId();
1772 } catch (Exception e) {
1776 private static void processCreatedUsers() {
1777 if (createdUserList != null) {
1778 for (User createdUser : createdUserList) {
1781 Organization school = getRattachSchool(createdUser);
1783 List<Role> userRoles = RoleLocalServiceUtil.getUserRoles(createdUser.getUserId());
1784 for (Role userRole : userRoles) {
1785 if (userRole.getName().equals(ENTRolesConstants.NATIONAL_1)) {
1786 SynchronizationReport.notifyCreation(school, createdUser, RoleEnum.STUDENT_ROLE);
1788 } else if (userRole.getName().equals(ENTRolesConstants.NATIONAL_2)) {
1789 SynchronizationReport.notifyCreation(school, createdUser, RoleEnum.PARENT_ROLE);
1791 } else if (userRole.getName().equals(ENTRolesConstants.NATIONAL_3)) {
1792 SynchronizationReport.notifyCreation(school, createdUser, RoleEnum.TEACHER_ROLE);
1797 SynchronizationReport.notifyCreation(school, createdUser, RoleEnum.OTHER_ROLE);
1798 } catch (Exception e) {
1799 _log.error("Error when processing newly created user "+createdUser, e);
1806 public static Map<String, Organization> getEtabMap() {
1810 public static Map<String, String> getEtabOuMap() {
1814 public static Map<String, Long> getUserEverImported() {
1815 return userEverImported;
1818 public static Map<String, String> getUserRattachSchoolMap() {
1819 return userRattachSchoolMap;
1822 public static Map<String, Attributes> getUserAttributesMap() {
1823 return userAttributesMap;
1826 public static void initUserRattachSchoolMap() {
1827 userRattachSchoolMap = new HashMap<String, String>();
1830 public enum RoleEnum {