2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portal.service.impl;
\r
17 import com.liferay.portal.CompanyMaxUsersException;
\r
18 import com.liferay.portal.ContactBirthdayException;
\r
19 import com.liferay.portal.ContactFirstNameException;
\r
20 import com.liferay.portal.ContactFullNameException;
\r
21 import com.liferay.portal.ContactLastNameException;
\r
22 import com.liferay.portal.DuplicateUserEmailAddressException;
\r
23 import com.liferay.portal.DuplicateUserScreenNameException;
\r
24 import com.liferay.portal.GroupFriendlyURLException;
\r
25 import com.liferay.portal.ModelListenerException;
\r
26 import com.liferay.portal.NoSuchContactException;
\r
27 import com.liferay.portal.NoSuchGroupException;
\r
28 import com.liferay.portal.NoSuchOrganizationException;
\r
29 import com.liferay.portal.NoSuchRoleException;
\r
30 import com.liferay.portal.NoSuchTicketException;
\r
31 import com.liferay.portal.NoSuchUserException;
\r
32 import com.liferay.portal.NoSuchUserGroupException;
\r
33 import com.liferay.portal.PasswordExpiredException;
\r
34 import com.liferay.portal.RequiredUserException;
\r
35 import com.liferay.portal.ReservedUserEmailAddressException;
\r
36 import com.liferay.portal.ReservedUserScreenNameException;
\r
37 import com.liferay.portal.UserEmailAddressException;
\r
38 import com.liferay.portal.UserIdException;
\r
39 import com.liferay.portal.UserLockoutException;
\r
40 import com.liferay.portal.UserPasswordException;
\r
41 import com.liferay.portal.UserPortraitSizeException;
\r
42 import com.liferay.portal.UserPortraitTypeException;
\r
43 import com.liferay.portal.UserReminderQueryException;
\r
44 import com.liferay.portal.UserScreenNameException;
\r
45 import com.liferay.portal.UserSmsException;
\r
46 import com.liferay.portal.kernel.exception.PortalException;
\r
47 import com.liferay.portal.kernel.exception.SystemException;
\r
48 import com.liferay.portal.kernel.image.ImageBag;
\r
49 import com.liferay.portal.kernel.image.ImageToolUtil;
\r
50 import com.liferay.portal.kernel.language.LanguageUtil;
\r
51 import com.liferay.portal.kernel.log.Log;
\r
52 import com.liferay.portal.kernel.log.LogFactoryUtil;
\r
53 import com.liferay.portal.kernel.search.Hits;
\r
54 import com.liferay.portal.kernel.search.Indexer;
\r
55 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
\r
56 import com.liferay.portal.kernel.search.QueryConfig;
\r
57 import com.liferay.portal.kernel.search.SearchContext;
\r
58 import com.liferay.portal.kernel.search.Sort;
\r
59 import com.liferay.portal.kernel.spring.aop.Skip;
\r
60 import com.liferay.portal.kernel.transaction.Propagation;
\r
61 import com.liferay.portal.kernel.transaction.Transactional;
\r
62 import com.liferay.portal.kernel.util.ArrayUtil;
\r
63 import com.liferay.portal.kernel.util.CharPool;
\r
64 import com.liferay.portal.kernel.util.Digester;
\r
65 import com.liferay.portal.kernel.util.DigesterUtil;
\r
66 import com.liferay.portal.kernel.util.GetterUtil;
\r
67 import com.liferay.portal.kernel.util.KeyValuePair;
\r
68 import com.liferay.portal.kernel.util.OrderByComparator;
\r
69 import com.liferay.portal.kernel.util.ParamUtil;
\r
70 import com.liferay.portal.kernel.util.PropsKeys;
\r
71 import com.liferay.portal.kernel.util.StringPool;
\r
72 import com.liferay.portal.kernel.util.StringUtil;
\r
73 import com.liferay.portal.kernel.util.Validator;
\r
74 import com.liferay.portal.kernel.workflow.WorkflowConstants;
\r
75 import com.liferay.portal.kernel.workflow.WorkflowHandlerRegistryUtil;
\r
76 import com.liferay.portal.kernel.workflow.WorkflowThreadLocal;
\r
77 import com.liferay.portal.model.Account;
\r
78 import com.liferay.portal.model.Company;
\r
79 import com.liferay.portal.model.CompanyConstants;
\r
80 import com.liferay.portal.model.Contact;
\r
81 import com.liferay.portal.model.ContactConstants;
\r
82 import com.liferay.portal.model.Group;
\r
83 import com.liferay.portal.model.GroupConstants;
\r
84 import com.liferay.portal.model.Layout;
\r
85 import com.liferay.portal.model.Organization;
\r
86 import com.liferay.portal.model.PasswordPolicy;
\r
87 import com.liferay.portal.model.ResourceConstants;
\r
88 import com.liferay.portal.model.Role;
\r
89 import com.liferay.portal.model.RoleConstants;
\r
90 import com.liferay.portal.model.Team;
\r
91 import com.liferay.portal.model.Ticket;
\r
92 import com.liferay.portal.model.TicketConstants;
\r
93 import com.liferay.portal.model.User;
\r
94 import com.liferay.portal.model.UserGroup;
\r
95 import com.liferay.portal.model.UserGroupRole;
\r
96 import com.liferay.portal.model.impl.LayoutImpl;
\r
97 import com.liferay.portal.security.auth.AuthPipeline;
\r
98 import com.liferay.portal.security.auth.Authenticator;
\r
99 import com.liferay.portal.security.auth.EmailAddressGenerator;
\r
100 import com.liferay.portal.security.auth.EmailAddressGeneratorFactory;
\r
101 import com.liferay.portal.security.auth.EmailAddressValidator;
\r
102 import com.liferay.portal.security.auth.EmailAddressValidatorFactory;
\r
103 import com.liferay.portal.security.auth.FullNameGenerator;
\r
104 import com.liferay.portal.security.auth.FullNameGeneratorFactory;
\r
105 import com.liferay.portal.security.auth.FullNameValidator;
\r
106 import com.liferay.portal.security.auth.FullNameValidatorFactory;
\r
107 import com.liferay.portal.security.auth.PrincipalException;
\r
108 import com.liferay.portal.security.auth.ScreenNameGenerator;
\r
109 import com.liferay.portal.security.auth.ScreenNameGeneratorFactory;
\r
110 import com.liferay.portal.security.auth.ScreenNameValidator;
\r
111 import com.liferay.portal.security.auth.ScreenNameValidatorFactory;
\r
112 import com.liferay.portal.security.ldap.LDAPSettingsUtil;
\r
113 import com.liferay.portal.security.permission.PermissionCacheUtil;
\r
114 import com.liferay.portal.security.pwd.PwdAuthenticator;
\r
115 import com.liferay.portal.security.pwd.PwdEncryptor;
\r
116 import com.liferay.portal.security.pwd.PwdToolkitUtil;
\r
117 import com.liferay.portal.service.BaseServiceImpl;
\r
118 import com.liferay.portal.service.ExtUserLocalService;
\r
119 import com.liferay.portal.service.ServiceContext;
\r
120 import com.liferay.portal.service.base.UserLocalServiceBaseImpl;
\r
121 import com.liferay.portal.spring.transaction.TransactionCommitCallbackUtil;
\r
122 import com.liferay.portal.util.PortalUtil;
\r
123 import com.liferay.portal.util.PrefsPropsUtil;
\r
124 import com.liferay.portal.util.PropsValues;
\r
125 import com.liferay.portal.util.SubscriptionSender;
\r
126 import com.liferay.portlet.documentlibrary.ImageSizeException;
\r
127 import com.liferay.portlet.messageboards.model.MBMessage;
\r
128 import com.liferay.portlet.usersadmin.util.UsersAdminUtil;
\r
129 import com.liferay.util.Encryptor;
\r
130 import com.liferay.util.EncryptorException;
\r
132 import java.awt.image.RenderedImage;
\r
134 import java.io.IOException;
\r
135 import java.io.Serializable;
\r
137 import java.util.ArrayList;
\r
138 import java.util.Arrays;
\r
139 import java.util.Calendar;
\r
140 import java.util.Date;
\r
141 import java.util.HashMap;
\r
142 import java.util.HashSet;
\r
143 import java.util.LinkedHashMap;
\r
144 import java.util.List;
\r
145 import java.util.Locale;
\r
146 import java.util.Map;
\r
147 import java.util.Set;
\r
148 import java.util.concurrent.Callable;
\r
149 import java.util.concurrent.ConcurrentHashMap;
\r
152 * The implementation of the user local service.
\r
154 * @author Brian Wing Shun Chan
\r
155 * @author Scott Lee
\r
156 * @author Raymond Augé
\r
157 * @author Jorge Ferrer
\r
158 * @author Julio Camarero
\r
159 * @author Wesley Gong
\r
160 * @author Zsigmond Rab
\r
162 public class ExtUserLocalServiceImpl extends UserLocalServiceBaseImpl implements ExtUserLocalService {
\r
164 public User addDefaultAdminUser(
\r
165 long companyId, String screenName, String emailAddress,
\r
166 Locale locale, String firstName, String middleName, String lastName)
\r
167 throws PortalException, SystemException {
\r
169 long creatorUserId = 0;
\r
170 boolean autoPassword = false;
\r
171 String password1 = PropsValues.DEFAULT_ADMIN_PASSWORD;
\r
172 String password2 = password1;
\r
173 boolean autoScreenName = false;
\r
175 screenName = getScreenName(screenName);
\r
177 for (int i = 1;; i++) {
\r
178 User screenNameUser = userPersistence.fetchByC_SN(
\r
179 companyId, screenName);
\r
181 if (screenNameUser == null) {
\r
185 screenName = screenName + i;
\r
188 long facebookId = 0;
\r
189 String openId = StringPool.BLANK;
\r
192 boolean male = true;
\r
193 int birthdayMonth = Calendar.JANUARY;
\r
194 int birthdayDay = 1;
\r
195 int birthdayYear = 1970;
\r
196 String jobTitle = StringPool.BLANK;
\r
198 Group guestGroup = groupLocalService.getGroup(
\r
199 companyId, GroupConstants.GUEST);
\r
201 long[] groupIds = {guestGroup.getGroupId()};
\r
203 long[] organizationIds = null;
\r
205 Role adminRole = roleLocalService.getRole(
\r
206 companyId, RoleConstants.ADMINISTRATOR);
\r
208 Role powerUserRole = roleLocalService.getRole(
\r
209 companyId, RoleConstants.POWER_USER);
\r
211 long[] roleIds = {adminRole.getRoleId(), powerUserRole.getRoleId()};
\r
213 long[] userGroupIds = null;
\r
214 boolean sendEmail = false;
\r
215 ServiceContext serviceContext = new ServiceContext();
\r
217 User defaultAdminUser = addUser(
\r
218 creatorUserId, companyId, autoPassword, password1, password2,
\r
219 autoScreenName, screenName, emailAddress, facebookId, openId,
\r
220 locale, firstName, middleName, lastName, prefixId, suffixId, male,
\r
221 birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds,
\r
222 organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
\r
224 updateEmailAddressVerified(defaultAdminUser.getUserId(), true);
\r
227 defaultAdminUser.getUserId(), defaultAdminUser.getLoginIP());
\r
229 updatePasswordReset(defaultAdminUser.getUserId(), false);
\r
231 return defaultAdminUser;
\r
235 * Adds the user to the default groups, unless the user is already in these
\r
236 * groups. The default groups can be specified in
\r
237 * <code>portal.properties</code> with the key
\r
238 * <code>admin.default.group.names</code>.
\r
240 * @param userId the primary key of the user
\r
241 * @throws PortalException if a user with the primary key could not be found
\r
242 * @throws SystemException if a system exception occurred
\r
244 public void addDefaultGroups(long userId)
\r
245 throws PortalException, SystemException {
\r
247 User user = userPersistence.findByPrimaryKey(userId);
\r
249 Set<Long> groupIdsSet = new HashSet<Long>();
\r
251 String[] defaultGroupNames = PrefsPropsUtil.getStringArray(
\r
252 user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_GROUP_NAMES,
\r
253 StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_GROUP_NAMES);
\r
255 for (String defaultGroupName : defaultGroupNames) {
\r
256 Company company = companyPersistence.findByPrimaryKey(
\r
257 user.getCompanyId());
\r
259 Account account = company.getAccount();
\r
261 if (defaultGroupName.equalsIgnoreCase(account.getName())) {
\r
262 defaultGroupName = GroupConstants.GUEST;
\r
266 Group group = groupPersistence.findByC_N(
\r
267 user.getCompanyId(), defaultGroupName);
\r
269 if (!userPersistence.containsGroup(
\r
270 userId, group.getGroupId())) {
\r
272 groupIdsSet.add(group.getGroupId());
\r
275 catch (NoSuchGroupException nsge) {
\r
279 long[] groupIds = ArrayUtil.toArray(
\r
280 groupIdsSet.toArray(new Long[groupIdsSet.size()]));
\r
282 groupLocalService.addUserGroups(userId, groupIds);
\r
286 * Adds the user to the default roles, unless the user already has these
\r
287 * roles. The default roles can be specified in
\r
288 * <code>portal.properties</code> with the key
\r
289 * <code>admin.default.role.names</code>.
\r
291 * @param userId the primary key of the user
\r
292 * @throws PortalException if a user with the primary key could not be found
\r
293 * @throws SystemException if a system exception occurred
\r
295 public void addDefaultRoles(long userId)
\r
296 throws PortalException, SystemException {
\r
298 User user = userPersistence.findByPrimaryKey(userId);
\r
300 Set<Long> roleIdSet = new HashSet<Long>();
\r
302 String[] defaultRoleNames = PrefsPropsUtil.getStringArray(
\r
303 user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_ROLE_NAMES,
\r
304 StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_ROLE_NAMES);
\r
306 for (String defaultRoleName : defaultRoleNames) {
\r
308 Role role = rolePersistence.findByC_N(
\r
309 user.getCompanyId(), defaultRoleName);
\r
311 if (!userPersistence.containsRole(userId, role.getRoleId())) {
\r
312 roleIdSet.add(role.getRoleId());
\r
315 catch (NoSuchRoleException nsre) {
\r
319 long[] roleIds = ArrayUtil.toArray(
\r
320 roleIdSet.toArray(new Long[roleIdSet.size()]));
\r
322 roleIds = UsersAdminUtil.addRequiredRoles(user, roleIds);
\r
324 userPersistence.addRoles(userId, roleIds);
\r
328 * Adds the user to the default user groups, unless the user is already in
\r
329 * these user groups. The default user groups can be specified in
\r
330 * <code>portal.properties</code> with the property
\r
331 * <code>admin.default.user.group.names</code>.
\r
333 * @param userId the primary key of the user
\r
334 * @throws PortalException if a user with the primary key could not be found
\r
335 * @throws SystemException if a system exception occurred
\r
337 @SuppressWarnings("deprecation")
\r
338 public void addDefaultUserGroups(long userId)
\r
339 throws PortalException, SystemException {
\r
341 User user = userPersistence.findByPrimaryKey(userId);
\r
343 Set<Long> userGroupIdSet = new HashSet<Long>();
\r
345 String[] defaultUserGroupNames = PrefsPropsUtil.getStringArray(
\r
346 user.getCompanyId(), PropsKeys.ADMIN_DEFAULT_USER_GROUP_NAMES,
\r
347 StringPool.NEW_LINE, PropsValues.ADMIN_DEFAULT_USER_GROUP_NAMES);
\r
349 for (String defaultUserGroupName : defaultUserGroupNames) {
\r
351 UserGroup userGroup = userGroupPersistence.findByC_N(
\r
352 user.getCompanyId(), defaultUserGroupName);
\r
354 if (!userPersistence.containsUserGroup(
\r
355 userId, userGroup.getUserGroupId())) {
\r
357 userGroupIdSet.add(userGroup.getUserGroupId());
\r
360 catch (NoSuchUserGroupException nsuge) {
\r
364 long[] userGroupIds = ArrayUtil.toArray(
\r
365 userGroupIdSet.toArray(new Long[userGroupIdSet.size()]));
\r
367 if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) {
\r
368 for (long userGroupId : userGroupIds) {
\r
369 userGroupLocalService.copyUserGroupLayouts(userGroupId, userId);
\r
373 userPersistence.addUserGroups(userId, userGroupIds);
\r
377 * Adds the users to the group.
\r
379 * @param groupId the primary key of the group
\r
380 * @param userIds the primary keys of the users
\r
381 * @throws PortalException if a group or user with the primary key could not
\r
383 * @throws SystemException if a system exception occurred
\r
385 public void addGroupUsers(long groupId, long[] userIds)
\r
386 throws PortalException, SystemException {
\r
388 groupPersistence.addUsers(groupId, userIds);
\r
390 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
392 indexer.reindex(userIds);
\r
394 PermissionCacheUtil.clearCache();
\r
398 * Adds the users to the organization.
\r
400 * @param organizationId the primary key of the organization
\r
401 * @param userIds the primary keys of the users
\r
402 * @throws PortalException if an organization or user with the primary key
\r
403 * could not be found
\r
404 * @throws SystemException if a system exception occurred
\r
406 public void addOrganizationUsers(long organizationId, long[] userIds)
\r
407 throws PortalException, SystemException {
\r
409 organizationPersistence.addUsers(organizationId, userIds);
\r
411 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
413 indexer.reindex(userIds);
\r
415 PermissionCacheUtil.clearCache();
\r
419 * Assigns the password policy to the users, removing any other currently
\r
420 * assigned password policies.
\r
422 * @param passwordPolicyId the primary key of the password policy
\r
423 * @param userIds the primary keys of the users
\r
424 * @throws SystemException if a system exception occurred
\r
426 public void addPasswordPolicyUsers(long passwordPolicyId, long[] userIds)
\r
427 throws SystemException {
\r
429 passwordPolicyRelLocalService.addPasswordPolicyRels(
\r
430 passwordPolicyId, User.class.getName(), userIds);
\r
434 * Adds the users to the role.
\r
436 * @param roleId the primary key of the role
\r
437 * @param userIds the primary keys of the users
\r
438 * @throws PortalException if a role or user with the primary key could not
\r
440 * @throws SystemException if a system exception occurred
\r
442 public void addRoleUsers(long roleId, long[] userIds)
\r
443 throws PortalException, SystemException {
\r
445 rolePersistence.addUsers(roleId, userIds);
\r
447 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
449 indexer.reindex(userIds);
\r
451 PermissionCacheUtil.clearCache();
\r
455 * Adds the users to the team.
\r
457 * @param teamId the primary key of the team
\r
458 * @param userIds the primary keys of the users
\r
459 * @throws PortalException if a team or user with the primary key could not
\r
461 * @throws SystemException if a system exception occurred
\r
463 public void addTeamUsers(long teamId, long[] userIds)
\r
464 throws PortalException, SystemException {
\r
466 teamPersistence.addUsers(teamId, userIds);
\r
468 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
470 indexer.reindex(userIds);
\r
472 PermissionCacheUtil.clearCache();
\r
479 * This method handles the creation and bookkeeping of the user including
\r
480 * its resources, metadata, and internal data structures. It is not
\r
481 * necessary to make subsequent calls to any methods to setup default
\r
482 * groups, resources, etc.
\r
485 * @param creatorUserId the primary key of the creator
\r
486 * @param companyId the primary key of the user's company
\r
487 * @param autoPassword whether a password should be automatically generated
\r
489 * @param password1 the user's password
\r
490 * @param password2 the user's password confirmation
\r
491 * @param autoScreenName whether a screen name should be automatically
\r
492 * generated for the user
\r
493 * @param screenName the user's screen name
\r
494 * @param emailAddress the user's email address
\r
495 * @param facebookId the user's facebook ID
\r
496 * @param openId the user's OpenID
\r
497 * @param locale the user's locale
\r
498 * @param firstName the user's first name
\r
499 * @param middleName the user's middle name
\r
500 * @param lastName the user's last name
\r
501 * @param prefixId the user's name prefix ID
\r
502 * @param suffixId the user's name suffix ID
\r
503 * @param male whether the user is male
\r
504 * @param birthdayMonth the user's birthday month (0-based, meaning 0 for
\r
506 * @param birthdayDay the user's birthday day
\r
507 * @param birthdayYear the user's birthday year
\r
508 * @param jobTitle the user's job title
\r
509 * @param groupIds the primary keys of the user's groups
\r
510 * @param organizationIds the primary keys of the user's organizations
\r
511 * @param roleIds the primary keys of the roles this user possesses
\r
512 * @param userGroupIds the primary keys of the user's user groups
\r
513 * @param sendEmail whether to send the user an email notification about
\r
514 * their new account
\r
515 * @param serviceContext the user's service context (optionally
\r
516 * <code>null</code>). Can set the universally unique identifier
\r
517 * (with the <code>uuid</code> attribute), asset category IDs, asset
\r
518 * tag names, and expando bridge attributes for the user.
\r
519 * @return the new user
\r
520 * @throws PortalException if the user's information was invalid
\r
521 * @throws SystemException if a system exception occurred
\r
523 public User addUser(
\r
524 long creatorUserId, long companyId, boolean autoPassword,
\r
525 String password1, String password2, boolean autoScreenName,
\r
526 String screenName, String emailAddress, long facebookId,
\r
527 String openId, Locale locale, String firstName, String middleName,
\r
528 String lastName, int prefixId, int suffixId, boolean male,
\r
529 int birthdayMonth, int birthdayDay, int birthdayYear,
\r
530 String jobTitle, long[] groupIds, long[] organizationIds,
\r
531 long[] roleIds, long[] userGroupIds, boolean sendEmail,
\r
532 ServiceContext serviceContext)
\r
533 throws PortalException, SystemException {
\r
535 boolean workflowEnabled = WorkflowThreadLocal.isEnabled();
\r
538 WorkflowThreadLocal.setEnabled(false);
\r
540 return addUserWithWorkflow(
\r
541 creatorUserId, companyId, autoPassword, password1, password2,
\r
542 autoScreenName, screenName, emailAddress, facebookId, openId,
\r
543 locale, firstName, middleName, lastName, prefixId, suffixId,
\r
544 male, birthdayMonth, birthdayDay, birthdayYear, jobTitle,
\r
545 groupIds, organizationIds, roleIds, userGroupIds, sendEmail,
\r
549 WorkflowThreadLocal.setEnabled(workflowEnabled);
\r
554 * Adds the users to the user group.
\r
556 * @param userGroupId the primary key of the user group
\r
557 * @param userIds the primary keys of the users
\r
558 * @throws PortalException if a user group or user with the primary could
\r
559 * could not be found
\r
560 * @throws SystemException if a system exception occurred
\r
562 @SuppressWarnings("deprecation")
\r
563 public void addUserGroupUsers(long userGroupId, long[] userIds)
\r
564 throws PortalException, SystemException {
\r
566 if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) {
\r
567 userGroupLocalService.copyUserGroupLayouts(userGroupId, userIds);
\r
570 userGroupPersistence.addUsers(userGroupId, userIds);
\r
572 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
574 indexer.reindex(userIds);
\r
576 PermissionCacheUtil.clearCache();
\r
580 * Adds a user with workflow.
\r
583 * This method handles the creation and bookkeeping of the user including
\r
584 * its resources, metadata, and internal data structures. It is not
\r
585 * necessary to make subsequent calls to any methods to setup default
\r
586 * groups, resources, etc.
\r
589 * @param creatorUserId the primary key of the creator
\r
590 * @param companyId the primary key of the user's company
\r
591 * @param autoPassword whether a password should be automatically generated
\r
593 * @param password1 the user's password
\r
594 * @param password2 the user's password confirmation
\r
595 * @param autoScreenName whether a screen name should be automatically
\r
596 * generated for the user
\r
597 * @param screenName the user's screen name
\r
598 * @param emailAddress the user's email address
\r
599 * @param facebookId the user's facebook ID
\r
600 * @param openId the user's OpenID
\r
601 * @param locale the user's locale
\r
602 * @param firstName the user's first name
\r
603 * @param middleName the user's middle name
\r
604 * @param lastName the user's last name
\r
605 * @param prefixId the user's name prefix ID
\r
606 * @param suffixId the user's name suffix ID
\r
607 * @param male whether the user is male
\r
608 * @param birthdayMonth the user's birthday month (0-based, meaning 0 for
\r
610 * @param birthdayDay the user's birthday day
\r
611 * @param birthdayYear the user's birthday year
\r
612 * @param jobTitle the user's job title
\r
613 * @param groupIds the primary keys of the user's groups
\r
614 * @param organizationIds the primary keys of the user's organizations
\r
615 * @param roleIds the primary keys of the roles this user possesses
\r
616 * @param userGroupIds the primary keys of the user's user groups
\r
617 * @param sendEmail whether to send the user an email notification about
\r
618 * their new account
\r
619 * @param serviceContext the user's service context (optionally
\r
620 * <code>null</code>). Can set the universally unique identifier
\r
621 * (with the <code>uuid</code> attribute), asset category IDs, asset
\r
622 * tag names, and expando bridge attributes for the user.
\r
623 * @return the new user
\r
624 * @throws PortalException if the user's information was invalid
\r
625 * @throws SystemException if a system exception occurred
\r
627 @SuppressWarnings("deprecation")
\r
628 public User addUserWithWorkflow(
\r
629 long creatorUserId, long companyId, boolean autoPassword,
\r
630 String password1, String password2, boolean autoScreenName,
\r
631 String screenName, String emailAddress, long facebookId,
\r
632 String openId, Locale locale, String firstName, String middleName,
\r
633 String lastName, int prefixId, int suffixId, boolean male,
\r
634 int birthdayMonth, int birthdayDay, int birthdayYear,
\r
635 String jobTitle, long[] groupIds, long[] organizationIds,
\r
636 long[] roleIds, long[] userGroupIds, boolean sendEmail,
\r
637 ServiceContext serviceContext)
\r
638 throws PortalException, SystemException {
\r
642 Company company = companyPersistence.findByPrimaryKey(companyId);
\r
643 screenName = getScreenName(screenName);
\r
644 emailAddress = emailAddress.trim().toLowerCase();
\r
645 openId = openId.trim();
\r
646 Date now = new Date();
\r
648 if (PrefsPropsUtil.getBoolean(
\r
649 companyId, PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE)) {
\r
651 autoScreenName = true;
\r
654 long userId = counterLocalService.increment();
\r
656 EmailAddressGenerator emailAddressGenerator =
\r
657 EmailAddressGeneratorFactory.getInstance();
\r
659 if (emailAddressGenerator.isGenerated(emailAddress)) {
\r
660 emailAddress = StringPool.BLANK;
\r
663 if (!PropsValues.USERS_EMAIL_ADDRESS_REQUIRED &&
\r
664 Validator.isNull(emailAddress)) {
\r
666 emailAddress = emailAddressGenerator.generate(companyId, userId);
\r
670 companyId, userId, autoPassword, password1, password2,
\r
671 autoScreenName, screenName, emailAddress, firstName, middleName,
\r
672 lastName, organizationIds);
\r
674 if (!autoPassword) {
\r
675 if (Validator.isNull(password1) || Validator.isNull(password2)) {
\r
676 throw new UserPasswordException(
\r
677 UserPasswordException.PASSWORD_INVALID);
\r
681 if (autoScreenName) {
\r
682 ScreenNameGenerator screenNameGenerator =
\r
683 ScreenNameGeneratorFactory.getInstance();
\r
686 screenName = screenNameGenerator.generate(
\r
687 companyId, userId, emailAddress);
\r
689 catch (Exception e) {
\r
690 throw new SystemException(e);
\r
694 User defaultUser = getDefaultUser(companyId);
\r
696 FullNameGenerator fullNameGenerator =
\r
697 FullNameGeneratorFactory.getInstance();
\r
699 String fullName = fullNameGenerator.getFullName(
\r
700 firstName, middleName, lastName);
\r
702 String greeting = LanguageUtil.format(
\r
703 locale, "welcome-x", " " + fullName, false);
\r
705 User user = userPersistence.create(userId);
\r
707 if (serviceContext != null) {
\r
708 String uuid = serviceContext.getUuid();
\r
710 if (Validator.isNotNull(uuid)) {
\r
711 user.setUuid(uuid);
\r
715 user.setCompanyId(companyId);
\r
716 user.setCreateDate(now);
\r
717 user.setModifiedDate(now);
\r
718 user.setDefaultUser(false);
\r
719 user.setContactId(counterLocalService.increment());
\r
721 if (Validator.isNotNull(password1)) {
\r
722 user.setPassword(PwdEncryptor.encrypt(password1));
\r
723 user.setPasswordUnencrypted(password1);
\r
726 user.setPasswordEncrypted(true);
\r
728 PasswordPolicy passwordPolicy = defaultUser.getPasswordPolicy();
\r
730 if ((passwordPolicy != null) && passwordPolicy.isChangeable() &&
\r
731 passwordPolicy.isChangeRequired()) {
\r
733 user.setPasswordReset(true);
\r
736 user.setPasswordReset(false);
\r
739 user.setDigest(StringPool.BLANK);
\r
740 user.setScreenName(screenName);
\r
741 user.setEmailAddress(emailAddress);
\r
742 user.setFacebookId(facebookId);
\r
743 user.setOpenId(openId);
\r
744 user.setLanguageId(locale.toString());
\r
745 user.setTimeZoneId(defaultUser.getTimeZoneId());
\r
746 user.setGreeting(greeting);
\r
747 user.setFirstName(firstName);
\r
748 user.setMiddleName(middleName);
\r
749 user.setLastName(lastName);
\r
750 user.setJobTitle(jobTitle);
\r
751 user.setStatus(WorkflowConstants.STATUS_DRAFT);
\r
752 user.setExpandoBridgeAttributes(serviceContext);
\r
754 userPersistence.update(user, false, serviceContext);
\r
758 String creatorUserName = StringPool.BLANK;
\r
760 if (creatorUserId <= 0) {
\r
761 creatorUserId = user.getUserId();
\r
763 // Don't grab the full name from the User object because it doesn't
\r
764 // have a corresponding Contact object yet
\r
766 //creatorUserName = user.getFullName();
\r
769 User creatorUser = userPersistence.findByPrimaryKey(creatorUserId);
\r
771 creatorUserName = creatorUser.getFullName();
\r
774 resourceLocalService.addResources(
\r
775 companyId, 0, creatorUserId, User.class.getName(), user.getUserId(),
\r
776 false, false, false);
\r
780 Date birthday = PortalUtil.getDate(
\r
781 birthdayMonth, birthdayDay, birthdayYear,
\r
782 ContactBirthdayException.class);
\r
784 Contact contact = contactPersistence.create(user.getContactId());
\r
786 contact.setCompanyId(user.getCompanyId());
\r
787 contact.setUserId(creatorUserId);
\r
788 contact.setUserName(creatorUserName);
\r
789 contact.setCreateDate(now);
\r
790 contact.setModifiedDate(now);
\r
791 contact.setAccountId(company.getAccountId());
\r
792 contact.setParentContactId(ContactConstants.DEFAULT_PARENT_CONTACT_ID);
\r
793 contact.setFirstName(firstName);
\r
794 contact.setMiddleName(middleName);
\r
795 contact.setLastName(lastName);
\r
796 contact.setPrefixId(prefixId);
\r
797 contact.setSuffixId(suffixId);
\r
798 contact.setMale(male);
\r
799 contact.setBirthday(birthday);
\r
800 contact.setJobTitle(jobTitle);
\r
802 contactPersistence.update(contact, false, serviceContext);
\r
806 groupLocalService.addGroup(
\r
807 user.getUserId(), User.class.getName(), user.getUserId(), null,
\r
808 null, 0, StringPool.SLASH + screenName, false, true, null);
\r
812 if (groupIds != null) {
\r
813 groupLocalService.addUserGroups(userId, groupIds);
\r
816 addDefaultGroups(userId);
\r
820 updateOrganizations(userId, organizationIds, false);
\r
824 if (roleIds != null) {
\r
825 roleIds = UsersAdminUtil.addRequiredRoles(user, roleIds);
\r
827 userPersistence.setRoles(userId, roleIds);
\r
830 addDefaultRoles(userId);
\r
834 if (userGroupIds != null) {
\r
835 if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) {
\r
836 for (long userGroupId : userGroupIds) {
\r
837 userGroupLocalService.copyUserGroupLayouts(
\r
838 userGroupId, new long[] {userId});
\r
842 userPersistence.setUserGroups(userId, userGroupIds);
\r
845 addDefaultUserGroups(userId);
\r
849 if (serviceContext != null) {
\r
851 creatorUserId, user, serviceContext.getAssetCategoryIds(),
\r
852 serviceContext.getAssetTagNames());
\r
857 if ((serviceContext == null) || serviceContext.isIndexingEnabled()) {
\r
863 long workflowUserId = creatorUserId;
\r
865 if (workflowUserId == userId) {
\r
866 workflowUserId = defaultUser.getUserId();
\r
869 ServiceContext workflowServiceContext = serviceContext;
\r
871 if (workflowServiceContext == null) {
\r
872 workflowServiceContext = new ServiceContext();
\r
875 workflowServiceContext.setAttribute("autoPassword", autoPassword);
\r
876 workflowServiceContext.setAttribute("sendEmail", sendEmail);
\r
878 WorkflowHandlerRegistryUtil.startWorkflowInstance(
\r
879 companyId, workflowUserId, User.class.getName(), userId, user,
\r
880 workflowServiceContext);
\r
882 if (serviceContext != null) {
\r
883 String passwordUnencrypted =
\r
884 (String)serviceContext.getAttribute("passwordUnencrypted");
\r
886 if (Validator.isNotNull(passwordUnencrypted)) {
\r
887 user.setPasswordUnencrypted(passwordUnencrypted);
\r
895 * Attempts to authenticate the user by their email address and password,
\r
896 * while using the AuthPipeline.
\r
898 * @param companyId the primary key of the user's company
\r
899 * @param emailAddress the user's email address
\r
900 * @param password the user's password
\r
901 * @param headerMap the header map from the authentication request
\r
902 * @param parameterMap the parameter map from the authentication request
\r
903 * @param resultsMap the map of authentication results (may be nil). After
\r
904 * a succesful authentication the user's primary key will be placed
\r
905 * under the key <code>userId</code>.
\r
906 * @return the authentication status. This can be {@link
\r
907 * com.liferay.portal.security.auth.Authenticator#FAILURE}
\r
908 * indicating that the user's credentials are invalid, {@link
\r
909 * com.liferay.portal.security.auth.Authenticator#SUCCESS}
\r
910 * indicating a successful login, or {@link
\r
911 * com.liferay.portal.security.auth.Authenticator#DNE} indicating
\r
912 * that a user with that login does not exist.
\r
913 * @throws PortalException if <code>emailAddress</code> or
\r
914 * <code>password</code> was <code>null</code>
\r
915 * @throws SystemException if a system exception occurred
\r
916 * @see com.liferay.portal.security.auth.AuthPipeline
\r
918 public int authenticateByEmailAddress(
\r
919 long companyId, String emailAddress, String password,
\r
920 Map<String, String[]> headerMap, Map<String, String[]> parameterMap,
\r
921 Map<String, Object> resultsMap)
\r
922 throws PortalException, SystemException {
\r
924 return authenticate(
\r
925 companyId, emailAddress, password, CompanyConstants.AUTH_TYPE_EA,
\r
926 headerMap, parameterMap, resultsMap);
\r
930 * Attempts to authenticate the user by their screen name and password,
\r
931 * while using the AuthPipeline.
\r
933 * @param companyId the primary key of the user's company
\r
934 * @param screenName the user's screen name
\r
935 * @param password the user's password
\r
936 * @param headerMap the header map from the authentication request
\r
937 * @param parameterMap the parameter map from the authentication request
\r
938 * @param resultsMap the map of authentication results (may be nil). After
\r
939 * a succesful authentication the user's primary key will be placed
\r
940 * under the key <code>userId</code>.
\r
941 * @return the authentication status. This can be {@link
\r
942 * com.liferay.portal.security.auth.Authenticator#FAILURE}
\r
943 * indicating that the user's credentials are invalid, {@link
\r
944 * com.liferay.portal.security.auth.Authenticator#SUCCESS}
\r
945 * indicating a successful login, or {@link
\r
946 * com.liferay.portal.security.auth.Authenticator#DNE} indicating
\r
947 * that a user with that login does not exist.
\r
948 * @throws PortalException if <code>screenName</code> or
\r
949 * <code>password</code> was <code>null</code>
\r
950 * @throws SystemException if a system exception occurred
\r
951 * @see com.liferay.portal.security.auth.AuthPipeline
\r
953 public int authenticateByScreenName(
\r
954 long companyId, String screenName, String password,
\r
955 Map<String, String[]> headerMap, Map<String, String[]> parameterMap,
\r
956 Map<String, Object> resultsMap)
\r
957 throws PortalException, SystemException {
\r
959 return authenticate(
\r
960 companyId, screenName, password, CompanyConstants.AUTH_TYPE_SN,
\r
961 headerMap, parameterMap, resultsMap);
\r
965 * Attempts to authenticate the user by their primary key and password,
\r
966 * while using the AuthPipeline.
\r
968 * @param companyId the primary key of the user's company
\r
969 * @param userId the user's primary key
\r
970 * @param password the user's password
\r
971 * @param headerMap the header map from the authentication request
\r
972 * @param parameterMap the parameter map from the authentication request
\r
973 * @param resultsMap the map of authentication results (may be nil). After
\r
974 * a succesful authentication the user's primary key will be placed
\r
975 * under the key <code>userId</code>.
\r
976 * @return the authentication status. This can be {@link
\r
977 * com.liferay.portal.security.auth.Authenticator#FAILURE}
\r
978 * indicating that the user's credentials are invalid, {@link
\r
979 * com.liferay.portal.security.auth.Authenticator#SUCCESS}
\r
980 * indicating a successful login, or {@link
\r
981 * com.liferay.portal.security.auth.Authenticator#DNE} indicating
\r
982 * that a user with that login does not exist.
\r
983 * @throws PortalException if <code>userId</code> or <code>password</code>
\r
984 * was <code>null</code>
\r
985 * @throws SystemException if a system exception occurred
\r
986 * @see com.liferay.portal.security.auth.AuthPipeline
\r
988 public int authenticateByUserId(
\r
989 long companyId, long userId, String password,
\r
990 Map<String, String[]> headerMap, Map<String, String[]> parameterMap,
\r
991 Map<String, Object> resultsMap)
\r
992 throws PortalException, SystemException {
\r
994 return authenticate(
\r
995 companyId, String.valueOf(userId), password,
\r
996 CompanyConstants.AUTH_TYPE_ID, headerMap, parameterMap, resultsMap);
\r
1000 * Attempts to authenticate the user using HTTP basic access authentication,
\r
1001 * without using the AuthPipeline. Primarily used for authenticating users
\r
1002 * of <code>tunnel-web</code>.
\r
1005 * Authentication type specifies what <code>login</code> contains.The valid
\r
1011 * <code>CompanyConstants.AUTH_TYPE_EA</code> - <code>login</code> is the
\r
1012 * user's email address
\r
1015 * <code>CompanyConstants.AUTH_TYPE_SN</code> - <code>login</code> is the
\r
1016 * user's screen name
\r
1019 * <code>CompanyConstants.AUTH_TYPE_ID</code> - <code>login</code> is the
\r
1020 * user's primary key
\r
1024 * @param companyId the primary key of the user's company
\r
1025 * @param authType the type of authentication to perform
\r
1026 * @param login either the user's email address, screen name, or primary
\r
1027 * key depending on the value of <code>authType</code>
\r
1028 * @param password the user's password
\r
1029 * @return the authentication status. This can be {@link
\r
1030 * com.liferay.portal.security.auth.Authenticator#FAILURE}
\r
1031 * indicating that the user's credentials are invalid, {@link
\r
1032 * com.liferay.portal.security.auth.Authenticator#SUCCESS}
\r
1033 * indicating a successful login, or {@link
\r
1034 * com.liferay.portal.security.auth.Authenticator#DNE} indicating
\r
1035 * that a user with that login does not exist.
\r
1036 * @throws PortalException if a portal exception occurred
\r
1037 * @throws SystemException if a system exception occurred
\r
1039 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
\r
1040 public long authenticateForBasic(
\r
1041 long companyId, String authType, String login, String password)
\r
1042 throws PortalException, SystemException {
\r
1044 if (PropsValues.AUTH_LOGIN_DISABLED) {
\r
1051 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
\r
1052 user = getUserByEmailAddress(companyId, login);
\r
1054 else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
\r
1055 user = getUserByScreenName(companyId, login);
\r
1057 else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
\r
1058 user = getUserById(companyId, GetterUtil.getLong(login));
\r
1061 if (user.isDefaultUser()) {
\r
1062 if (_log.isInfoEnabled()) {
\r
1064 "Basic authentication is disabled for the default " +
\r
1070 else if (!user.isActive()) {
\r
1071 if (_log.isInfoEnabled()) {
\r
1073 "Basic authentication is disabled for inactive user " +
\r
1074 user.getUserId());
\r
1080 if (!PropsValues.BASIC_AUTH_PASSWORD_REQUIRED) {
\r
1081 return user.getUserId();
\r
1084 String userPassword = user.getPassword();
\r
1086 if (!user.isPasswordEncrypted()) {
\r
1087 userPassword = PwdEncryptor.encrypt(userPassword);
\r
1090 String encPassword = PwdEncryptor.encrypt(password);
\r
1092 if (userPassword.equals(password) ||
\r
1093 userPassword.equals(encPassword)) {
\r
1095 return user.getUserId();
\r
1098 catch (NoSuchUserException nsue) {
\r
1105 * Attempts to authenticate the user using HTTP digest access
\r
1106 * authentication, without using the AuthPipeline. Primarily used for
\r
1107 * authenticating users of <code>tunnel-web</code>.
\r
1109 * @param companyId the primary key of the user's company
\r
1110 * @param username either the user's email address, screen name, or primary
\r
1112 * @param realm unused
\r
1113 * @param nonce the number used once
\r
1114 * @param method the request method
\r
1115 * @param uri the request URI
\r
1116 * @param response the authentication response hash
\r
1117 * @return the user's primary key if authentication is succesful;
\r
1118 * <code>0</code> otherwise
\r
1119 * @throws PortalException if a portal exception occurred
\r
1120 * @throws SystemException if a system exception occurred
\r
1122 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
\r
1123 public long authenticateForDigest(
\r
1124 long companyId, String username, String realm, String nonce,
\r
1125 String method, String uri, String response)
\r
1126 throws PortalException, SystemException {
\r
1128 if (PropsValues.AUTH_LOGIN_DISABLED) {
\r
1137 user = getUserByEmailAddress(companyId, username);
\r
1139 catch (NoSuchUserException nsue) {
\r
1141 user = getUserByScreenName(companyId, username);
\r
1143 catch (NoSuchUserException nsue2) {
\r
1145 user = getUserById(GetterUtil.getLong(username));
\r
1147 catch (NoSuchUserException nsue3) {
\r
1153 if (user.isDefaultUser()) {
\r
1154 if (_log.isInfoEnabled()) {
\r
1156 "Digest authentication is disabled for the default user");
\r
1161 else if (!user.isActive()) {
\r
1162 if (_log.isInfoEnabled()) {
\r
1164 "Digest authentication is disabled for inactive user " +
\r
1165 user.getUserId());
\r
1173 String digest = user.getDigest();
\r
1175 if (Validator.isNull(digest)) {
\r
1177 "User must first login through the portal " + user.getUserId());
\r
1182 String[] digestArray = StringUtil.split(user.getDigest());
\r
1184 for (String ha1 : digestArray) {
\r
1185 String ha2 = DigesterUtil.digestHex(Digester.MD5, method, uri);
\r
1187 String curResponse = DigesterUtil.digestHex(
\r
1188 Digester.MD5, ha1, nonce, ha2);
\r
1190 if (response.equals(curResponse)) {
\r
1191 return user.getUserId();
\r
1199 * Attempts to authenticate the user using JAAS credentials, without using
\r
1200 * the AuthPipeline.
\r
1202 * @param userId the primary key of the user
\r
1203 * @param encPassword the encrypted password
\r
1204 * @return <code>true</code> if authentication is successful;
\r
1205 * <code>false</code> otherwise
\r
1207 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
\r
1208 public boolean authenticateForJAAS(long userId, String encPassword) {
\r
1209 if (PropsValues.AUTH_LOGIN_DISABLED) {
\r
1214 User user = userPersistence.findByPrimaryKey(userId);
\r
1216 if (user.isDefaultUser()) {
\r
1217 if (_log.isInfoEnabled()) {
\r
1219 "JAAS authentication is disabled for the default user");
\r
1224 else if (!user.isActive()) {
\r
1225 if (_log.isInfoEnabled()) {
\r
1227 "JAAS authentication is disabled for inactive user " +
\r
1234 String password = user.getPassword();
\r
1236 if (user.isPasswordEncrypted()) {
\r
1237 if (password.equals(encPassword)) {
\r
1241 if (!PropsValues.PORTAL_JAAS_STRICT_PASSWORD) {
\r
1242 encPassword = PwdEncryptor.encrypt(encPassword, password);
\r
1244 if (password.equals(encPassword)) {
\r
1250 if (!PropsValues.PORTAL_JAAS_STRICT_PASSWORD) {
\r
1251 if (password.equals(encPassword)) {
\r
1256 password = PwdEncryptor.encrypt(password);
\r
1258 if (password.equals(encPassword)) {
\r
1263 catch (Exception e) {
\r
1271 * Checks if the user is currently locked out based on the password policy,
\r
1272 * and performs maintenance on the user's lockout and failed login data.
\r
1274 * @param user the user
\r
1275 * @throws PortalException if the user was determined to still be locked out
\r
1276 * @throws SystemException if a system exception occurred
\r
1278 public void checkLockout(User user)
\r
1279 throws PortalException, SystemException {
\r
1281 if (LDAPSettingsUtil.isPasswordPolicyEnabled(user.getCompanyId())) {
\r
1285 PasswordPolicy passwordPolicy = user.getPasswordPolicy();
\r
1287 if (passwordPolicy.isLockout()) {
\r
1289 // Reset failure count
\r
1291 Date now = new Date();
\r
1292 int failedLoginAttempts = user.getFailedLoginAttempts();
\r
1294 if (failedLoginAttempts > 0) {
\r
1295 long failedLoginTime = user.getLastFailedLoginDate().getTime();
\r
1296 long elapsedTime = now.getTime() - failedLoginTime;
\r
1297 long requiredElapsedTime =
\r
1298 passwordPolicy.getResetFailureCount() * 1000;
\r
1300 if ((requiredElapsedTime != 0) &&
\r
1301 (elapsedTime > requiredElapsedTime)) {
\r
1303 user.setLastFailedLoginDate(null);
\r
1304 user.setFailedLoginAttempts(0);
\r
1306 userPersistence.update(user, false);
\r
1312 if (user.isLockout()) {
\r
1313 long lockoutTime = user.getLockoutDate().getTime();
\r
1314 long elapsedTime = now.getTime() - lockoutTime;
\r
1315 long requiredElapsedTime =
\r
1316 passwordPolicy.getLockoutDuration() * 1000;
\r
1318 if ((requiredElapsedTime != 0) &&
\r
1319 (elapsedTime > requiredElapsedTime)) {
\r
1321 user.setLockout(false);
\r
1322 user.setLockoutDate(null);
\r
1324 userPersistence.update(user, false);
\r
1328 if (user.isLockout()) {
\r
1329 throw new UserLockoutException();
\r
1335 * Adds a failed login attempt to the user and updates the user's last
\r
1336 * failed login date.
\r
1338 * @param user the user
\r
1339 * @throws SystemException if a system exception occurred
\r
1341 public void checkLoginFailure(User user) throws SystemException {
\r
1342 Date now = new Date();
\r
1344 int failedLoginAttempts = user.getFailedLoginAttempts();
\r
1346 user.setLastFailedLoginDate(now);
\r
1347 user.setFailedLoginAttempts(++failedLoginAttempts);
\r
1349 userPersistence.update(user, false);
\r
1353 * Adds a failed login attempt to the user with the email address and
\r
1354 * updates the user's last failed login date.
\r
1356 * @param companyId the primary key of the user's company
\r
1357 * @param emailAddress the user's email address
\r
1358 * @throws PortalException if a user with the email address could not be
\r
1360 * @throws SystemException if a system exception occurred
\r
1362 public void checkLoginFailureByEmailAddress(
\r
1363 long companyId, String emailAddress)
\r
1364 throws PortalException, SystemException {
\r
1366 User user = getUserByEmailAddress(companyId, emailAddress);
\r
1368 checkLoginFailure(user);
\r
1372 * Adds a failed login attempt to the user and updates the user's last
\r
1373 * failed login date.
\r
1375 * @param userId the primary key of the user
\r
1376 * @throws PortalException if a user with the primary key could not be found
\r
1377 * @throws SystemException if a system exception occurred
\r
1379 public void checkLoginFailureById(long userId)
\r
1380 throws PortalException, SystemException {
\r
1382 User user = userPersistence.findByPrimaryKey(userId);
\r
1384 checkLoginFailure(user);
\r
1388 * Adds a failed login attempt to the user with the screen name and updates
\r
1389 * the user's last failed login date.
\r
1391 * @param companyId the primary key of the user's company
\r
1392 * @param screenName the user's screen name
\r
1393 * @throws PortalException if a user with the screen name could not be found
\r
1394 * @throws SystemException if a system exception occurred
\r
1396 public void checkLoginFailureByScreenName(long companyId, String screenName)
\r
1397 throws PortalException, SystemException {
\r
1399 User user = getUserByScreenName(companyId, screenName);
\r
1401 checkLoginFailure(user);
\r
1405 * Checks if the user's password is expired based on the password policy,
\r
1406 * and performs maintenance on the user's grace login and password reset
\r
1409 * @param user the user
\r
1410 * @throws PortalException if the user's password has expired and the grace
\r
1411 * login limit has been exceeded
\r
1412 * @throws SystemException if a system exception occurred
\r
1414 public void checkPasswordExpired(User user)
\r
1415 throws PortalException, SystemException {
\r
1417 if (LDAPSettingsUtil.isPasswordPolicyEnabled(user.getCompanyId())) {
\r
1421 PasswordPolicy passwordPolicy = user.getPasswordPolicy();
\r
1423 // Check if password has expired
\r
1425 if (isPasswordExpired(user)) {
\r
1426 int graceLoginCount = user.getGraceLoginCount();
\r
1428 if (graceLoginCount < passwordPolicy.getGraceLimit()) {
\r
1429 user.setGraceLoginCount(++graceLoginCount);
\r
1431 userPersistence.update(user, false);
\r
1434 user.setDigest(StringPool.BLANK);
\r
1436 userPersistence.update(user, false);
\r
1438 throw new PasswordExpiredException();
\r
1442 // Check if user should be forced to change password on first login
\r
1444 if (passwordPolicy.isChangeable() &&
\r
1445 passwordPolicy.isChangeRequired()) {
\r
1447 if (user.getLastLoginDate() == null) {
\r
1448 user.setPasswordReset(true);
\r
1450 userPersistence.update(user, false);
\r
1456 * Removes all the users from the organization.
\r
1458 * @param organizationId the primary key of the organization
\r
1459 * @throws SystemException if a system exception occurred
\r
1461 public void clearOrganizationUsers(long organizationId)
\r
1462 throws SystemException {
\r
1464 organizationPersistence.clearUsers(organizationId);
\r
1466 PermissionCacheUtil.clearCache();
\r
1470 * Removes all the users from the user group.
\r
1472 * @param userGroupId the primary key of the user group
\r
1473 * @throws SystemException if a system exception occurred
\r
1475 public void clearUserGroupUsers(long userGroupId) throws SystemException {
\r
1476 userGroupPersistence.clearUsers(userGroupId);
\r
1478 PermissionCacheUtil.clearCache();
\r
1482 * Completes the user's registration by generating a password and sending
\r
1483 * the confirmation email.
\r
1485 * @param user the user
\r
1486 * @param serviceContext the user's service context. Can set whether a
\r
1487 * password should be generated (with the <code>autoPassword</code>
\r
1488 * attribute) and whether the confirmation email should be sent
\r
1489 * (with the <code>sendEmail</code> attribute) for the user.
\r
1490 * @throws PortalException if a portal exception occurred
\r
1491 * @throws SystemException if a system exception occurred
\r
1493 public void completeUserRegistration(
\r
1494 User user, ServiceContext serviceContext)
\r
1495 throws PortalException, SystemException {
\r
1497 boolean autoPassword = ParamUtil.getBoolean(
\r
1498 serviceContext, "autoPassword");
\r
1500 String password = null;
\r
1502 if (autoPassword) {
\r
1503 PasswordPolicy passwordPolicy =
\r
1504 passwordPolicyLocalService.getPasswordPolicy(
\r
1505 user.getCompanyId(), user.getOrganizationIds());
\r
1507 password = PwdToolkitUtil.generate(passwordPolicy);
\r
1509 user.setPassword(PwdEncryptor.encrypt(password));
\r
1510 user.setPasswordEncrypted(true);
\r
1511 user.setPasswordUnencrypted(password);
\r
1513 userPersistence.update(user, false);
\r
1517 if (user.hasCompanyMx()) {
\r
1518 String mailPassword = password;
\r
1520 if (Validator.isNull(mailPassword)) {
\r
1521 mailPassword = user.getPasswordUnencrypted();
\r
1524 mailService.addUser(
\r
1525 user.getCompanyId(), user.getUserId(), mailPassword,
\r
1526 user.getFirstName(), user.getMiddleName(), user.getLastName(),
\r
1527 user.getEmailAddress());
\r
1530 boolean sendEmail = ParamUtil.getBoolean(serviceContext, "sendEmail");
\r
1533 sendEmail(user, password, serviceContext);
\r
1536 Company company = companyPersistence.findByPrimaryKey(
\r
1537 user.getCompanyId());
\r
1539 if (company.isStrangersVerify() && (serviceContext.getPlid() > 0)) {
\r
1540 sendEmailAddressVerification(
\r
1541 user, user.getEmailAddress(), serviceContext);
\r
1546 * Decrypts the user's primary key and password from their encrypted forms.
\r
1547 * Used for decrypting a user's credentials from the values stored in an
\r
1548 * automatic login cookie.
\r
1550 * @param companyId the primary key of the user's company
\r
1551 * @param name the encrypted primary key of the user
\r
1552 * @param password the encrypted password of the user
\r
1553 * @return the user's primary key and password
\r
1554 * @throws PortalException if a user with the primary key could not be found
\r
1555 * or if the user's password was incorrect
\r
1556 * @throws SystemException if a system exception occurred
\r
1558 public KeyValuePair decryptUserId(
\r
1559 long companyId, String name, String password)
\r
1560 throws PortalException, SystemException {
\r
1562 Company company = companyPersistence.findByPrimaryKey(companyId);
\r
1565 name = Encryptor.decrypt(company.getKeyObj(), name);
\r
1567 catch (EncryptorException ee) {
\r
1568 throw new SystemException(ee);
\r
1571 long userId = GetterUtil.getLong(name);
\r
1573 User user = userPersistence.findByPrimaryKey(userId);
\r
1576 password = Encryptor.decrypt(company.getKeyObj(), password);
\r
1578 catch (EncryptorException ee) {
\r
1579 throw new SystemException(ee);
\r
1582 String encPassword = PwdEncryptor.encrypt(password);
\r
1584 if (user.getPassword().equals(encPassword)) {
\r
1585 if (isPasswordExpired(user)) {
\r
1586 user.setPasswordReset(true);
\r
1588 userPersistence.update(user, false);
\r
1591 return new KeyValuePair(name, password);
\r
1594 throw new PrincipalException();
\r
1599 * Deletes the user's portrait image.
\r
1601 * @param userId the primary key of the user
\r
1602 * @throws PortalException if a user with the primary key could not be found
\r
1603 * or if the user's portrait could not be found
\r
1604 * @throws SystemException if a system exception occurred
\r
1606 public void deletePortrait(long userId)
\r
1607 throws PortalException, SystemException {
\r
1609 User user = userPersistence.findByPrimaryKey(userId);
\r
1611 long portraitId = user.getPortraitId();
\r
1613 if (portraitId > 0) {
\r
1614 user.setPortraitId(0);
\r
1616 userPersistence.update(user, false);
\r
1618 imageLocalService.deleteImage(portraitId);
\r
1623 * Removes the user from the role.
\r
1625 * @param roleId the primary key of the role
\r
1626 * @param userId the primary key of the user
\r
1627 * @throws PortalException if a role or user with the primary key could not
\r
1629 * @throws SystemException if a system exception occurred
\r
1631 public void deleteRoleUser(long roleId, long userId)
\r
1632 throws PortalException, SystemException {
\r
1634 rolePersistence.removeUser(roleId, userId);
\r
1636 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
1638 indexer.reindex(userId);
\r
1640 PermissionCacheUtil.clearCache();
\r
1644 * Deletes the user.
\r
1646 * @param userId the primary key of the user
\r
1647 * @throws PortalException if a user with the primary key could not be found
\r
1648 * @throws SystemException if a system exception occurred
\r
1651 public User deleteUser(long userId)
\r
1652 throws PortalException, SystemException {
\r
1654 User user = userPersistence.findByPrimaryKey(userId);
\r
1656 return deleteUser(user);
\r
1660 * Deletes the user.
\r
1662 * @param user the user
\r
1663 * @throws PortalException if a portal exception occurred
\r
1664 * @throws SystemException if a system exception occurred
\r
1667 public User deleteUser(User user) throws PortalException, SystemException {
\r
1668 if (!PropsValues.USERS_DELETE) {
\r
1669 throw new RequiredUserException();
\r
1672 // Browser tracker
\r
1674 browserTrackerLocalService.deleteUserBrowserTracker(user.getUserId());
\r
1678 Group group = user.getGroup();
\r
1680 if (group != null) {
\r
1681 groupLocalService.deleteGroup(group);
\r
1686 imageLocalService.deleteImage(user.getPortraitId());
\r
1688 // Password policy relation
\r
1690 passwordPolicyRelLocalService.deletePasswordPolicyRel(
\r
1691 User.class.getName(), user.getUserId());
\r
1695 passwordTrackerLocalService.deletePasswordTrackers(user.getUserId());
\r
1699 subscriptionLocalService.deleteSubscriptions(user.getUserId());
\r
1701 // External user ids
\r
1703 userIdMapperLocalService.deleteUserIdMappers(user.getUserId());
\r
1707 announcementsDeliveryLocalService.deleteDeliveries(user.getUserId());
\r
1711 assetEntryLocalService.deleteEntry(
\r
1712 User.class.getName(), user.getUserId());
\r
1716 blogsStatsUserLocalService.deleteStatsUserByUserId(user.getUserId());
\r
1718 // Document library
\r
1720 dlFileRankLocalService.deleteFileRanksByUserId(user.getUserId());
\r
1724 expandoValueLocalService.deleteValues(
\r
1725 User.class.getName(), user.getUserId());
\r
1729 mbBanLocalService.deleteBansByBanUserId(user.getUserId());
\r
1730 mbStatsUserLocalService.deleteStatsUsersByUserId(user.getUserId());
\r
1731 mbThreadFlagLocalService.deleteThreadFlagsByUserId(user.getUserId());
\r
1733 // Membership requests
\r
1735 membershipRequestLocalService.deleteMembershipRequestsByUserId(
\r
1736 user.getUserId());
\r
1740 shoppingCartLocalService.deleteUserCarts(user.getUserId());
\r
1744 socialActivityLocalService.deleteUserActivities(user.getUserId());
\r
1745 socialRequestLocalService.deleteReceiverUserRequests(user.getUserId());
\r
1746 socialRequestLocalService.deleteUserRequests(user.getUserId());
\r
1750 mailService.deleteUser(user.getCompanyId(), user.getUserId());
\r
1755 contactLocalService.deleteContact(user.getContactId());
\r
1757 catch (NoSuchContactException nsce) {
\r
1762 resourceLocalService.deleteResource(
\r
1763 user.getCompanyId(), User.class.getName(),
\r
1764 ResourceConstants.SCOPE_INDIVIDUAL, user.getUserId());
\r
1768 userGroupRoleLocalService.deleteUserGroupRolesByUserId(
\r
1769 user.getUserId());
\r
1773 userPersistence.remove(user);
\r
1775 // Permission cache
\r
1777 PermissionCacheUtil.clearCache();
\r
1781 workflowInstanceLinkLocalService.deleteWorkflowInstanceLinks(
\r
1782 user.getCompanyId(), 0, User.class.getName(), user.getUserId());
\r
1788 * Removes the user from the user group.
\r
1790 * @param userGroupId the primary key of the user group
\r
1791 * @param userId the primary key of the user
\r
1792 * @throws PortalException if a portal exception occurred
\r
1793 * @throws SystemException if a system exception occurred
\r
1795 public void deleteUserGroupUser(long userGroupId, long userId)
\r
1796 throws PortalException, SystemException {
\r
1798 userGroupPersistence.removeUser(userGroupId, userId);
\r
1800 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
1802 indexer.reindex(userId);
\r
1804 PermissionCacheUtil.clearCache();
\r
1808 * Encrypts the primary key of the user. Used when encrypting the user's
\r
1809 * credentials for storage in an automatic login cookie.
\r
1811 * @param name the primary key of the user
\r
1812 * @return the user's encrypted primary key
\r
1813 * @throws PortalException if a user with the primary key could not be found
\r
1814 * @throws SystemException if a system exception occurred
\r
1816 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
\r
1817 public String encryptUserId(String name)
\r
1818 throws PortalException, SystemException {
\r
1820 long userId = GetterUtil.getLong(name);
\r
1822 User user = userPersistence.findByPrimaryKey(userId);
\r
1824 Company company = companyPersistence.findByPrimaryKey(
\r
1825 user.getCompanyId());
\r
1828 return Encryptor.encrypt(company.getKeyObj(), name);
\r
1830 catch (EncryptorException ee) {
\r
1831 throw new SystemException(ee);
\r
1836 * Returns the user with the email address.
\r
1838 * @param companyId the primary key of the user's company
\r
1839 * @param emailAddress the user's email address
\r
1840 * @return the user with the email address, or <code>null</code> if a user
\r
1841 * with the email address could not be found
\r
1842 * @throws SystemException if a system exception occurred
\r
1844 public User fetchUserByEmailAddress(long companyId, String emailAddress)
\r
1845 throws SystemException {
\r
1847 return userPersistence.fetchByC_EA(companyId, emailAddress);
\r
1851 * Returns the user with the primary key.
\r
1853 * @param userId the primary key of the user
\r
1854 * @return the user with the primary key, or <code>null</code> if a user
\r
1855 * with the primary key could not be found
\r
1856 * @throws SystemException if a system exception occurred
\r
1858 public User fetchUserById(long userId) throws SystemException {
\r
1859 return userPersistence.fetchByPrimaryKey(userId);
\r
1863 * Returns the user with the screen name.
\r
1865 * @param companyId the primary key of the user's company
\r
1866 * @param screenName the user's screen name
\r
1867 * @return the user with the screen name, or <code>null</code> if a user
\r
1868 * with the screen name could not be found
\r
1869 * @throws SystemException if a system exception occurred
\r
1871 public User fetchUserByScreenName(long companyId, String screenName)
\r
1872 throws SystemException {
\r
1874 screenName = getScreenName(screenName);
\r
1876 return userPersistence.fetchByC_SN(companyId, screenName);
\r
1880 * Returns the users with the given email
\r
1882 public List<User> findUsersByEmail(String email) throws SystemException {
\r
1883 return userPersistence.findByEmailAddress(email);
\r
1888 * Returns a range of all the users belonging to the company.
\r
1891 * Useful when paginating results. Returns a maximum of <code>end -
\r
1892 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
1893 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
1894 * refers to the first result in the set. Setting both <code>start</code>
\r
1895 * and <code>end</code> to {@link
\r
1896 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
1900 * @param companyId the primary key of the company
\r
1901 * @param start the lower bound of the range of users
\r
1902 * @param end the upper bound of the range of users (not inclusive)
\r
1903 * @return the range of users belonging to the company
\r
1904 * @throws SystemException if a system exception occurred
\r
1906 public List<User> getCompanyUsers(long companyId, int start, int end)
\r
1907 throws SystemException {
\r
1909 return userPersistence.findByCompanyId(companyId, start, end);
\r
1913 * Returns the number of users belonging to the company.
\r
1915 * @param companyId the primary key of the company
\r
1916 * @return the number of users belonging to the company
\r
1917 * @throws SystemException if a system exception occurred
\r
1919 public int getCompanyUsersCount(long companyId) throws SystemException {
\r
1920 return userPersistence.countByCompanyId(companyId);
\r
1924 * Returns the default user for the company.
\r
1926 * @param companyId the primary key of the company
\r
1927 * @return the default user for the company
\r
1928 * @throws PortalException if a default user for the company could not be
\r
1930 * @throws SystemException if a system exception occurred
\r
1933 public User getDefaultUser(long companyId)
\r
1934 throws PortalException, SystemException {
\r
1936 User userModel = _defaultUsers.get(companyId);
\r
1938 if (userModel == null) {
\r
1939 userModel = userLocalService.loadGetDefaultUser(companyId);
\r
1941 _defaultUsers.put(companyId, userModel);
\r
1948 * Returns the primary key of the default user for the company.
\r
1950 * @param companyId the primary key of the company
\r
1951 * @return the primary key of the default user for the company
\r
1952 * @throws PortalException if a default user for the company could not be
\r
1954 * @throws SystemException if a system exception occurred
\r
1957 public long getDefaultUserId(long companyId)
\r
1958 throws PortalException, SystemException {
\r
1960 User user = getDefaultUser(companyId);
\r
1962 return user.getUserId();
\r
1966 * Returns the primary keys of all the users belonging to the group.
\r
1968 * @param groupId the primary key of the group
\r
1969 * @return the primary keys of the users belonging to the group
\r
1970 * @throws SystemException if a system exception occurred
\r
1972 public long[] getGroupUserIds(long groupId) throws SystemException {
\r
1973 return getUserIds(getGroupUsers(groupId));
\r
1977 * Returns all the users belonging to the group.
\r
1979 * @param groupId the primary key of the group
\r
1980 * @return the users belonging to the group
\r
1981 * @throws SystemException if a system exception occurred
\r
1983 public List<User> getGroupUsers(long groupId) throws SystemException {
\r
1984 return groupPersistence.getUsers(groupId);
\r
1988 * Returns the number of users belonging to the group.
\r
1990 * @param groupId the primary key of the group
\r
1991 * @return the number of users belonging to the group
\r
1992 * @throws SystemException if a system exception occurred
\r
1994 public int getGroupUsersCount(long groupId) throws SystemException {
\r
1995 return groupPersistence.getUsersSize(groupId);
\r
1999 * Returns the number of users with the status belonging to the group.
\r
2001 * @param groupId the primary key of the group
\r
2002 * @param status the workflow status
\r
2003 * @return the number of users with the status belonging to the group
\r
2004 * @throws PortalException if a group with the primary key could not be
\r
2006 * @throws SystemException if a system exception occurred
\r
2008 public int getGroupUsersCount(long groupId, int status)
\r
2009 throws PortalException, SystemException {
\r
2011 Group group = groupPersistence.findByPrimaryKey(groupId);
\r
2013 LinkedHashMap<String, Object> params =
\r
2014 new LinkedHashMap<String, Object>();
\r
2016 params.put("usersGroups", new Long(groupId));
\r
2018 return searchCount(group.getCompanyId(), null, status, params);
\r
2022 * Returns all the users who have not had any announcements of the type
\r
2023 * delivered, excluding the default user.
\r
2025 * @param type the type of announcement
\r
2026 * @return the users who have not had any annoucements of the type delivered
\r
2027 * @throws SystemException if a system exception occurred
\r
2029 public List<User> getNoAnnouncementsDeliveries(String type)
\r
2030 throws SystemException {
\r
2032 return userFinder.findByNoAnnouncementsDeliveries(type);
\r
2036 * Returns all the users who do not have any contacts.
\r
2038 * @return the users who do not have any contacts
\r
2039 * @throws SystemException if a system exception occurred
\r
2041 public List<User> getNoContacts() throws SystemException {
\r
2042 return userFinder.findByNoContacts();
\r
2046 * Returns all the users who do not belong to any groups, excluding the
\r
2049 * @return the users who do not belong to any groups
\r
2050 * @throws SystemException if a system exception occurred
\r
2052 public List<User> getNoGroups() throws SystemException {
\r
2053 return userFinder.findByNoGroups();
\r
2057 * Returns the primary keys of all the users belonging to the organization.
\r
2059 * @param organizationId the primary key of the organization
\r
2060 * @return the primary keys of the users belonging to the organization
\r
2061 * @throws SystemException if a system exception occurred
\r
2063 public long[] getOrganizationUserIds(long organizationId)
\r
2064 throws SystemException {
\r
2066 return getUserIds(getOrganizationUsers(organizationId));
\r
2070 * Returns all the users belonging to the organization.
\r
2072 * @param organizationId the primary key of the organization
\r
2073 * @return the users belonging to the organization
\r
2074 * @throws SystemException if a system exception occurred
\r
2076 public List<User> getOrganizationUsers(long organizationId)
\r
2077 throws SystemException {
\r
2079 return organizationPersistence.getUsers(organizationId);
\r
2083 public List<User> getOrganizationUsers(long organizationId,
\r
2084 int start, int stop) throws SystemException {
\r
2085 return organizationPersistence.getUsers(organizationId, start, stop);
\r
2088 public List<User> getOrganizationUsers(long organizationId,
\r
2089 int start, int stop, OrderByComparator orderComp) throws SystemException {
\r
2090 return organizationPersistence.getUsers(organizationId, start, stop, orderComp);
\r
2094 * Returns the number of users belonging to the organization.
\r
2096 * @param organizationId the primary key of the organization
\r
2097 * @return the number of users belonging to the organization
\r
2098 * @throws SystemException if a system exception occurred
\r
2100 public int getOrganizationUsersCount(long organizationId)
\r
2101 throws SystemException {
\r
2103 return organizationPersistence.getUsersSize(organizationId);
\r
2107 * Returns the number of users with the status belonging to the
\r
2110 * @param organizationId the primary key of the organization
\r
2111 * @param status the workflow status
\r
2112 * @return the number of users with the status belonging to the organization
\r
2113 * @throws PortalException if an organization with the primary key could not
\r
2115 * @throws SystemException if a system exception occurred
\r
2117 public int getOrganizationUsersCount(long organizationId, int status)
\r
2118 throws PortalException, SystemException {
\r
2120 Organization organization = organizationPersistence.findByPrimaryKey(
\r
2123 LinkedHashMap<String, Object> params =
\r
2124 new LinkedHashMap<String, Object>();
\r
2126 params.put("usersOrgs", new Long(organizationId));
\r
2128 return searchCount(organization.getCompanyId(), null, status, params);
\r
2132 * Returns the primary keys of all the users belonging to the role.
\r
2134 * @param roleId the primary key of the role
\r
2135 * @return the primary keys of the users belonging to the role
\r
2136 * @throws SystemException if a system exception occurred
\r
2138 public long[] getRoleUserIds(long roleId) throws SystemException {
\r
2139 return getUserIds(getRoleUsers(roleId));
\r
2143 * Returns all the users belonging to the role.
\r
2145 * @param roleId the primary key of the role
\r
2146 * @return the users belonging to the role
\r
2147 * @throws SystemException if a system exception occurred
\r
2149 public List<User> getRoleUsers(long roleId) throws SystemException {
\r
2150 return rolePersistence.getUsers(roleId);
\r
2154 * Returns a range of all the users belonging to the role.
\r
2157 * Useful when paginating results. Returns a maximum of <code>end -
\r
2158 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
2159 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
2160 * refers to the first result in the set. Setting both <code>start</code>
\r
2161 * and <code>end</code> to {@link
\r
2162 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
2166 * @param roleId the primary key of the role
\r
2167 * @param start the lower bound of the range of users
\r
2168 * @param end the upper bound of the range of users (not inclusive)
\r
2169 * @return the range of users belonging to the role
\r
2170 * @throws SystemException if a system exception occurred
\r
2172 public List<User> getRoleUsers(long roleId, int start, int end)
\r
2173 throws SystemException {
\r
2175 return rolePersistence.getUsers(roleId, start, end);
\r
2179 * Returns the number of users belonging to the role.
\r
2181 * @param roleId the primary key of the role
\r
2182 * @return the number of users belonging to the role
\r
2183 * @throws SystemException if a system exception occurred
\r
2185 public int getRoleUsersCount(long roleId) throws SystemException {
\r
2186 return rolePersistence.getUsersSize(roleId);
\r
2190 * Returns the number of users with the status belonging to the role.
\r
2192 * @param roleId the primary key of the role
\r
2193 * @param status the workflow status
\r
2194 * @return the number of users with the status belonging to the role
\r
2195 * @throws PortalException if an role with the primary key could not be
\r
2197 * @throws SystemException if a system exception occurred
\r
2199 public int getRoleUsersCount(long roleId, int status)
\r
2200 throws PortalException, SystemException {
\r
2202 Role role = rolePersistence.findByPrimaryKey(roleId);
\r
2204 LinkedHashMap<String, Object> params =
\r
2205 new LinkedHashMap<String, Object>();
\r
2207 params.put("usersRoles", new Long(roleId));
\r
2209 return searchCount(role.getCompanyId(), null, status, params);
\r
2213 * Returns an ordered range of all the users with a social relation of the
\r
2214 * type with the user.
\r
2217 * Useful when paginating results. Returns a maximum of <code>end -
\r
2218 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
2219 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
2220 * refers to the first result in the set. Setting both <code>start</code>
\r
2221 * and <code>end</code> to {@link
\r
2222 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
2226 * @param userId the primary key of the user
\r
2227 * @param type the type of social relation. The possible types can be found
\r
2229 * com.liferay.portlet.social.model.SocialRelationConstants}.
\r
2230 * @param start the lower bound of the range of users
\r
2231 * @param end the upper bound of the range of users (not inclusive)
\r
2232 * @param obc the comparator to order the users by (optionally
\r
2233 * <code>null</code>)
\r
2234 * @return the ordered range of users with a social relation of the type
\r
2236 * @throws PortalException if a user with the primary key could not be found
\r
2237 * @throws SystemException if a system exception occurred
\r
2239 public List<User> getSocialUsers(
\r
2240 long userId, int type, int start, int end, OrderByComparator obc)
\r
2241 throws PortalException, SystemException {
\r
2243 User user = userPersistence.findByPrimaryKey(userId);
\r
2245 LinkedHashMap<String, Object> params =
\r
2246 new LinkedHashMap<String, Object>();
\r
2248 params.put("socialRelationType", new Long[] {userId, new Long(type)});
\r
2251 user.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
\r
2252 params, start, end, obc);
\r
2256 * Returns an ordered range of all the users with a social relation with the
\r
2260 * Useful when paginating results. Returns a maximum of <code>end -
\r
2261 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
2262 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
2263 * refers to the first result in the set. Setting both <code>start</code>
\r
2264 * and <code>end</code> to {@link
\r
2265 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
2269 * @param userId the primary key of the user
\r
2270 * @param start the lower bound of the range of users
\r
2271 * @param end the upper bound of the range of users (not inclusive)
\r
2272 * @param obc the comparator to order the users by (optionally
\r
2273 * <code>null</code>)
\r
2274 * @return the ordered range of users with a social relation with the user
\r
2275 * @throws PortalException if a user with the primary key could not be found
\r
2276 * @throws SystemException if a system exception occurred
\r
2278 public List<User> getSocialUsers(
\r
2279 long userId, int start, int end, OrderByComparator obc)
\r
2280 throws PortalException, SystemException {
\r
2282 User user = userPersistence.findByPrimaryKey(userId);
\r
2284 LinkedHashMap<String, Object> params =
\r
2285 new LinkedHashMap<String, Object>();
\r
2287 params.put("socialRelation", new Long[] {userId});
\r
2290 user.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
\r
2291 params, start, end, obc);
\r
2295 * Returns an ordered range of all the users with a mutual social relation
\r
2296 * of the type with both of the given users.
\r
2299 * Useful when paginating results. Returns a maximum of <code>end -
\r
2300 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
2301 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
2302 * refers to the first result in the set. Setting both <code>start</code>
\r
2303 * and <code>end</code> to {@link
\r
2304 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
2308 * @param userId1 the primary key of the first user
\r
2309 * @param userId2 the primary key of the second user
\r
2310 * @param type the type of social relation. The possible types can be found
\r
2312 * com.liferay.portlet.social.model.SocialRelationConstants}.
\r
2313 * @param start the lower bound of the range of users
\r
2314 * @param end the upper bound of the range of users (not inclusive)
\r
2315 * @param obc the comparator to order the users by (optionally
\r
2316 * <code>null</code>)
\r
2317 * @return the ordered range of users with a mutual social relation of the
\r
2318 * type with the user
\r
2319 * @throws PortalException if a user with the primary key could not be found
\r
2320 * @throws SystemException if a system exception occurred
\r
2322 public List<User> getSocialUsers(
\r
2323 long userId1, long userId2, int type, int start, int end,
\r
2324 OrderByComparator obc)
\r
2325 throws PortalException, SystemException {
\r
2327 User user1 = userPersistence.findByPrimaryKey(userId1);
\r
2329 LinkedHashMap<String, Object> params =
\r
2330 new LinkedHashMap<String, Object>();
\r
2333 "socialMutualRelationType",
\r
2334 new Long[] {userId1, new Long(type), userId2, new Long(type)});
\r
2337 user1.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
\r
2338 params, start, end, obc);
\r
2342 * Returns an ordered range of all the users with a mutual social relation
\r
2343 * with both of the given users.
\r
2346 * Useful when paginating results. Returns a maximum of <code>end -
\r
2347 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
2348 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
2349 * refers to the first result in the set. Setting both <code>start</code>
\r
2350 * and <code>end</code> to {@link
\r
2351 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
2355 * @param userId1 the primary key of the first user
\r
2356 * @param userId2 the primary key of the second user
\r
2357 * @param start the lower bound of the range of users
\r
2358 * @param end the upper bound of the range of users (not inclusive)
\r
2359 * @param obc the comparator to order the users by (optionally
\r
2360 * <code>null</code>)
\r
2361 * @return the ordered range of users with a mutual social relation with the
\r
2363 * @throws PortalException if a user with the primary key could not be found
\r
2364 * @throws SystemException if a system exception occurred
\r
2366 public List<User> getSocialUsers(
\r
2367 long userId1, long userId2, int start, int end,
\r
2368 OrderByComparator obc)
\r
2369 throws PortalException, SystemException {
\r
2371 User user1 = userPersistence.findByPrimaryKey(userId1);
\r
2373 LinkedHashMap<String, Object> params =
\r
2374 new LinkedHashMap<String, Object>();
\r
2376 params.put("socialMutualRelation", new Long[] {userId1, userId2});
\r
2379 user1.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
\r
2380 params, start, end, obc);
\r
2384 * Returns the number of users with a social relation with the user.
\r
2386 * @param userId the primary key of the user
\r
2387 * @return the number of users with a social relation with the user
\r
2388 * @throws PortalException if a user with the primary key could not be found
\r
2389 * @throws SystemException if a system exception occurred
\r
2391 public int getSocialUsersCount(long userId)
\r
2392 throws PortalException, SystemException {
\r
2394 User user = userPersistence.findByPrimaryKey(userId);
\r
2396 LinkedHashMap<String, Object> params =
\r
2397 new LinkedHashMap<String, Object>();
\r
2399 params.put("socialRelation", new Long[] {userId});
\r
2401 return searchCount(
\r
2402 user.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
\r
2407 * Returns the number of users with a social relation of the type with the
\r
2410 * @param userId the primary key of the user
\r
2411 * @param type the type of social relation. The possible types can be found
\r
2413 * com.liferay.portlet.social.model.SocialRelationConstants}.
\r
2414 * @return the number of users with a social relation of the type with the
\r
2416 * @throws PortalException if a user with the primary key could not be found
\r
2417 * @throws SystemException if a system exception occurred
\r
2419 public int getSocialUsersCount(long userId, int type)
\r
2420 throws PortalException, SystemException {
\r
2422 User user = userPersistence.findByPrimaryKey(userId);
\r
2424 LinkedHashMap<String, Object> params =
\r
2425 new LinkedHashMap<String, Object>();
\r
2427 params.put("socialRelationType", new Long[] {userId, new Long(type)});
\r
2429 return searchCount(
\r
2430 user.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
\r
2435 * Returns the number of users with a mutual social relation with both of
\r
2436 * the given users.
\r
2438 * @param userId1 the primary key of the first user
\r
2439 * @param userId2 the primary key of the second user
\r
2440 * @return the number of users with a mutual social relation with the user
\r
2441 * @throws PortalException if a user with the primary key could not be found
\r
2442 * @throws SystemException if a system exception occurred
\r
2444 public int getSocialUsersCount(long userId1, long userId2)
\r
2445 throws PortalException, SystemException {
\r
2447 User user1 = userPersistence.findByPrimaryKey(userId1);
\r
2449 LinkedHashMap<String, Object> params =
\r
2450 new LinkedHashMap<String, Object>();
\r
2452 params.put("socialMutualRelation", new Long[] {userId1, userId2});
\r
2454 return searchCount(
\r
2455 user1.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
\r
2460 * Returns the number of users with a mutual social relation of the type
\r
2461 * with both of the given users.
\r
2463 * @param userId1 the primary key of the first user
\r
2464 * @param userId2 the primary key of the second user
\r
2465 * @param type the type of social relation. The possible types can be found
\r
2467 * com.liferay.portlet.social.model.SocialRelationConstants}.
\r
2468 * @return the number of users with a mutual social relation of the type
\r
2470 * @throws PortalException if a user with the primary key could not be found
\r
2471 * @throws SystemException if a system exception occurred
\r
2473 public int getSocialUsersCount(long userId1, long userId2, int type)
\r
2474 throws PortalException, SystemException {
\r
2476 User user1 = userPersistence.findByPrimaryKey(userId1);
\r
2478 LinkedHashMap<String, Object> params =
\r
2479 new LinkedHashMap<String, Object>();
\r
2482 "socialMutualRelationType",
\r
2483 new Long[] {userId1, new Long(type), userId2, new Long(type)});
\r
2485 return searchCount(
\r
2486 user1.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED,
\r
2491 * Returns the user with the contact ID.
\r
2493 * @param contactId the user's contact ID
\r
2494 * @return the user with the contact ID
\r
2495 * @throws PortalException if a user with the contact ID could not be found
\r
2496 * @throws SystemException if a system exception occurred
\r
2498 public User getUserByContactId(long contactId)
\r
2499 throws PortalException, SystemException {
\r
2501 return userPersistence.findByContactId(contactId);
\r
2505 * Returns the user with the email address.
\r
2507 * @param companyId the primary key of the user's company
\r
2508 * @param emailAddress the user's email address
\r
2509 * @return the user with the email address
\r
2510 * @throws PortalException if a user with the email address could not be
\r
2512 * @throws SystemException if a system exception occurred
\r
2514 public User getUserByEmailAddress(long companyId, String emailAddress)
\r
2515 throws PortalException, SystemException {
\r
2517 emailAddress = emailAddress.trim().toLowerCase();
\r
2519 return userPersistence.findByC_EA(companyId, emailAddress);
\r
2523 * Returns the user with the Facebook ID.
\r
2525 * @param companyId the primary key of the user's company
\r
2526 * @param facebookId the user's Facebook ID
\r
2527 * @return the user with the Facebook ID
\r
2528 * @throws PortalException if a user with the Facebook ID could not be found
\r
2529 * @throws SystemException if a system exception occurred
\r
2531 public User getUserByFacebookId(long companyId, long facebookId)
\r
2532 throws PortalException, SystemException {
\r
2534 return userPersistence.findByC_FID(companyId, facebookId);
\r
2538 * Returns the user with the primary key.
\r
2540 * @param userId the primary key of the user
\r
2541 * @return the user with the primary key
\r
2542 * @throws PortalException if a user with the primary key could not be found
\r
2543 * @throws SystemException if a system exception occurred
\r
2545 public User getUserById(long userId)
\r
2546 throws PortalException, SystemException {
\r
2548 return userPersistence.findByPrimaryKey(userId);
\r
2552 * Returns the user with the primary key from the company.
\r
2554 * @param companyId the primary key of the user's company
\r
2555 * @param userId the primary key of the user
\r
2556 * @return the user with the primary key
\r
2557 * @throws PortalException if a user with the primary key from the company
\r
2558 * could not be found
\r
2559 * @throws SystemException if a system exception occurred
\r
2561 public User getUserById(long companyId, long userId)
\r
2562 throws PortalException, SystemException {
\r
2564 return userPersistence.findByC_U(companyId, userId);
\r
2568 * Returns the user with the OpenID.
\r
2570 * @param companyId the primary key of the user's company
\r
2571 * @param openId the user's OpenID
\r
2572 * @return the user with the OpenID
\r
2573 * @throws PortalException if a user with the OpenID could not be found
\r
2574 * @throws SystemException if a system exception occurred
\r
2576 public User getUserByOpenId(long companyId, String openId)
\r
2577 throws PortalException, SystemException {
\r
2579 return userPersistence.findByC_O(companyId, openId);
\r
2583 * Returns the user with the portrait ID.
\r
2585 * @param portraitId the user's portrait ID
\r
2586 * @return the user with the portrait ID
\r
2587 * @throws PortalException if a user with the portrait ID could not be found
\r
2588 * @throws SystemException if a system exception occurred
\r
2590 public User getUserByPortraitId(long portraitId)
\r
2591 throws PortalException, SystemException {
\r
2593 return userPersistence.findByPortraitId(portraitId);
\r
2597 * Returns the user with the screen name.
\r
2599 * @param companyId the primary key of the user's company
\r
2600 * @param screenName the user's screen name
\r
2601 * @return the user with the screen name
\r
2602 * @throws PortalException if a user with the screen name could not be found
\r
2603 * @throws SystemException if a system exception occurred
\r
2605 public User getUserByScreenName(long companyId, String screenName)
\r
2606 throws PortalException, SystemException {
\r
2608 screenName = getScreenName(screenName);
\r
2610 return userPersistence.findByC_SN(companyId, screenName);
\r
2614 * Returns the user with the universally unique identifier.
\r
2616 * @param uuid the user's universally unique identifier
\r
2617 * @return the user with the universally unique identifier
\r
2618 * @throws PortalException if a user with the universally unique identifier
\r
2619 * could not be found
\r
2620 * @throws SystemException if a system exception occurred
\r
2622 public User getUserByUuid(String uuid)
\r
2623 throws PortalException, SystemException {
\r
2625 List<User> users = userPersistence.findByUuid(uuid);
\r
2627 if (users.isEmpty()) {
\r
2628 throw new NoSuchUserException();
\r
2631 return users.get(0);
\r
2636 * Returns all the users belonging to the user group.
\r
2638 * @param userGroupId the primary key of the user group
\r
2639 * @return the users belonging to the user group
\r
2640 * @throws SystemException if a system exception occurred
\r
2642 public List<User> getUserGroupUsers(long userGroupId)
\r
2643 throws SystemException {
\r
2645 return userGroupPersistence.getUsers(userGroupId);
\r
2649 * Returns the number of users belonging to the user group.
\r
2651 * @param userGroupId the primary key of the user group
\r
2652 * @return the number of users belonging to the user group
\r
2653 * @throws SystemException if a system exception occurred
\r
2655 public int getUserGroupUsersCount(long userGroupId) throws SystemException {
\r
2656 return userGroupPersistence.getUsersSize(userGroupId);
\r
2660 * Returns the number of users with the status belonging to the user group.
\r
2662 * @param userGroupId the primary key of the user group
\r
2663 * @param status the workflow status
\r
2664 * @return the number of users with the status belonging to the user group
\r
2665 * @throws PortalException if a user group with the primary key could not be
\r
2667 * @throws SystemException if a system exception occurred
\r
2669 public int getUserGroupUsersCount(long userGroupId, int status)
\r
2670 throws PortalException, SystemException {
\r
2672 UserGroup userGroup = userGroupPersistence.findByPrimaryKey(
\r
2675 LinkedHashMap<String, Object> params =
\r
2676 new LinkedHashMap<String, Object>();
\r
2678 params.put("usersUserGroups", new Long(userGroupId));
\r
2680 return searchCount(userGroup.getCompanyId(), null, status, params);
\r
2684 * Returns the primary key of the user with the email address.
\r
2686 * @param companyId the primary key of the user's company
\r
2687 * @param emailAddress the user's email address
\r
2688 * @return the primary key of the user with the email address
\r
2689 * @throws PortalException if a user with the email address could not be
\r
2691 * @throws SystemException if a system exception occurred
\r
2693 public long getUserIdByEmailAddress(long companyId, String emailAddress)
\r
2694 throws PortalException, SystemException {
\r
2696 emailAddress = emailAddress.trim().toLowerCase();
\r
2698 User user = userPersistence.findByC_EA(companyId, emailAddress);
\r
2700 return user.getUserId();
\r
2704 * Returns the primary key of the user with the screen name.
\r
2706 * @param companyId the primary key of the user's company
\r
2707 * @param screenName the user's screen name
\r
2708 * @return the primary key of the user with the screen name
\r
2709 * @throws PortalException if a user with the screen name could not be found
\r
2710 * @throws SystemException if a system exception occurred
\r
2712 public long getUserIdByScreenName(long companyId, String screenName)
\r
2713 throws PortalException, SystemException {
\r
2715 screenName = getScreenName(screenName);
\r
2717 User user = userPersistence.findByC_SN(companyId, screenName);
\r
2719 return user.getUserId();
\r
2723 * Returns <code>true</code> if the user is a member of the group.
\r
2725 * @param groupId the primary key of the group
\r
2726 * @param userId the primary key of the user
\r
2727 * @return <code>true</code> if the user is a member of the group;
\r
2728 * <code>false</code> otherwise
\r
2729 * @throws SystemException if a system exception occurred
\r
2731 public boolean hasGroupUser(long groupId, long userId)
\r
2732 throws SystemException {
\r
2734 return groupPersistence.containsUser(groupId, userId);
\r
2738 * Returns <code>true</code> if the user is a member of the organization.
\r
2740 * @param organizationId the primary key of the organization
\r
2741 * @param userId the primary key of the user
\r
2742 * @return <code>true</code> if the user is a member of the organization;
\r
2743 * <code>false</code> otherwise
\r
2744 * @throws SystemException if a system exception occurred
\r
2746 public boolean hasOrganizationUser(long organizationId, long userId)
\r
2747 throws SystemException {
\r
2749 return organizationPersistence.containsUser(organizationId, userId);
\r
2753 * Returns <code>true</code> if the password policy has been assigned to the
\r
2756 * @param passwordPolicyId the primary key of the password policy
\r
2757 * @param userId the primary key of the user
\r
2758 * @return <code>true</code> if the password policy is assigned to the user;
\r
2759 * <code>false</code> otherwise
\r
2760 * @throws SystemException if a system exception occurred
\r
2762 public boolean hasPasswordPolicyUser(long passwordPolicyId, long userId)
\r
2763 throws SystemException {
\r
2765 return passwordPolicyRelLocalService.hasPasswordPolicyRel(
\r
2766 passwordPolicyId, User.class.getName(), userId);
\r
2770 * Returns <code>true</code> if the user is a member of the role.
\r
2772 * @param roleId the primary key of the role
\r
2773 * @param userId the primary key of the user
\r
2774 * @return <code>true</code> if the user is a member of the role;
\r
2775 * <code>false</code> otherwise
\r
2776 * @throws SystemException if a system exception occurred
\r
2778 public boolean hasRoleUser(long roleId, long userId)
\r
2779 throws SystemException {
\r
2781 return rolePersistence.containsUser(roleId, userId);
\r
2785 * Returns <code>true</code> if the user has the role with the name,
\r
2786 * optionally through inheritance.
\r
2788 * @param companyId the primary key of the role's company
\r
2789 * @param name the name of the role (must be a regular role, not an
\r
2790 * organization, site or provider role)
\r
2791 * @param userId the primary key of the user
\r
2792 * @param inherited whether to include roles inherited from organizations,
\r
2794 * @return <code>true</code> if the user has the role; <code>false</code>
\r
2796 * @throws PortalException if a role with the name could not be found
\r
2797 * @throws SystemException if a system exception occurred
\r
2799 public boolean hasRoleUser(
\r
2800 long companyId, String name, long userId, boolean inherited)
\r
2801 throws PortalException, SystemException {
\r
2803 return roleLocalService.hasUserRole(userId, companyId, name, inherited);
\r
2807 * Returns <code>true</code> if the user is a member of the team.
\r
2809 * @param teamId the primary key of the team
\r
2810 * @param userId the primary key of the user
\r
2811 * @return <code>true</code> if the user is a member of the team;
\r
2812 * <code>false</code> otherwise
\r
2813 * @throws SystemException if a system exception occurred
\r
2815 public boolean hasTeamUser(long teamId, long userId)
\r
2816 throws SystemException {
\r
2818 return teamPersistence.containsUser(teamId, userId);
\r
2822 * Returns <code>true</code> if the user is a member of the user group.
\r
2824 * @param userGroupId the primary key of the user group
\r
2825 * @param userId the primary key of the user
\r
2826 * @return <code>true</code> if the user is a member of the user group;
\r
2827 * <code>false</code> otherwise
\r
2828 * @throws SystemException if a system exception occurred
\r
2830 public boolean hasUserGroupUser(long userGroupId, long userId)
\r
2831 throws SystemException {
\r
2833 return userGroupPersistence.containsUser(userGroupId, userId);
\r
2837 * Returns <code>true</code> if the user's password is expired.
\r
2839 * @param user the user
\r
2840 * @return <code>true</code> if the user's password is expired;
\r
2841 * <code>false</code> otherwise
\r
2842 * @throws PortalException if the password policy for the user could not be
\r
2844 * @throws SystemException if a system exception occurred
\r
2846 public boolean isPasswordExpired(User user)
\r
2847 throws PortalException, SystemException {
\r
2849 PasswordPolicy passwordPolicy = user.getPasswordPolicy();
\r
2851 if (passwordPolicy.getExpireable()) {
\r
2852 Date now = new Date();
\r
2854 if (user.getPasswordModifiedDate() == null) {
\r
2855 user.setPasswordModifiedDate(now);
\r
2857 userLocalService.updateUser(user, false);
\r
2860 long passwordStartTime = user.getPasswordModifiedDate().getTime();
\r
2861 long elapsedTime = now.getTime() - passwordStartTime;
\r
2863 if (elapsedTime > (passwordPolicy.getMaxAge() * 1000)) {
\r
2875 * Returns <code>true</code> if the user's password is expiring soon.
\r
2877 * @param user the user
\r
2878 * @return <code>true</code> if the user's password is expiring soon;
\r
2879 * <code>false</code> otherwise
\r
2880 * @throws PortalException if the password policy for the user could not be
\r
2882 * @throws SystemException if a system exception occurred
\r
2884 public boolean isPasswordExpiringSoon(User user)
\r
2885 throws PortalException, SystemException {
\r
2887 PasswordPolicy passwordPolicy = user.getPasswordPolicy();
\r
2889 if (passwordPolicy.isExpireable()) {
\r
2890 Date now = new Date();
\r
2892 if (user.getPasswordModifiedDate() == null) {
\r
2893 user.setPasswordModifiedDate(now);
\r
2895 userLocalService.updateUser(user, false);
\r
2898 long timeModified = user.getPasswordModifiedDate().getTime();
\r
2899 long passwordExpiresOn =
\r
2900 (passwordPolicy.getMaxAge() * 1000) + timeModified;
\r
2902 long timeStartWarning =
\r
2903 passwordExpiresOn - (passwordPolicy.getWarningTime() * 1000);
\r
2905 if (now.getTime() > timeStartWarning) {
\r
2916 public User loadGetDefaultUser(long companyId)
\r
2917 throws PortalException, SystemException {
\r
2919 return userPersistence.findByC_DU(companyId, true);
\r
2923 * Returns an ordered range of all the users who match the keywords and
\r
2924 * status, without using the indexer. It is preferable to use the indexed
\r
2925 * version {@link #search(long, String, int, LinkedHashMap, int, int, Sort)}
\r
2926 * instead of this method wherever possible for performance reasons.
\r
2929 * Useful when paginating results. Returns a maximum of <code>end -
\r
2930 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
2931 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
2932 * refers to the first result in the set. Setting both <code>start</code>
\r
2933 * and <code>end</code> to {@link
\r
2934 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
2938 * @param companyId the primary key of the user's company
\r
2939 * @param keywords the keywords (space separated), which may occur in the
\r
2940 * user's first name, middle name, last name, screen name, or email
\r
2942 * @param status the workflow status
\r
2943 * @param params the finder parameters (optionally <code>null</code>). For
\r
2944 * more information see {@link
\r
2945 * com.liferay.portal.service.persistence.UserFinder}.
\r
2946 * @param start the lower bound of the range of users
\r
2947 * @param end the upper bound of the range of users (not inclusive)
\r
2948 * @param obc the comparator to order the users by (optionally
\r
2949 * <code>null</code>)
\r
2950 * @return the matching users
\r
2951 * @throws SystemException if a system exception occurred
\r
2952 * @see com.liferay.portal.service.persistence.UserFinder
\r
2954 public List<User> search(
\r
2955 long companyId, String keywords, int status,
\r
2956 LinkedHashMap<String, Object> params, int start, int end,
\r
2957 OrderByComparator obc)
\r
2958 throws SystemException {
\r
2960 return userFinder.findByKeywords(
\r
2961 companyId, keywords, status, params, start, end, obc);
\r
2965 * Returns an ordered range of all the users who match the keywords and
\r
2966 * status, using the indexer. It is preferable to use this method instead of
\r
2967 * the non-indexed version whenever possible for performance reasons.
\r
2970 * Useful when paginating results. Returns a maximum of <code>end -
\r
2971 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
2972 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
2973 * refers to the first result in the set. Setting both <code>start</code>
\r
2974 * and <code>end</code> to {@link
\r
2975 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
2979 * @param companyId the primary key of the user's company
\r
2980 * @param keywords the keywords (space separated), which may occur in the
\r
2981 * user's first name, middle name, last name, screen name, or email
\r
2983 * @param status the workflow status
\r
2984 * @param params the indexer parameters (optionally <code>null</code>). For
\r
2985 * more information see {@link
\r
2986 * com.liferay.portlet.usersadmin.util.UserIndexer}.
\r
2987 * @param start the lower bound of the range of users
\r
2988 * @param end the upper bound of the range of users (not inclusive)
\r
2989 * @param sort the field and direction to sort by (optionally
\r
2990 * <code>null</code>)
\r
2991 * @return the matching users
\r
2992 * @throws SystemException if a system exception occurred
\r
2993 * @see com.liferay.portlet.usersadmin.util.UserIndexer
\r
2995 public Hits search(
\r
2996 long companyId, String keywords, int status,
\r
2997 LinkedHashMap<String, Object> params, int start, int end, Sort sort)
\r
2998 throws SystemException {
\r
3000 String firstName = null;
\r
3001 String middleName = null;
\r
3002 String lastName = null;
\r
3003 String fullName = null;
\r
3004 String screenName = null;
\r
3005 String emailAddress = null;
\r
3006 String street = null;
\r
3007 String city = null;
\r
3008 String zip = null;
\r
3009 String region = null;
\r
3010 String country = null;
\r
3011 boolean andOperator = false;
\r
3013 if (Validator.isNotNull(keywords)) {
\r
3014 firstName = keywords;
\r
3015 middleName = keywords;
\r
3016 lastName = keywords;
\r
3017 fullName = keywords;
\r
3018 screenName = keywords;
\r
3019 emailAddress = keywords;
\r
3020 street = keywords;
\r
3023 region = keywords;
\r
3024 country = keywords;
\r
3027 andOperator = true;
\r
3030 if (params != null) {
\r
3031 params.put("keywords", keywords);
\r
3035 companyId, firstName, middleName, lastName, fullName, screenName,
\r
3036 emailAddress, street, city, zip, region, country, status, params,
\r
3037 andOperator, start, end, sort);
\r
3041 * Returns an ordered range of all the users with the status, and whose
\r
3042 * first name, middle name, last name, screen name, and email address match
\r
3043 * the keywords specified for them, without using the indexer. It is
\r
3044 * preferable to use the indexed version {@link #search(long, String,
\r
3045 * String, String, String, String, int, LinkedHashMap, boolean, int, int,
\r
3046 * Sort)} instead of this method wherever possible for performance reasons.
\r
3049 * Useful when paginating results. Returns a maximum of <code>end -
\r
3050 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
3051 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
3052 * refers to the first result in the set. Setting both <code>start</code>
\r
3053 * and <code>end</code> to {@link
\r
3054 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
3058 * @param companyId the primary key of the user's company
\r
3059 * @param firstName the first name keywords (space separated)
\r
3060 * @param middleName the middle name keywords
\r
3061 * @param lastName the last name keywords
\r
3062 * @param screenName the screen name keywords
\r
3063 * @param emailAddress the email address keywords
\r
3064 * @param status the workflow status
\r
3065 * @param params the finder parameters (optionally <code>null</code>). For
\r
3066 * more information see {@link
\r
3067 * com.liferay.portal.service.persistence.UserFinder}.
\r
3068 * @param andSearch whether every field must match its keywords, or just
\r
3069 * one field. For example, "users with the first name 'bob' and
\r
3070 * last name 'smith'" vs "users with the first name 'bob'
\r
3071 * or the last name 'smith'".
\r
3072 * @param start the lower bound of the range of users
\r
3073 * @param end the upper bound of the range of users (not inclusive)
\r
3074 * @param obc the comparator to order the users by (optionally
\r
3075 * <code>null</code>)
\r
3076 * @return the matching users
\r
3077 * @throws SystemException if a system exception occurred
\r
3078 * @see com.liferay.portal.service.persistence.UserFinder
\r
3080 public List<User> search(
\r
3081 long companyId, String firstName, String middleName,
\r
3082 String lastName, String screenName, String emailAddress, int status,
\r
3083 LinkedHashMap<String, Object> params, boolean andSearch, int start,
\r
3084 int end, OrderByComparator obc)
\r
3085 throws SystemException {
\r
3087 return userFinder.findByC_FN_MN_LN_SN_EA_S(
\r
3088 companyId, firstName, middleName, lastName, screenName,
\r
3089 emailAddress, status, params, andSearch, start, end, obc);
\r
3093 * Returns an ordered range of all the users with the status, and whose
\r
3094 * first name, middle name, last name, screen name, and email address match
\r
3095 * the keywords specified for them, using the indexer. It is preferable to
\r
3096 * use this method instead of the non-indexed version whenever possible for
\r
3097 * performance reasons.
\r
3100 * Useful when paginating results. Returns a maximum of <code>end -
\r
3101 * start</code> instances. <code>start</code> and <code>end</code> are not
\r
3102 * primary keys, they are indexes in the result set. Thus, <code>0</code>
\r
3103 * refers to the first result in the set. Setting both <code>start</code>
\r
3104 * and <code>end</code> to {@link
\r
3105 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
\r
3109 * @param companyId the primary key of the user's company
\r
3110 * @param firstName the first name keywords (space separated)
\r
3111 * @param middleName the middle name keywords
\r
3112 * @param lastName the last name keywords
\r
3113 * @param screenName the screen name keywords
\r
3114 * @param emailAddress the email address keywords
\r
3115 * @param status the workflow status
\r
3116 * @param params the indexer parameters (optionally <code>null</code>). For
\r
3117 * more information see {@link
\r
3118 * com.liferay.portlet.usersadmin.util.UserIndexer}.
\r
3119 * @param andSearch whether every field must match its keywords, or just
\r
3120 * one field. For example, "users with the first name 'bob' and
\r
3121 * last name 'smith'" vs "users with the first name 'bob'
\r
3122 * or the last name 'smith'".
\r
3123 * @param start the lower bound of the range of users
\r
3124 * @param end the upper bound of the range of users (not inclusive)
\r
3125 * @param sort the field and direction to sort by (optionally
\r
3126 * <code>null</code>)
\r
3127 * @return the matching users
\r
3128 * @throws SystemException if a system exception occurred
\r
3129 * @see com.liferay.portlet.usersadmin.util.UserIndexer
\r
3131 public Hits search(
\r
3132 long companyId, String firstName, String middleName,
\r
3133 String lastName, String screenName, String emailAddress, int status,
\r
3134 LinkedHashMap<String, Object> params, boolean andSearch, int start,
\r
3135 int end, Sort sort)
\r
3136 throws SystemException {
\r
3139 companyId, firstName, middleName, lastName, null, screenName,
\r
3140 emailAddress, null, null, null, null, null, status, params,
\r
3141 andSearch, start, end, sort);
\r
3145 * Returns the number of users who match the keywords and status.
\r
3147 * @param companyId the primary key of the user's company
\r
3148 * @param keywords the keywords (space separated), which may occur in the
\r
3149 * user's first name, middle name, last name, screen name, or email
\r
3151 * @param status the workflow status
\r
3152 * @param params the finder parameters (optionally <code>null</code>). For
\r
3153 * more information see {@link
\r
3154 * com.liferay.portal.service.persistence.UserFinder}.
\r
3155 * @return the number matching users
\r
3156 * @throws SystemException if a system exception occurred
\r
3158 public int searchCount(
\r
3159 long companyId, String keywords, int status,
\r
3160 LinkedHashMap<String, Object> params)
\r
3161 throws SystemException {
\r
3163 return userFinder.countByKeywords(companyId, keywords, status, params);
\r
3167 * Returns the number of users with the status, and whose first name, middle
\r
3168 * name, last name, screen name, and email address match the keywords
\r
3169 * specified for them.
\r
3171 * @param companyId the primary key of the user's company
\r
3172 * @param firstName the first name keywords (space separated)
\r
3173 * @param middleName the middle name keywords
\r
3174 * @param lastName the last name keywords
\r
3175 * @param screenName the screen name keywords
\r
3176 * @param emailAddress the email address keywords
\r
3177 * @param status the workflow status
\r
3178 * @param params the finder parameters (optionally <code>null</code>). For
\r
3179 * more information see {@link
\r
3180 * com.liferay.portal.service.persistence.UserFinder}.
\r
3181 * @param andSearch whether every field must match its keywords, or just
\r
3182 * one field. For example, "users with the first name 'bob' and
\r
3183 * last name 'smith'" vs "users with the first name 'bob'
\r
3184 * or the last name 'smith'".
\r
3185 * @return the number of matching users
\r
3186 * @throws SystemException if a system exception occurred
\r
3188 public int searchCount(
\r
3189 long companyId, String firstName, String middleName,
\r
3190 String lastName, String screenName, String emailAddress, int status,
\r
3191 LinkedHashMap<String, Object> params, boolean andSearch)
\r
3192 throws SystemException {
\r
3194 return userFinder.countByC_FN_MN_LN_SN_EA_S(
\r
3195 companyId, firstName, middleName, lastName, screenName,
\r
3196 emailAddress, status, params, andSearch);
\r
3200 * Sends an email address verification to the user.
\r
3202 * @param user the verification email recipient
\r
3203 * @param emailAddress the recipient's email address
\r
3204 * @param serviceContext the service context. Must set the portal URL, main
\r
3205 * path, primary key of the layout, remote address, remote host, and
\r
3206 * agent for the user.
\r
3207 * @throws PortalException if a portal exception occurred
\r
3208 * @throws SystemException if a system exception occurred
\r
3210 public void sendEmailAddressVerification(
\r
3211 User user, String emailAddress, ServiceContext serviceContext)
\r
3212 throws PortalException, SystemException {
\r
3214 if (user.isEmailAddressVerified() &&
\r
3215 emailAddress.equalsIgnoreCase(user.getEmailAddress())) {
\r
3220 Ticket ticket = ticketLocalService.addTicket(
\r
3221 user.getCompanyId(), User.class.getName(), user.getUserId(),
\r
3222 TicketConstants.TYPE_EMAIL_ADDRESS, emailAddress, null,
\r
3225 String verifyEmailAddressURL =
\r
3226 serviceContext.getPortalURL() + serviceContext.getPathMain() +
\r
3227 "/portal/verify_email_address?ticketKey=" + ticket.getKey();
\r
3229 Layout layout = layoutLocalService.getLayout(serviceContext.getPlid());
\r
3231 Group group = layout.getGroup();
\r
3233 if (!layout.isPrivateLayout() && !group.isUser()) {
\r
3234 verifyEmailAddressURL += "&p_l_id=" + serviceContext.getPlid();
\r
3237 String fromName = PrefsPropsUtil.getString(
\r
3238 user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
\r
3239 String fromAddress = PrefsPropsUtil.getString(
\r
3240 user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
\r
3242 String toName = user.getFullName();
\r
3243 String toAddress = emailAddress;
\r
3245 String subject = PrefsPropsUtil.getContent(
\r
3246 user.getCompanyId(), PropsKeys.ADMIN_EMAIL_VERIFICATION_SUBJECT);
\r
3248 String body = PrefsPropsUtil.getContent(
\r
3249 user.getCompanyId(), PropsKeys.ADMIN_EMAIL_VERIFICATION_BODY);
\r
3251 SubscriptionSender subscriptionSender = new SubscriptionSender();
\r
3253 subscriptionSender.setBody(body);
\r
3254 subscriptionSender.setCompanyId(user.getCompanyId());
\r
3255 subscriptionSender.setContextAttributes(
\r
3256 "[$EMAIL_VERIFICATION_CODE$]", ticket.getKey(),
\r
3257 "[$EMAIL_VERIFICATION_URL$]", verifyEmailAddressURL,
\r
3258 "[$REMOTE_ADDRESS$]", serviceContext.getRemoteAddr(),
\r
3259 "[$REMOTE_HOST$]", serviceContext.getRemoteHost(), "[$USER_ID$]",
\r
3260 user.getUserId(), "[$USER_SCREENNAME$]", user.getScreenName());
\r
3261 subscriptionSender.setFrom(fromAddress, fromName);
\r
3262 subscriptionSender.setHtmlFormat(true);
\r
3263 subscriptionSender.setMailId("user", user.getUserId());
\r
3264 subscriptionSender.setServiceContext(serviceContext);
\r
3265 subscriptionSender.setSubject(subject);
\r
3266 subscriptionSender.setUserId(user.getUserId());
\r
3268 subscriptionSender.addRuntimeSubscribers(toAddress, toName);
\r
3270 subscriptionSender.flushNotificationsAsync();
\r
3274 * Sends the password email to the user with the email address. The content
\r
3275 * of this email can be specified in <code>portal.properties</code> with the
\r
3276 * <code>admin.email.password</code> keys.
\r
3278 * @param companyId the primary key of the user's company
\r
3279 * @param emailAddress the user's email address
\r
3280 * @param fromName the name of the individual that the email should be from
\r
3281 * @param fromAddress the address of the individual that the email should
\r
3283 * @param subject the email subject. If <code>null</code>, the subject
\r
3284 * specified in <code>portal.properties</code> will be used.
\r
3285 * @param body the email body. If <code>null</code>, the body specified in
\r
3286 * <code>portal.properties</code> will be used.
\r
3287 * @param serviceContext the user's service context
\r
3288 * @throws PortalException if a user with the email address could not be
\r
3290 * @throws SystemException if a system exception occurred
\r
3292 public void sendPassword(
\r
3293 long companyId, String emailAddress, String fromName,
\r
3294 String fromAddress, String subject, String body,
\r
3295 ServiceContext serviceContext)
\r
3296 throws PortalException, SystemException {
\r
3298 Company company = companyPersistence.findByPrimaryKey(companyId);
\r
3300 if (!company.isSendPassword() && !company.isSendPasswordResetLink()) {
\r
3304 emailAddress = emailAddress.trim().toLowerCase();
\r
3306 if (Validator.isNull(emailAddress)) {
\r
3307 throw new UserEmailAddressException();
\r
3310 User user = userPersistence.findByC_EA(companyId, emailAddress);
\r
3312 PasswordPolicy passwordPolicy = user.getPasswordPolicy();
\r
3314 String newPassword = StringPool.BLANK;
\r
3315 String passwordResetURL = StringPool.BLANK;
\r
3317 if (company.isSendPasswordResetLink()) {
\r
3318 Date expirationDate = null;
\r
3320 if (passwordPolicy.getResetTicketMaxAge() > 0) {
\r
3321 expirationDate = new Date(
\r
3322 System.currentTimeMillis() +
\r
3323 (passwordPolicy.getResetTicketMaxAge() * 1000));
\r
3326 Ticket ticket = ticketLocalService.addTicket(
\r
3327 companyId, User.class.getName(), user.getUserId(),
\r
3328 TicketConstants.TYPE_PASSWORD, null, expirationDate,
\r
3331 passwordResetURL =
\r
3332 serviceContext.getPortalURL() + serviceContext.getPathMain() +
\r
3333 "/portal/update_password?p_l_id="+
\r
3334 serviceContext.getPlid() +
\r
3335 "&ticketKey=" + ticket.getKey();
\r
3338 if (!PwdEncryptor.PASSWORDS_ENCRYPTION_ALGORITHM.equals(
\r
3339 PwdEncryptor.TYPE_NONE)) {
\r
3341 newPassword = PwdToolkitUtil.generate(passwordPolicy);
\r
3343 boolean passwordReset = false;
\r
3345 if (passwordPolicy.getChangeable() &&
\r
3346 passwordPolicy.getChangeRequired()) {
\r
3348 passwordReset = true;
\r
3351 user.setPassword(PwdEncryptor.encrypt(newPassword));
\r
3352 user.setPasswordUnencrypted(newPassword);
\r
3353 user.setPasswordEncrypted(true);
\r
3354 user.setPasswordReset(passwordReset);
\r
3355 user.setPasswordModified(true);
\r
3356 user.setPasswordModifiedDate(new Date());
\r
3358 userPersistence.update(user, false);
\r
3360 user.setPasswordModified(false);
\r
3363 newPassword = user.getPassword();
\r
3367 if (Validator.isNull(fromName)) {
\r
3368 fromName = PrefsPropsUtil.getString(
\r
3369 companyId, PropsKeys.ADMIN_EMAIL_FROM_NAME);
\r
3372 if (Validator.isNull(fromAddress)) {
\r
3373 fromAddress = PrefsPropsUtil.getString(
\r
3374 companyId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
\r
3377 String toName = user.getFullName();
\r
3378 String toAddress = user.getEmailAddress();
\r
3380 if (Validator.isNull(subject)) {
\r
3381 if (company.isSendPasswordResetLink()) {
\r
3382 subject = PrefsPropsUtil.getContent(
\r
3383 companyId, PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_SUBJECT);
\r
3386 subject = PrefsPropsUtil.getContent(
\r
3387 companyId, PropsKeys.ADMIN_EMAIL_PASSWORD_SENT_SUBJECT);
\r
3391 if (Validator.isNull(body)) {
\r
3392 if (company.isSendPasswordResetLink()) {
\r
3393 body = PrefsPropsUtil.getContent(
\r
3394 companyId, PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_BODY);
\r
3397 body = PrefsPropsUtil.getContent(
\r
3398 companyId, PropsKeys.ADMIN_EMAIL_PASSWORD_SENT_BODY);
\r
3402 SubscriptionSender subscriptionSender = new SubscriptionSender();
\r
3404 subscriptionSender.setBody(body);
\r
3405 subscriptionSender.setCompanyId(companyId);
\r
3406 subscriptionSender.setContextAttributes(
\r
3407 "[$PASSWORD_RESET_URL$]", passwordResetURL, "[$REMOTE_ADDRESS$]",
\r
3408 serviceContext.getRemoteAddr(), "[$REMOTE_HOST$]",
\r
3409 serviceContext.getRemoteHost(), "[$USER_ID$]", user.getUserId(),
\r
3410 "[$USER_PASSWORD$]", newPassword, "[$USER_SCREENNAME$]",
\r
3411 user.getScreenName());
\r
3412 subscriptionSender.setFrom(fromAddress, fromName);
\r
3413 subscriptionSender.setHtmlFormat(true);
\r
3414 subscriptionSender.setMailId("user", user.getUserId());
\r
3415 subscriptionSender.setServiceContext(serviceContext);
\r
3416 subscriptionSender.setSubject(subject);
\r
3417 subscriptionSender.setUserId(user.getUserId());
\r
3419 subscriptionSender.addRuntimeSubscribers(toAddress, toName);
\r
3421 subscriptionSender.flushNotificationsAsync();
\r
3425 * Sets the users in the role, removing and adding users to the role as
\r
3428 * @param roleId the primary key of the role
\r
3429 * @param userIds the primary keys of the users
\r
3430 * @throws PortalException if a portal exception occurred
\r
3431 * @throws SystemException if a system exception occurred
\r
3433 public void setRoleUsers(long roleId, long[] userIds)
\r
3434 throws PortalException, SystemException {
\r
3436 rolePersistence.setUsers(roleId, userIds);
\r
3438 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
3440 indexer.reindex(userIds);
\r
3442 PermissionCacheUtil.clearCache();
\r
3446 * Sets the users in the user group, removing and adding users to the user
\r
3447 * group as necessary.
\r
3449 * @param userGroupId the primary key of the user group
\r
3450 * @param userIds the primary keys of the users
\r
3451 * @throws PortalException if a portal exception occurred
\r
3452 * @throws SystemException if a system exception occurred
\r
3454 @SuppressWarnings("deprecation")
\r
3455 public void setUserGroupUsers(long userGroupId, long[] userIds)
\r
3456 throws PortalException, SystemException {
\r
3458 if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) {
\r
3459 userGroupLocalService.copyUserGroupLayouts(userGroupId, userIds);
\r
3462 userGroupPersistence.setUsers(userGroupId, userIds);
\r
3464 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
3466 indexer.reindex(userIds);
\r
3468 PermissionCacheUtil.clearCache();
\r
3472 * Removes the users from the teams of a group.
\r
3474 * @param groupId the primary key of the group
\r
3475 * @param userIds the primary keys of the users
\r
3476 * @throws PortalException if a portal exception occurred
\r
3477 * @throws SystemException if a system exception occurred
\r
3479 public void unsetGroupTeamsUsers(long groupId, long[] userIds)
\r
3480 throws PortalException, SystemException {
\r
3482 List<Team> teams = teamPersistence.findByGroupId(groupId);
\r
3484 for (Team team : teams) {
\r
3485 unsetTeamUsers(team.getTeamId(), userIds);
\r
3488 PermissionCacheUtil.clearCache();
\r
3492 * Removes the users from the group.
\r
3494 * @param groupId the primary key of the group
\r
3495 * @param userIds the primary keys of the users
\r
3496 * @throws PortalException if a portal exception occurred
\r
3497 * @throws SystemException if a system exception occurred
\r
3499 public void unsetGroupUsers(
\r
3500 long groupId, long[] userIds, ServiceContext serviceContext)
\r
3501 throws PortalException, SystemException {
\r
3503 userGroupRoleLocalService.deleteUserGroupRoles(userIds, groupId);
\r
3505 userLocalService.unsetGroupTeamsUsers(groupId, userIds);
\r
3507 groupPersistence.removeUsers(groupId, userIds);
\r
3509 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
3511 indexer.reindex(userIds);
\r
3513 PermissionCacheUtil.clearCache();
\r
3517 * Removes the users from the organization.
\r
3519 * @param organizationId the primary key of the organization
\r
3520 * @param userIds the primary keys of the users
\r
3521 * @throws PortalException if a portal exception occurred
\r
3522 * @throws SystemException if a system exception occurred
\r
3524 public void unsetOrganizationUsers(long organizationId, long[] userIds)
\r
3525 throws PortalException, SystemException {
\r
3527 Organization organization = organizationPersistence.findByPrimaryKey(
\r
3530 Group group = organization.getGroup();
\r
3532 long groupId = group.getGroupId();
\r
3534 userGroupRoleLocalService.deleteUserGroupRoles(userIds, groupId);
\r
3536 organizationPersistence.removeUsers(organizationId, userIds);
\r
3538 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
3540 indexer.reindex(userIds);
\r
3542 PermissionCacheUtil.clearCache();
\r
3546 * Removes the users from the password policy.
\r
3548 * @param passwordPolicyId the primary key of the password policy
\r
3549 * @param userIds the primary keys of the users
\r
3550 * @throws SystemException if a system exception occurred
\r
3552 public void unsetPasswordPolicyUsers(long passwordPolicyId, long[] userIds)
\r
3553 throws SystemException {
\r
3555 passwordPolicyRelLocalService.deletePasswordPolicyRels(
\r
3556 passwordPolicyId, User.class.getName(), userIds);
\r
3560 * Removes the users from the role.
\r
3562 * @param roleId the primary key of the role
\r
3563 * @param users the users
\r
3564 * @throws PortalException if a portal exception occurred
\r
3565 * @throws SystemException if a system exception occurred
\r
3567 public void unsetRoleUsers(long roleId, List<User> users)
\r
3568 throws PortalException, SystemException {
\r
3570 Role role = rolePersistence.findByPrimaryKey(roleId);
\r
3572 if (role.getName().equals(RoleConstants.USER)) {
\r
3576 rolePersistence.removeUsers(roleId, users);
\r
3578 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
3580 indexer.reindex(users);
\r
3582 PermissionCacheUtil.clearCache();
\r
3586 * Removes the users from the role.
\r
3588 * @param roleId the primary key of the role
\r
3589 * @param userIds the primary keys of the users
\r
3590 * @throws PortalException if a portal exception occurred
\r
3591 * @throws SystemException if a system exception occurred
\r
3593 public void unsetRoleUsers(long roleId, long[] userIds)
\r
3594 throws PortalException, SystemException {
\r
3596 Role role = rolePersistence.findByPrimaryKey(roleId);
\r
3598 if (role.getName().equals(RoleConstants.USER)) {
\r
3602 rolePersistence.removeUsers(roleId, userIds);
\r
3604 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
3606 indexer.reindex(userIds);
\r
3608 PermissionCacheUtil.clearCache();
\r
3612 * Removes the users from the team.
\r
3614 * @param teamId the primary key of the team
\r
3615 * @param userIds the primary keys of the users
\r
3616 * @throws PortalException if a portal exception occurred
\r
3617 * @throws SystemException if a system exception occurred
\r
3619 public void unsetTeamUsers(long teamId, long[] userIds)
\r
3620 throws PortalException, SystemException {
\r
3622 teamPersistence.removeUsers(teamId, userIds);
\r
3624 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
3626 indexer.reindex(userIds);
\r
3628 PermissionCacheUtil.clearCache();
\r
3632 * Removes the users from the user group.
\r
3634 * @param userGroupId the primary key of the user group
\r
3635 * @param userIds the primary keys of the users
\r
3636 * @throws PortalException if a portal exception occurred
\r
3637 * @throws SystemException if a system exception occurred
\r
3639 public void unsetUserGroupUsers(long userGroupId, long[] userIds)
\r
3640 throws PortalException, SystemException {
\r
3642 userGroupPersistence.removeUsers(userGroupId, userIds);
\r
3644 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
\r
3646 indexer.reindex(userIds);
\r
3648 PermissionCacheUtil.clearCache();
\r
3652 * Updates whether the user has agreed to the terms of use.
\r
3654 * @param userId the primary key of the user
\r
3655 * @param agreedToTermsOfUse whether the user has agreet to the terms of
\r
3657 * @return the user
\r
3658 * @throws PortalException if a user with the primary key could not be found
\r
3659 * @throws SystemException if a system exception occurred
\r
3661 public User updateAgreedToTermsOfUse(
\r
3662 long userId, boolean agreedToTermsOfUse)
\r
3663 throws PortalException, SystemException {
\r
3665 User user = userPersistence.findByPrimaryKey(userId);
\r
3667 user.setAgreedToTermsOfUse(agreedToTermsOfUse);
\r
3669 userPersistence.update(user, false);
\r
3675 * Updates the user's asset with the new asset categories and tag names,
\r
3676 * removing and adding asset categories and tag names as necessary.
\r
3678 * @param userId the primary key of the user
\r
3679 * @param user ID the primary key of the user
\r
3680 * @param assetCategoryIds the primary key's of the new asset categories
\r
3681 * @param assetTagNames the new asset tag names
\r
3682 * @throws PortalException if a user with the primary key could not be found
\r
3683 * @throws SystemException if a system exception occurred
\r
3685 public void updateAsset(
\r
3686 long userId, User user, long[] assetCategoryIds,
\r
3687 String[] assetTagNames)
\r
3688 throws PortalException, SystemException {
\r
3690 User owner = userPersistence.findByPrimaryKey(userId);
\r
3692 Company company = companyPersistence.findByPrimaryKey(
\r
3693 owner.getCompanyId());
\r
3695 Group companyGroup = company.getGroup();
\r
3697 assetEntryLocalService.updateEntry(
\r
3698 userId, companyGroup.getGroupId(), User.class.getName(),
\r
3699 user.getUserId(), user.getUuid(), 0, assetCategoryIds,
\r
3700 assetTagNames, false, null, null, null, null, null,
\r
3701 user.getFullName(), null, null, null, null, 0, 0, null, false);
\r
3705 * Updates the user's creation date.
\r
3707 * @param userId the primary key of the user
\r
3708 * @param createDate the new creation date
\r
3709 * @return the user
\r
3710 * @throws PortalException if a user with the primary key could not be found
\r
3711 * @throws SystemException if a system exception occurred
\r
3713 public User updateCreateDate(long userId, Date createDate)
\r
3714 throws PortalException, SystemException {
\r
3716 User user = userPersistence.findByPrimaryKey(userId);
\r
3718 user.setCreateDate(createDate);
\r
3720 userPersistence.update(user, false);
\r
3726 * Updates the user's email address.
\r
3728 * @param userId the primary key of the user
\r
3729 * @param password the user's password
\r
3730 * @param emailAddress1 the user's new email address
\r
3731 * @param emailAddress2 the user's new email address confirmation
\r
3732 * @return the user
\r
3733 * @throws PortalException if a user with the primary key could not be found
\r
3734 * @throws SystemException if a system exception occurred
\r
3736 public User updateEmailAddress(
\r
3737 long userId, String password, String emailAddress1,
\r
3738 String emailAddress2)
\r
3739 throws PortalException, SystemException {
\r
3741 emailAddress1 = emailAddress1.trim().toLowerCase();
\r
3742 emailAddress2 = emailAddress2.trim().toLowerCase();
\r
3744 User user = userPersistence.findByPrimaryKey(userId);
\r
3746 validateEmailAddress(user, emailAddress1, emailAddress2);
\r
3749 user, password, user.getFirstName(), user.getMiddleName(),
\r
3750 user.getLastName(), emailAddress1);
\r
3752 userPersistence.update(user, false);
\r
3758 * Updates the user's email address or sends verification email.
\r
3760 * @param userId the primary key of the user
\r
3761 * @param password the user's password
\r
3762 * @param emailAddress1 the user's new email address
\r
3763 * @param emailAddress2 the user's new email address confirmation
\r
3764 * @return the user
\r
3765 * @throws PortalException if a user with the primary key could not be found
\r
3766 * @throws SystemException if a system exception occurred
\r
3768 public User updateEmailAddress(
\r
3769 long userId, String password, String emailAddress1,
\r
3770 String emailAddress2, ServiceContext serviceContext)
\r
3771 throws PortalException, SystemException {
\r
3773 emailAddress1 = emailAddress1.trim().toLowerCase();
\r
3774 emailAddress2 = emailAddress2.trim().toLowerCase();
\r
3776 User user = userPersistence.findByPrimaryKey(userId);
\r
3778 validateEmailAddress(user, emailAddress1, emailAddress2);
\r
3780 Company company = companyPersistence.findByPrimaryKey(
\r
3781 user.getCompanyId());
\r
3783 if (!company.isStrangersVerify()) {
\r
3785 user, password, user.getFirstName(), user.getMiddleName(),
\r
3786 user.getLastName(), emailAddress1);
\r
3788 userPersistence.update(user, false);
\r
3791 sendEmailAddressVerification(user, emailAddress1, serviceContext);
\r
3798 * Updates whether the user has verified email address.
\r
3800 * @param userId the primary key of the user
\r
3801 * @param emailAddressVerified whether the user has verified email address
\r
3802 * @return the user
\r
3803 * @throws PortalException if a user with the primary key could not be found
\r
3804 * @throws SystemException if a system exception occurred
\r
3806 public User updateEmailAddressVerified(
\r
3807 long userId, boolean emailAddressVerified)
\r
3808 throws PortalException, SystemException {
\r
3810 User user = userPersistence.findByPrimaryKey(userId);
\r
3812 user.setEmailAddressVerified(emailAddressVerified);
\r
3814 userPersistence.update(user, false);
\r
3820 * Updates the user's Facebook ID.
\r
3822 * @param userId the primary key of the user
\r
3823 * @param facebookId the user's new Facebook ID
\r
3824 * @return the user
\r
3825 * @throws PortalException if a user with the primary key could not be found
\r
3826 * @throws SystemException if a system exception occurred
\r
3828 public User updateFacebookId(long userId, long facebookId)
\r
3829 throws PortalException, SystemException {
\r
3831 User user = userPersistence.findByPrimaryKey(userId);
\r
3833 user.setFacebookId(facebookId);
\r
3835 userPersistence.update(user, false);
\r
3841 * Sets the groups the user is in, removing and adding groups as necessary.
\r
3843 * @param userId the primary key of the user
\r
3844 * @param newGroupIds the primary keys of the groups
\r
3845 * @throws PortalException if a portal exception occurred
\r
3846 * @throws SystemException if a system exception occurred
\r
3848 public void updateGroups(
\r
3849 long userId, long[] newGroupIds, ServiceContext serviceContext)
\r
3850 throws PortalException, SystemException {
\r
3853 userId, newGroupIds, serviceContext,
\r
3854 serviceContext.isIndexingEnabled());
\r
3858 * Updates a user account that was automatically created when a guest user
\r
3859 * participated in an action (e.g. posting a comment) and only provided his
\r
3860 * name and email address.
\r
3862 * @param creatorUserId the primary key of the creator
\r
3863 * @param companyId the primary key of the user's company
\r
3864 * @param autoPassword whether a password should be automatically generated
\r
3866 * @param password1 the user's password
\r
3867 * @param password2 the user's password confirmation
\r
3868 * @param autoScreenName whether a screen name should be automatically
\r
3869 * generated for the user
\r
3870 * @param screenName the user's screen name
\r
3871 * @param emailAddress the user's email address
\r
3872 * @param facebookId the user's facebook ID
\r
3873 * @param openId the user's OpenID
\r
3874 * @param locale the user's locale
\r
3875 * @param firstName the user's first name
\r
3876 * @param middleName the user's middle name
\r
3877 * @param lastName the user's last name
\r
3878 * @param prefixId the user's name prefix ID
\r
3879 * @param suffixId the user's name suffix ID
\r
3880 * @param male whether the user is male
\r
3881 * @param birthdayMonth the user's birthday month (0-based, meaning 0 for
\r
3883 * @param birthdayDay the user's birthday day
\r
3884 * @param birthdayYear the user's birthday year
\r
3885 * @param jobTitle the user's job title
\r
3886 * @param updateUserInformation whether to update the user's information
\r
3887 * @param sendEmail whether to send the user an email notification about
\r
3888 * their new account
\r
3889 * @param serviceContext the user's service context (optionally
\r
3890 * <code>null</code>). Can set expando bridge attributes for the
\r
3892 * @return the user
\r
3893 * @throws PortalException if the user's information was invalid
\r
3894 * @throws SystemException if a system exception occurred
\r
3896 public User updateIncompleteUser(
\r
3897 long creatorUserId, long companyId, boolean autoPassword,
\r
3898 String password1, String password2, boolean autoScreenName,
\r
3899 String screenName, String emailAddress, long facebookId,
\r
3900 String openId, Locale locale, String firstName, String middleName,
\r
3901 String lastName, int prefixId, int suffixId, boolean male,
\r
3902 int birthdayMonth, int birthdayDay, int birthdayYear,
\r
3903 String jobTitle, boolean updateUserInformation, boolean sendEmail,
\r
3904 ServiceContext serviceContext)
\r
3905 throws PortalException, SystemException {
\r
3907 User user = getUserByEmailAddress(companyId, emailAddress);
\r
3909 if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) {
\r
3910 throw new PortalException("Invalid user status");
\r
3913 User defaultUser = getDefaultUser(companyId);
\r
3915 if (updateUserInformation) {
\r
3916 autoScreenName = false;
\r
3918 if (PrefsPropsUtil.getBoolean(
\r
3920 PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE)) {
\r
3922 autoScreenName = true;
\r
3926 companyId, user.getUserId(), autoPassword, password1, password2,
\r
3927 autoScreenName, screenName, emailAddress, firstName, middleName,
\r
3930 if (!autoPassword) {
\r
3931 if (Validator.isNull(password1) ||
\r
3932 Validator.isNull(password2)) {
\r
3933 throw new UserPasswordException(
\r
3934 UserPasswordException.PASSWORD_INVALID);
\r
3938 if (autoScreenName) {
\r
3939 ScreenNameGenerator screenNameGenerator =
\r
3940 ScreenNameGeneratorFactory.getInstance();
\r
3943 screenName = screenNameGenerator.generate(
\r
3944 companyId, user.getUserId(), emailAddress);
\r
3946 catch (Exception e) {
\r
3947 throw new SystemException(e);
\r
3951 FullNameGenerator fullNameGenerator =
\r
3952 FullNameGeneratorFactory.getInstance();
\r
3954 String fullName = fullNameGenerator.getFullName(
\r
3955 firstName, middleName, lastName);
\r
3957 String greeting = LanguageUtil.format(
\r
3958 locale, "welcome-x", " " + fullName, false);
\r
3960 if (Validator.isNotNull(password1)) {
\r
3961 user.setPassword(PwdEncryptor.encrypt(password1));
\r
3962 user.setPasswordUnencrypted(password1);
\r
3965 user.setPasswordEncrypted(true);
\r
3967 PasswordPolicy passwordPolicy = defaultUser.getPasswordPolicy();
\r
3969 if (passwordPolicy.isChangeable() &&
\r
3970 passwordPolicy.isChangeRequired()) {
\r
3972 user.setPasswordReset(true);
\r
3975 user.setPasswordReset(false);
\r
3978 user.setScreenName(screenName);
\r
3979 user.setFacebookId(facebookId);
\r
3980 user.setOpenId(openId);
\r
3981 user.setLanguageId(locale.toString());
\r
3982 user.setTimeZoneId(defaultUser.getTimeZoneId());
\r
3983 user.setGreeting(greeting);
\r
3984 user.setFirstName(firstName);
\r
3985 user.setMiddleName(middleName);
\r
3986 user.setLastName(lastName);
\r
3987 user.setJobTitle(jobTitle);
\r
3988 user.setExpandoBridgeAttributes(serviceContext);
\r
3990 Date birthday = PortalUtil.getDate(
\r
3991 birthdayMonth, birthdayDay, birthdayYear,
\r
3992 ContactBirthdayException.class);
\r
3994 Contact contact = user.getContact();
\r
3996 contact.setFirstName(firstName);
\r
3997 contact.setMiddleName(middleName);
\r
3998 contact.setLastName(lastName);
\r
3999 contact.setPrefixId(prefixId);
\r
4000 contact.setSuffixId(suffixId);
\r
4001 contact.setMale(male);
\r
4002 contact.setBirthday(birthday);
\r
4003 contact.setJobTitle(jobTitle);
\r
4005 contactPersistence.update(contact, false, serviceContext);
\r
4009 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
\r
4012 indexer.reindex(user);
\r
4015 user.setStatus(WorkflowConstants.STATUS_DRAFT);
\r
4017 userPersistence.update(user, false, serviceContext);
\r
4021 long workflowUserId = creatorUserId;
\r
4023 if (workflowUserId == user.getUserId()) {
\r
4024 workflowUserId = defaultUser.getUserId();
\r
4027 ServiceContext workflowServiceContext = serviceContext;
\r
4029 if (workflowServiceContext == null) {
\r
4030 workflowServiceContext = new ServiceContext();
\r
4033 workflowServiceContext.setAttribute("autoPassword", autoPassword);
\r
4034 workflowServiceContext.setAttribute("sendEmail", sendEmail);
\r
4036 WorkflowHandlerRegistryUtil.startWorkflowInstance(
\r
4037 companyId, workflowUserId, User.class.getName(), user.getUserId(),
\r
4038 user, workflowServiceContext);
\r
4040 return getUserByEmailAddress(companyId, emailAddress);
\r
4044 * Updates the user's job title.
\r
4046 * @param userId the primary key of the user
\r
4047 * @param jobTitle the user's job title
\r
4048 * @return the user
\r
4049 * @throws PortalException if a user with the primary key could not be found
\r
4050 * or if a contact could not be found matching the user's contact ID
\r
4051 * @throws SystemException if a system exception occurred
\r
4053 public User updateJobTitle(long userId, String jobTitle)
\r
4054 throws PortalException, SystemException {
\r
4056 User user = userPersistence.findByPrimaryKey(userId);
\r
4058 user.setJobTitle(jobTitle);
\r
4060 userPersistence.update(user, false);
\r
4062 Contact contact = contactPersistence.findByPrimaryKey(
\r
4063 user.getContactId());
\r
4065 contact.setJobTitle(jobTitle);
\r
4067 contactPersistence.update(contact, false);
\r
4073 * Updates the user's last login with the current time and the IP address.
\r
4075 * @param userId the primary key of the user
\r
4076 * @param loginIP the IP address the user logged in from
\r
4077 * @return the user
\r
4078 * @throws PortalException if a user with the primary key could not be found
\r
4079 * @throws SystemException if a system exception occurred
\r
4081 public User updateLastLogin(long userId, String loginIP)
\r
4082 throws PortalException, SystemException {
\r
4084 User user = userPersistence.findByPrimaryKey(userId);
\r
4086 Date lastLoginDate = user.getLoginDate();
\r
4088 if (lastLoginDate == null) {
\r
4089 lastLoginDate = new Date();
\r
4092 user.setLoginDate(new Date());
\r
4093 user.setLoginIP(loginIP);
\r
4094 user.setLastLoginDate(lastLoginDate);
\r
4095 user.setLastLoginIP(user.getLoginIP());
\r
4096 user.setLastFailedLoginDate(null);
\r
4097 user.setFailedLoginAttempts(0);
\r
4099 userPersistence.update(user, false);
\r
4105 * Updates whether the user is locked out from logging in.
\r
4107 * @param user the user
\r
4108 * @param lockout whether the user is locked out
\r
4109 * @return the user
\r
4110 * @throws PortalException if a portal exception occurred
\r
4111 * @throws SystemException if a system exception occurred
\r
4113 public User updateLockout(User user, boolean lockout)
\r
4114 throws PortalException, SystemException {
\r
4116 PasswordPolicy passwordPolicy = user.getPasswordPolicy();
\r
4118 if ((passwordPolicy == null) || !passwordPolicy.isLockout()) {
\r
4122 Date lockoutDate = null;
\r
4125 lockoutDate = new Date();
\r
4128 user.setLockout(lockout);
\r
4129 user.setLockoutDate(lockoutDate);
\r
4132 user.setLastFailedLoginDate(lockoutDate);
\r
4133 user.setFailedLoginAttempts(0);
\r
4136 userPersistence.update(user, false);
\r
4142 * Updates whether the user is locked out from logging in.
\r
4144 * @param companyId the primary key of the user's company
\r
4145 * @param emailAddress the user's email address
\r
4146 * @param lockout whether the user is locked out
\r
4147 * @return the user
\r
4148 * @throws PortalException if a user with the email address could not be
\r
4150 * @throws SystemException if a system exception occurred
\r
4152 public User updateLockoutByEmailAddress(
\r
4153 long companyId, String emailAddress, boolean lockout)
\r
4154 throws PortalException, SystemException {
\r
4156 User user = getUserByEmailAddress(companyId, emailAddress);
\r
4158 return updateLockout(user, lockout);
\r
4162 * Updates whether the user is locked out from logging in.
\r
4164 * @param userId the primary key of the user
\r
4165 * @param lockout whether the user is locked out
\r
4166 * @return the user
\r
4167 * @throws PortalException if a user with the primary key could not be found
\r
4168 * @throws SystemException if a system exception occurred
\r
4170 public User updateLockoutById(long userId, boolean lockout)
\r
4171 throws PortalException, SystemException {
\r
4173 User user = userPersistence.findByPrimaryKey(userId);
\r
4175 return updateLockout(user, lockout);
\r
4179 * Updates whether the user is locked out from logging in.
\r
4181 * @param companyId the primary key of the user's company
\r
4182 * @param screenName the user's screen name
\r
4183 * @param lockout whether the user is locked out
\r
4184 * @return the user
\r
4185 * @throws PortalException if a user with the screen name could not be found
\r
4186 * @throws SystemException if a system exception occurred
\r
4188 public User updateLockoutByScreenName(
\r
4189 long companyId, String screenName, boolean lockout)
\r
4190 throws PortalException, SystemException {
\r
4192 User user = getUserByScreenName(companyId, screenName);
\r
4194 return updateLockout(user, lockout);
\r
4198 * Updates the user's modified date.
\r
4200 * @param userId the primary key of the user
\r
4201 * @param modifiedDate the new modified date
\r
4202 * @return the user
\r
4203 * @throws PortalException if a user with the primary key could not be found
\r
4204 * @throws SystemException if a system exception occurred
\r
4206 public User updateModifiedDate(long userId, Date modifiedDate)
\r
4207 throws PortalException, SystemException {
\r
4209 User user = userPersistence.findByPrimaryKey(userId);
\r
4211 user.setModifiedDate(modifiedDate);
\r
4213 userPersistence.update(user, false);
\r
4219 * Updates the user's OpenID.
\r
4221 * @param userId the primary key of the user
\r
4222 * @param openId the new OpenID
\r
4223 * @return the user
\r
4224 * @throws PortalException if a user with the primary key could not be found
\r
4225 * @throws SystemException if a system exception occurred
\r
4227 public User updateOpenId(long userId, String openId)
\r
4228 throws PortalException, SystemException {
\r
4230 openId = openId.trim();
\r
4232 User user = userPersistence.findByPrimaryKey(userId);
\r
4234 user.setOpenId(openId);
\r
4236 userPersistence.update(user, false);
\r
4242 * Sets the organizations that the user is in, removing and adding
\r
4243 * organizations as necessary.
\r
4245 * @param userId the primary key of the user
\r
4246 * @param newOrganizationIds the primary keys of the organizations
\r
4247 * @throws PortalException if a user with the primary key could not be found
\r
4248 * @throws SystemException if a system exception occurred
\r
4250 public void updateOrganizations(
\r
4251 long userId, long[] newOrganizationIds,
\r
4252 ServiceContext serviceContext)
\r
4253 throws PortalException, SystemException {
\r
4255 updateOrganizations(
\r
4256 userId, newOrganizationIds, serviceContext.isIndexingEnabled());
\r
4260 * Updates the user's password without tracking or validation of the change.
\r
4262 * @param userId the primary key of the user
\r
4263 * @param password1 the user's new password
\r
4264 * @param password2 the user's new password confirmation
\r
4265 * @param passwordReset whether the user should be asked to reset their
\r
4266 * password the next time they log in
\r
4267 * @return the user
\r
4268 * @throws PortalException if a user with the primary key could not be found
\r
4269 * @throws SystemException if a system exception occurred
\r
4271 public User updatePassword(
\r
4272 long userId, String password1, String password2,
\r
4273 boolean passwordReset)
\r
4274 throws PortalException, SystemException {
\r
4276 return updatePassword(
\r
4277 userId, password1, password2, passwordReset, false);
\r
4281 * Updates the user's password, optionally with tracking and validation of
\r
4284 * @param userId the primary key of the user
\r
4285 * @param password1 the user's new password
\r
4286 * @param password2 the user's new password confirmation
\r
4287 * @param passwordReset whether the user should be asked to reset their
\r
4288 * password the next time they login
\r
4289 * @param silentUpdate whether the password should be updated without being
\r
4290 * tracked, or validated. Primarily used for password imports.
\r
4291 * @return the user
\r
4292 * @throws PortalException if a user with the primary key could not be found
\r
4293 * @throws SystemException if a system exception occurred
\r
4295 public User updatePassword(
\r
4296 long userId, String password1, String password2,
\r
4297 boolean passwordReset, boolean silentUpdate)
\r
4298 throws PortalException, SystemException {
\r
4300 User user = userPersistence.findByPrimaryKey(userId);
\r
4302 if (!silentUpdate) {
\r
4303 validatePassword(user.getCompanyId(), userId, password1, password2);
\r
4306 String oldEncPwd = user.getPassword();
\r
4308 if (!user.isPasswordEncrypted()) {
\r
4309 oldEncPwd = PwdEncryptor.encrypt(user.getPassword());
\r
4312 String newEncPwd = PwdEncryptor.encrypt(password1);
\r
4314 if (user.hasCompanyMx()) {
\r
4315 mailService.updatePassword(user.getCompanyId(), userId, password1);
\r
4318 user.setPassword(newEncPwd);
\r
4319 user.setPasswordUnencrypted(password1);
\r
4320 user.setPasswordEncrypted(true);
\r
4321 user.setPasswordReset(passwordReset);
\r
4322 user.setPasswordModifiedDate(new Date());
\r
4323 user.setDigest(StringPool.BLANK);
\r
4324 user.setGraceLoginCount(0);
\r
4326 if (!silentUpdate) {
\r
4327 user.setPasswordModified(true);
\r
4331 userPersistence.update(user, false);
\r
4333 catch (ModelListenerException mle) {
\r
4334 String msg = GetterUtil.getString(mle.getCause().getMessage());
\r
4336 if (LDAPSettingsUtil.isPasswordPolicyEnabled(user.getCompanyId())) {
\r
4337 String passwordHistory = PrefsPropsUtil.getString(
\r
4338 user.getCompanyId(), PropsKeys.LDAP_ERROR_PASSWORD_HISTORY);
\r
4340 if (msg.indexOf(passwordHistory) != -1) {
\r
4341 throw new UserPasswordException(
\r
4342 UserPasswordException.PASSWORD_ALREADY_USED);
\r
4346 throw new UserPasswordException(
\r
4347 UserPasswordException.PASSWORD_INVALID);
\r
4350 if (!silentUpdate) {
\r
4351 user.setPasswordModified(false);
\r
4353 passwordTrackerLocalService.trackPassword(userId, oldEncPwd);
\r
4360 * Updates the user's password with manually input information. This method
\r
4361 * should only be used when performing maintenance.
\r
4363 * @param userId the primary key of the user
\r
4364 * @param password the user's new password
\r
4365 * @param passwordEncrypted the user's new encrypted password
\r
4366 * @param passwordReset whether the user should be asked to reset their
\r
4367 * password the next time they login
\r
4368 * @param passwordModifiedDate the new password modified date
\r
4369 * @return the user
\r
4370 * @throws PortalException if a user with the primary key could not be found
\r
4371 * @throws SystemException if a system exception occurred
\r
4373 public User updatePasswordManually(
\r
4374 long userId, String password, boolean passwordEncrypted,
\r
4375 boolean passwordReset, Date passwordModifiedDate)
\r
4376 throws PortalException, SystemException {
\r
4378 // This method should only be used to manually massage data
\r
4380 User user = userPersistence.findByPrimaryKey(userId);
\r
4382 user.setPassword(password);
\r
4383 user.setPasswordEncrypted(passwordEncrypted);
\r
4384 user.setPasswordReset(passwordReset);
\r
4385 user.setPasswordModifiedDate(passwordModifiedDate);
\r
4386 user.setDigest(StringPool.BLANK);
\r
4388 userPersistence.update(user, false);
\r
4394 * Updates whether the user should be asked to reset their password the next
\r
4395 * time they login.
\r
4397 * @param userId the primary key of the user
\r
4398 * @param passwordReset whether the user should be asked to reset their
\r
4399 * password the next time they login
\r
4400 * @return the user
\r
4401 * @throws PortalException if a user with the primary key could not be found
\r
4402 * @throws SystemException if a system exception occurred
\r
4404 public User updatePasswordReset(long userId, boolean passwordReset)
\r
4405 throws PortalException, SystemException {
\r
4407 User user = userPersistence.findByPrimaryKey(userId);
\r
4409 user.setPasswordReset(passwordReset);
\r
4411 userPersistence.update(user, false);
\r
4417 * Updates the user's portrait image.
\r
4419 * @param userId the primary key of the user
\r
4420 * @param bytes the new portrait image data
\r
4421 * @return the user
\r
4422 * @throws PortalException if a user with the primary key could not be found
\r
4423 * or if the new portrait was invalid
\r
4424 * @throws SystemException if a system exception occurred
\r
4426 public User updatePortrait(long userId, byte[] bytes)
\r
4427 throws PortalException, SystemException {
\r
4429 User user = userPersistence.findByPrimaryKey(userId);
\r
4431 long imageMaxSize = PrefsPropsUtil.getLong(
\r
4432 PropsKeys.USERS_IMAGE_MAX_SIZE);
\r
4434 if ((imageMaxSize > 0) &&
\r
4435 ((bytes == null) || (bytes.length > imageMaxSize))) {
\r
4437 throw new UserPortraitSizeException();
\r
4440 long portraitId = user.getPortraitId();
\r
4442 if (portraitId <= 0) {
\r
4443 portraitId = counterLocalService.increment();
\r
4445 user.setPortraitId(portraitId);
\r
4449 ImageBag imageBag = ImageToolUtil.read(bytes);
\r
4451 RenderedImage renderedImage = imageBag.getRenderedImage();
\r
4453 if (renderedImage == null) {
\r
4454 throw new UserPortraitTypeException();
\r
4457 renderedImage = ImageToolUtil.scale(
\r
4458 renderedImage, PropsValues.USERS_IMAGE_MAX_HEIGHT,
\r
4459 PropsValues.USERS_IMAGE_MAX_WIDTH);
\r
4461 String contentType = imageBag.getType();
\r
4463 imageLocalService.updateImage(
\r
4465 ImageToolUtil.getBytes(renderedImage, contentType));
\r
4467 catch (IOException ioe) {
\r
4468 throw new ImageSizeException(ioe);
\r
4471 userPersistence.update(user, false);
\r
4477 * Updates the user's password reset question and answer.
\r
4479 * @param userId the primary key of the user
\r
4480 * @param question the user's new password reset question
\r
4481 * @param answer the user's new password reset answer
\r
4482 * @return the user
\r
4483 * @throws PortalException if a user with the primary key could not be found
\r
4484 * or if the new question or answer were invalid
\r
4485 * @throws SystemException if a system exception occurred
\r
4487 public User updateReminderQuery(long userId, String question, String answer)
\r
4488 throws PortalException, SystemException {
\r
4490 validateReminderQuery(question, answer) ;
\r
4492 User user = userPersistence.findByPrimaryKey(userId);
\r
4494 user.setReminderQueryQuestion(question);
\r
4495 user.setReminderQueryAnswer(answer);
\r
4497 userPersistence.update(user, false);
\r
4503 * Updates the user's screen name.
\r
4505 * @param userId the primary key of the user
\r
4506 * @param screenName the user's new screen name
\r
4507 * @return the user
\r
4508 * @throws PortalException if a user with the primary key could not be found
\r
4509 * or if the new screen name was invalid
\r
4510 * @throws SystemException if a system exception occurred
\r
4512 public User updateScreenName(long userId, String screenName)
\r
4513 throws PortalException, SystemException {
\r
4517 User user = userPersistence.findByPrimaryKey(userId);
\r
4519 screenName = getScreenName(screenName);
\r
4521 validateScreenName(user.getCompanyId(), userId, screenName);
\r
4523 if (!user.getScreenName().equalsIgnoreCase(screenName)) {
\r
4524 user.setDigest(StringPool.BLANK);
\r
4527 user.setScreenName(screenName);
\r
4529 userPersistence.update(user, false);
\r
4533 Group group = groupLocalService.getUserGroup(
\r
4534 user.getCompanyId(), userId);
\r
4536 group.setFriendlyURL(StringPool.SLASH + screenName);
\r
4538 groupPersistence.update(group, false);
\r
4544 * Updates the user's workflow status.
\r
4546 * @param userId the primary key of the user
\r
4547 * @param status the user's new workflow status
\r
4548 * @return the user
\r
4549 * @throws PortalException if a user with the primary key could not be found
\r
4550 * @throws SystemException if a system exception occurred
\r
4552 public User updateStatus(long userId, int status)
\r
4553 throws PortalException, SystemException {
\r
4555 User user = userPersistence.findByPrimaryKey(userId);
\r
4557 user.setStatus(status);
\r
4559 userPersistence.update(user, false);
\r
4567 * Updates the user.
\r
4569 * @param userId the primary key of the user
\r
4570 * @param oldPassword the user's old password
\r
4571 * @param newPassword1 the user's new password (optionally
\r
4572 * <code>null</code>)
\r
4573 * @param newPassword2 the user's new password confirmation (optionally
\r
4574 * <code>null</code>)
\r
4575 * @param passwordReset whether the user should be asked to reset their
\r
4576 * password the next time they login
\r
4577 * @param reminderQueryQuestion the user's new password reset question
\r
4578 * @param reminderQueryAnswer the user's new password reset answer
\r
4579 * @param screenName the user's new screen name
\r
4580 * @param emailAddress the user's new email address
\r
4581 * @param facebookId the user's new Facebook ID
\r
4582 * @param openId the user's new OpenID
\r
4583 * @param languageId the user's new language ID
\r
4584 * @param timeZoneId the user's new time zone ID
\r
4585 * @param greeting the user's new greeting
\r
4586 * @param comments the user's new comments
\r
4587 * @param firstName the user's new first name
\r
4588 * @param middleName the user's new middle name
\r
4589 * @param lastName the user's new last name
\r
4590 * @param prefixId the user's new name prefix ID
\r
4591 * @param suffixId the user's new name suffix ID
\r
4592 * @param male whether user is male
\r
4593 * @param birthdayMonth the user's new birthday month (0-based, meaning 0
\r
4595 * @param birthdayDay the user's new birthday day
\r
4596 * @param birthdayYear the user's birthday year
\r
4597 * @param smsSn the user's new SMS screen name
\r
4598 * @param aimSn the user's new AIM screen name
\r
4599 * @param facebookSn the user's new Facebook screen name
\r
4600 * @param icqSn the user's new ICQ screen name
\r
4601 * @param jabberSn the user's new Jabber screen name
\r
4602 * @param msnSn the user's new MSN screen name
\r
4603 * @param mySpaceSn the user's new MySpace screen name
\r
4604 * @param skypeSn the user's new Skype screen name
\r
4605 * @param twitterSn the user's new Twitter screen name
\r
4606 * @param ymSn the user's new Yahoo! Messenger screen name
\r
4607 * @param jobTitle the user's new job title
\r
4608 * @param groupIds the primary keys of the user's groups
\r
4609 * @param organizationIds the primary keys of the user's organizations
\r
4610 * @param roleIds the primary keys of the user's roles
\r
4611 * @param userGroupRoles the user user's group roles
\r
4612 * @param userGroupIds the primary keys of the user's user groups
\r
4613 * @param serviceContext the user's service context (optionally
\r
4614 * <code>null</code>). Can set the universally unique identifier
\r
4615 * (with the <code>uuid</code> attribute), asset category IDs, asset
\r
4616 * tag names, and expando bridge attributes for the user.
\r
4617 * @return the user
\r
4618 * @throws PortalException if a user with the primary key could not be found
\r
4619 * or if the new information was invalid
\r
4620 * @throws SystemException if a system exception occurred
\r
4622 @SuppressWarnings("deprecation")
\r
4623 public User updateUser(
\r
4624 long userId, String oldPassword, String newPassword1,
\r
4625 String newPassword2, boolean passwordReset,
\r
4626 String reminderQueryQuestion, String reminderQueryAnswer,
\r
4627 String screenName, String emailAddress, long facebookId,
\r
4628 String openId, String languageId, String timeZoneId,
\r
4629 String greeting, String comments, String firstName,
\r
4630 String middleName, String lastName, int prefixId, int suffixId,
\r
4631 boolean male, int birthdayMonth, int birthdayDay, int birthdayYear,
\r
4632 String smsSn, String aimSn, String facebookSn, String icqSn,
\r
4633 String jabberSn, String msnSn, String mySpaceSn, String skypeSn,
\r
4634 String twitterSn, String ymSn, String jobTitle, long[] groupIds,
\r
4635 long[] organizationIds, long[] roleIds,
\r
4636 List<UserGroupRole> userGroupRoles, long[] userGroupIds,
\r
4637 ServiceContext serviceContext)
\r
4638 throws PortalException, SystemException {
\r
4642 User user = userPersistence.findByPrimaryKey(userId);
\r
4643 Company company = companyPersistence.findByPrimaryKey(
\r
4644 user.getCompanyId());
\r
4645 String password = oldPassword;
\r
4646 screenName = getScreenName(screenName);
\r
4647 emailAddress = emailAddress.trim().toLowerCase();
\r
4648 openId = openId.trim();
\r
4649 String oldFullName = user.getFullName();
\r
4650 aimSn = aimSn.trim().toLowerCase();
\r
4651 facebookSn = facebookSn.trim().toLowerCase();
\r
4652 icqSn = icqSn.trim().toLowerCase();
\r
4653 jabberSn = jabberSn.trim().toLowerCase();
\r
4654 msnSn = msnSn.trim().toLowerCase();
\r
4655 mySpaceSn = mySpaceSn.trim().toLowerCase();
\r
4656 skypeSn = skypeSn.trim().toLowerCase();
\r
4657 twitterSn = twitterSn.trim().toLowerCase();
\r
4658 ymSn = ymSn.trim().toLowerCase();
\r
4659 Date now = new Date();
\r
4661 EmailAddressGenerator emailAddressGenerator =
\r
4662 EmailAddressGeneratorFactory.getInstance();
\r
4664 if (emailAddressGenerator.isGenerated(emailAddress)) {
\r
4665 emailAddress = StringPool.BLANK;
\r
4668 if (!PropsValues.USERS_EMAIL_ADDRESS_REQUIRED &&
\r
4669 Validator.isNull(emailAddress)) {
\r
4671 emailAddress = emailAddressGenerator.generate(
\r
4672 user.getCompanyId(), userId);
\r
4676 userId, screenName, emailAddress, firstName, middleName, lastName,
\r
4679 if (Validator.isNotNull(newPassword1) ||
\r
4680 Validator.isNotNull(newPassword2)) {
\r
4682 user = updatePassword(
\r
4683 userId, newPassword1, newPassword2, passwordReset);
\r
4685 password = newPassword1;
\r
4687 user.setDigest(StringPool.BLANK);
\r
4690 user.setModifiedDate(now);
\r
4692 if (user.getContactId() <= 0) {
\r
4693 user.setContactId(counterLocalService.increment());
\r
4696 user.setPasswordReset(passwordReset);
\r
4698 if (Validator.isNotNull(reminderQueryQuestion) &&
\r
4699 Validator.isNotNull(reminderQueryAnswer)) {
\r
4701 user.setReminderQueryQuestion(reminderQueryQuestion);
\r
4702 user.setReminderQueryAnswer(reminderQueryAnswer);
\r
4705 if (!user.getScreenName().equalsIgnoreCase(screenName)) {
\r
4706 user.setScreenName(screenName);
\r
4708 user.setDigest(StringPool.BLANK);
\r
4711 boolean sendEmailAddressVerification = false;
\r
4713 if (!company.isStrangersVerify()) {
\r
4715 user, password, firstName, middleName, lastName, emailAddress);
\r
4718 sendEmailAddressVerification = true;
\r
4721 if (serviceContext != null) {
\r
4722 String uuid = serviceContext.getUuid();
\r
4724 if (Validator.isNotNull(uuid)) {
\r
4725 user.setUuid(uuid);
\r
4729 user.setFacebookId(facebookId);
\r
4730 user.setOpenId(openId);
\r
4731 user.setLanguageId(languageId);
\r
4732 user.setTimeZoneId(timeZoneId);
\r
4733 user.setGreeting(greeting);
\r
4734 user.setComments(comments);
\r
4735 user.setFirstName(firstName);
\r
4736 user.setMiddleName(middleName);
\r
4737 user.setLastName(lastName);
\r
4738 user.setJobTitle(jobTitle);
\r
4739 user.setExpandoBridgeAttributes(serviceContext);
\r
4741 userPersistence.update(user, false, serviceContext);
\r
4745 Date birthday = PortalUtil.getDate(
\r
4746 birthdayMonth, birthdayDay, birthdayYear,
\r
4747 ContactBirthdayException.class);
\r
4749 long contactId = user.getContactId();
\r
4751 Contact contact = contactPersistence.fetchByPrimaryKey(contactId);
\r
4753 if (contact == null) {
\r
4754 contact = contactPersistence.create(contactId);
\r
4756 contact.setCompanyId(user.getCompanyId());
\r
4757 contact.setUserName(StringPool.BLANK);
\r
4758 contact.setCreateDate(now);
\r
4759 contact.setAccountId(company.getAccountId());
\r
4760 contact.setParentContactId(
\r
4761 ContactConstants.DEFAULT_PARENT_CONTACT_ID);
\r
4764 contact.setModifiedDate(now);
\r
4765 contact.setFirstName(firstName);
\r
4766 contact.setMiddleName(middleName);
\r
4767 contact.setLastName(lastName);
\r
4768 contact.setPrefixId(prefixId);
\r
4769 contact.setSuffixId(suffixId);
\r
4770 contact.setMale(male);
\r
4771 contact.setBirthday(birthday);
\r
4772 contact.setSmsSn(smsSn);
\r
4773 contact.setAimSn(aimSn);
\r
4774 contact.setFacebookSn(facebookSn);
\r
4775 contact.setIcqSn(icqSn);
\r
4776 contact.setJabberSn(jabberSn);
\r
4777 contact.setMsnSn(msnSn);
\r
4778 contact.setMySpaceSn(mySpaceSn);
\r
4779 contact.setSkypeSn(skypeSn);
\r
4780 contact.setTwitterSn(twitterSn);
\r
4781 contact.setYmSn(ymSn);
\r
4782 contact.setJobTitle(jobTitle);
\r
4784 contactPersistence.update(contact, false, serviceContext);
\r
4788 Group group = groupLocalService.getUserGroup(
\r
4789 user.getCompanyId(), userId);
\r
4791 group.setFriendlyURL(StringPool.SLASH + screenName);
\r
4793 groupPersistence.update(group, false);
\r
4795 // Groups and organizations
\r
4797 updateGroups(userId, groupIds, serviceContext, false);
\r
4798 updateOrganizations(userId, organizationIds, false);
\r
4802 if (roleIds != null) {
\r
4803 roleIds = UsersAdminUtil.addRequiredRoles(user, roleIds);
\r
4805 userPersistence.setRoles(userId, roleIds);
\r
4808 // User group roles
\r
4810 updateUserGroupRoles(user, groupIds, organizationIds, userGroupRoles);
\r
4814 if (userGroupIds != null) {
\r
4815 if (PropsValues.USER_GROUPS_COPY_LAYOUTS_TO_USER_PERSONAL_SITE) {
\r
4816 userGroupLocalService.copyUserGroupLayouts(
\r
4817 userGroupIds, userId);
\r
4820 userPersistence.setUserGroups(userId, userGroupIds);
\r
4825 announcementsDeliveryLocalService.getUserDeliveries(user.getUserId());
\r
4829 if (serviceContext != null) {
\r
4831 userId, user, serviceContext.getAssetCategoryIds(),
\r
4832 serviceContext.getAssetTagNames());
\r
4837 if (GetterUtil.getBoolean(
\r
4838 PropsKeys.USERS_UPDATE_USER_NAME + MBMessage.class.getName()) &&
\r
4839 !oldFullName.equals(user.getFullName())) {
\r
4841 mbMessageLocalService.updateUserName(userId, user.getFullName());
\r
4846 if ((serviceContext == null) || serviceContext.isIndexingEnabled()) {
\r
4847 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
\r
4850 indexer.reindex(user);
\r
4853 // Email address verification
\r
4855 if ((serviceContext != null) && sendEmailAddressVerification) {
\r
4856 sendEmailAddressVerification(user, emailAddress, serviceContext);
\r
4859 // Permission cache
\r
4861 PermissionCacheUtil.clearCache();
\r
4867 * Verifies the email address of the ticket.
\r
4869 * @param ticketKey the ticket key
\r
4870 * @throws PortalException if a ticket matching the ticket key could not be
\r
4871 * found, if the ticket has expired, if the ticket is an email
\r
4872 * address ticket, or if the email address is invalid
\r
4873 * @throws SystemException if a system exception occurred
\r
4875 public void verifyEmailAddress(String ticketKey)
\r
4876 throws PortalException, SystemException {
\r
4878 Ticket ticket = ticketLocalService.getTicket(ticketKey);
\r
4880 if (ticket.isExpired() ||
\r
4881 (ticket.getType() != TicketConstants.TYPE_EMAIL_ADDRESS)) {
\r
4883 throw new NoSuchTicketException();
\r
4886 User user = userPersistence.findByPrimaryKey(ticket.getClassPK());
\r
4888 String emailAddress = ticket.getExtraInfo();
\r
4890 emailAddress = emailAddress.toLowerCase().trim();
\r
4892 if (!emailAddress.equals(user.getEmailAddress())) {
\r
4893 if (userPersistence.fetchByC_EA(
\r
4894 user.getCompanyId(), emailAddress) != null) {
\r
4896 throw new DuplicateUserEmailAddressException();
\r
4900 user, StringPool.BLANK, user.getFirstName(),
\r
4901 user.getMiddleName(), user.getLastName(), emailAddress);
\r
4904 user.setEmailAddressVerified(true);
\r
4906 userPersistence.update(user, false);
\r
4908 ticketLocalService.deleteTicket(ticket);
\r
4912 * Attempts to authenticate the user by their login and password, while
\r
4913 * using the AuthPipeline.
\r
4916 * Authentication type specifies what <code>login</code> contains.The valid
\r
4922 * <code>CompanyConstants.AUTH_TYPE_EA</code> - <code>login</code> is the
\r
4923 * user's email address
\r
4926 * <code>CompanyConstants.AUTH_TYPE_SN</code> - <code>login</code> is the
\r
4927 * user's screen name
\r
4930 * <code>CompanyConstants.AUTH_TYPE_ID</code> - <code>login</code> is the
\r
4931 * user's primary key
\r
4935 * @param companyId the primary key of the user's company
\r
4936 * @param login either the user's email address, screen name, or primary
\r
4937 * key depending on the value of <code>authType</code>
\r
4938 * @param password the user's password
\r
4939 * @param authType the type of authentication to perform
\r
4940 * @param headerMap the header map from the authentication request
\r
4941 * @param parameterMap the parameter map from the authentication request
\r
4942 * @param resultsMap the map of authentication results (may be nil). After
\r
4943 * a succesful authentication the user's primary key will be placed
\r
4944 * under the key <code>userId</code>.
\r
4945 * @return the authentication status. This can be {@link
\r
4946 * com.liferay.portal.security.auth.Authenticator#FAILURE}
\r
4947 * indicating that the user's credentials are invalid, {@link
\r
4948 * com.liferay.portal.security.auth.Authenticator#SUCCESS}
\r
4949 * indicating a successful login, or {@link
\r
4950 * com.liferay.portal.security.auth.Authenticator#DNE} indicating
\r
4951 * that a user with that login does not exist.
\r
4952 * @throws PortalException if <code>login</code> or <code>password</code>
\r
4953 * was <code>null</code>
\r
4954 * @throws SystemException if a system exception occurred
\r
4955 * @see com.liferay.portal.security.auth.AuthPipeline
\r
4957 protected int authenticate(
\r
4958 long companyId, String login, String password, String authType,
\r
4959 Map<String, String[]> headerMap, Map<String, String[]> parameterMap,
\r
4960 Map<String, Object> resultsMap)
\r
4961 throws PortalException, SystemException {
\r
4963 if (PropsValues.AUTH_LOGIN_DISABLED) {
\r
4964 return Authenticator.FAILURE;
\r
4967 login = login.trim().toLowerCase();
\r
4969 long userId = GetterUtil.getLong(login);
\r
4971 // User input validation
\r
4973 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
\r
4974 if (Validator.isNull(login)) {
\r
4975 throw new UserEmailAddressException();
\r
4978 else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
\r
4979 if (Validator.isNull(login)) {
\r
4980 throw new UserScreenNameException();
\r
4983 else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
\r
4984 if (Validator.isNull(login)) {
\r
4985 throw new UserIdException();
\r
4989 if (Validator.isNull(password)) {
\r
4990 throw new UserPasswordException(
\r
4991 UserPasswordException.PASSWORD_INVALID);
\r
4994 int authResult = Authenticator.FAILURE;
\r
4996 // Pre-authentication pipeline
\r
4998 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
\r
4999 authResult = AuthPipeline.authenticateByEmailAddress(
\r
5000 PropsKeys.AUTH_PIPELINE_PRE, companyId, login, password,
\r
5001 headerMap, parameterMap);
\r
5003 else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
\r
5004 authResult = AuthPipeline.authenticateByScreenName(
\r
5005 PropsKeys.AUTH_PIPELINE_PRE, companyId, login, password,
\r
5006 headerMap, parameterMap);
\r
5008 else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
\r
5009 authResult = AuthPipeline.authenticateByUserId(
\r
5010 PropsKeys.AUTH_PIPELINE_PRE, companyId, userId, password,
\r
5011 headerMap, parameterMap);
\r
5019 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
\r
5020 user = userPersistence.findByC_EA(companyId, login);
\r
5022 else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
\r
5023 user = userPersistence.findByC_SN(companyId, login);
\r
5025 else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
\r
5026 user = userPersistence.findByC_U(
\r
5027 companyId, GetterUtil.getLong(login));
\r
5030 catch (NoSuchUserException nsue) {
\r
5031 return Authenticator.DNE;
\r
5034 if (user.isDefaultUser()) {
\r
5035 if (_log.isInfoEnabled()) {
\r
5036 _log.info("Authentication is disabled for the default user");
\r
5039 return Authenticator.DNE;
\r
5041 else if (!user.isActive()) {
\r
5042 if (_log.isInfoEnabled()) {
\r
5044 "Authentication is disabled for inactive user " +
\r
5045 user.getUserId());
\r
5048 return Authenticator.FAILURE;
\r
5051 if (!user.isPasswordEncrypted()) {
\r
5052 user.setPassword(PwdEncryptor.encrypt(user.getPassword()));
\r
5053 user.setPasswordEncrypted(true);
\r
5055 userPersistence.update(user, false);
\r
5058 // Check password policy to see if the is account locked out or if the
\r
5059 // password is expired
\r
5061 checkLockout(user);
\r
5063 checkPasswordExpired(user);
\r
5065 // Authenticate against the User_ table
\r
5067 if ((authResult == Authenticator.SUCCESS) &&
\r
5068 PropsValues.AUTH_PIPELINE_ENABLE_LIFERAY_CHECK) {
\r
5070 boolean authenticated = PwdAuthenticator.authenticate(
\r
5071 login, password, user.getPassword());
\r
5073 if (authenticated) {
\r
5074 authResult = Authenticator.SUCCESS;
\r
5077 authResult = Authenticator.FAILURE;
\r
5081 // Post-authentication pipeline
\r
5083 if (authResult == Authenticator.SUCCESS) {
\r
5084 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
\r
5085 authResult = AuthPipeline.authenticateByEmailAddress(
\r
5086 PropsKeys.AUTH_PIPELINE_POST, companyId, login, password,
\r
5087 headerMap, parameterMap);
\r
5089 else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
\r
5090 authResult = AuthPipeline.authenticateByScreenName(
\r
5091 PropsKeys.AUTH_PIPELINE_POST, companyId, login, password,
\r
5092 headerMap, parameterMap);
\r
5094 else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
\r
5095 authResult = AuthPipeline.authenticateByUserId(
\r
5096 PropsKeys.AUTH_PIPELINE_POST, companyId, userId, password,
\r
5097 headerMap, parameterMap);
\r
5101 if (authResult == Authenticator.SUCCESS) {
\r
5102 if (resultsMap != null) {
\r
5103 resultsMap.put("userId", user.getUserId());
\r
5108 boolean updateDigest = true;
\r
5110 if (PropsValues.AUTH_PIPELINE_ENABLE_LIFERAY_CHECK) {
\r
5111 if (Validator.isNotNull(user.getDigest())) {
\r
5112 updateDigest = false;
\r
5116 if (updateDigest) {
\r
5117 String digest = user.getDigest(password);
\r
5119 user.setDigest(digest);
\r
5121 userPersistence.update(user, false);
\r
5125 // Execute code triggered by authentication failure
\r
5127 if (authResult == Authenticator.FAILURE) {
\r
5129 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
\r
5130 AuthPipeline.onFailureByEmailAddress(
\r
5131 PropsKeys.AUTH_FAILURE, companyId, login, headerMap,
\r
5134 else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
\r
5135 AuthPipeline.onFailureByScreenName(
\r
5136 PropsKeys.AUTH_FAILURE, companyId, login, headerMap,
\r
5139 else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
\r
5140 AuthPipeline.onFailureByUserId(
\r
5141 PropsKeys.AUTH_FAILURE, companyId, userId, headerMap,
\r
5146 user = userPersistence.findByPrimaryKey(user.getUserId());
\r
5148 catch (NoSuchUserException nsue) {
\r
5149 return Authenticator.DNE;
\r
5152 // Let LDAP handle max failure event
\r
5154 if (!LDAPSettingsUtil.isPasswordPolicyEnabled(
\r
5155 user.getCompanyId())) {
\r
5157 PasswordPolicy passwordPolicy = user.getPasswordPolicy();
\r
5159 int failedLoginAttempts = user.getFailedLoginAttempts();
\r
5160 int maxFailures = passwordPolicy.getMaxFailure();
\r
5162 if ((failedLoginAttempts >= maxFailures) &&
\r
5163 (maxFailures != 0)) {
\r
5165 if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
\r
5166 AuthPipeline.onMaxFailuresByEmailAddress(
\r
5167 PropsKeys.AUTH_MAX_FAILURES, companyId, login,
\r
5168 headerMap, parameterMap);
\r
5170 else if (authType.equals(
\r
5171 CompanyConstants.AUTH_TYPE_SN)) {
\r
5173 AuthPipeline.onMaxFailuresByScreenName(
\r
5174 PropsKeys.AUTH_MAX_FAILURES, companyId, login,
\r
5175 headerMap, parameterMap);
\r
5177 else if (authType.equals(
\r
5178 CompanyConstants.AUTH_TYPE_ID)) {
\r
5180 AuthPipeline.onMaxFailuresByUserId(
\r
5181 PropsKeys.AUTH_MAX_FAILURES, companyId, userId,
\r
5182 headerMap, parameterMap);
\r
5187 catch (Exception e) {
\r
5192 return authResult;
\r
5195 protected String getScreenName(String screenName) {
\r
5196 return StringUtil.lowerCase(StringUtil.trim(screenName));
\r
5199 protected long[] getUserIds(List<User> users) {
\r
5200 long[] userIds = new long[users.size()];
\r
5202 for (int i = 0; i < users.size(); i++) {
\r
5203 User user = users.get(i);
\r
5205 userIds[i] = user.getUserId();
\r
5211 protected void reindex(final User user) {
\r
5212 final Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
\r
5215 Callable<Void> callable = new Callable<Void>() {
\r
5217 public Void call() throws Exception {
\r
5218 indexer.reindex(user);
\r
5225 TransactionCommitCallbackUtil.registerCallback(callable);
\r
5228 protected Hits search(
\r
5229 long companyId, String firstName, String middleName,
\r
5230 String lastName, String fullName, String screenName,
\r
5231 String emailAddress, String street, String city, String zip,
\r
5232 String region, String country, int status,
\r
5233 LinkedHashMap<String, Object> params, boolean andSearch, int start,
\r
5234 int end, Sort sort)
\r
5235 throws SystemException {
\r
5238 SearchContext searchContext = new SearchContext();
\r
5240 searchContext.setAndSearch(andSearch);
\r
5242 Map<String, Serializable> attributes =
\r
5243 new HashMap<String, Serializable>();
\r
5245 attributes.put("city", city);
\r
5246 attributes.put("country", country);
\r
5247 attributes.put("emailAddress", emailAddress);
\r
5248 attributes.put("firstName", firstName);
\r
5249 attributes.put("fullName", fullName);
\r
5250 attributes.put("lastName", lastName);
\r
5251 attributes.put("middleName", middleName);
\r
5252 attributes.put("params", params);
\r
5253 attributes.put("region", region);
\r
5254 attributes.put("screenName", screenName);
\r
5255 attributes.put("street", street);
\r
5256 attributes.put("status", status);
\r
5257 attributes.put("zip", zip);
\r
5259 searchContext.setAttributes(attributes);
\r
5261 searchContext.setCompanyId(companyId);
\r
5262 searchContext.setEnd(end);
\r
5264 if (params != null) {
\r
5265 String keywords = (String)params.remove("keywords");
\r
5267 if (Validator.isNotNull(keywords)) {
\r
5268 searchContext.setKeywords(keywords);
\r
5272 QueryConfig queryConfig = new QueryConfig();
\r
5274 queryConfig.setHighlightEnabled(false);
\r
5275 queryConfig.setScoreEnabled(false);
\r
5277 searchContext.setQueryConfig(queryConfig);
\r
5279 searchContext.setSorts(new Sort[] {sort});
\r
5280 searchContext.setStart(start);
\r
5282 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
\r
5285 return indexer.search(searchContext);
\r
5287 catch (Exception e) {
\r
5288 throw new SystemException(e);
\r
5292 protected void sendEmail(
\r
5293 User user, String password, ServiceContext serviceContext)
\r
5294 throws SystemException {
\r
5296 if (!PrefsPropsUtil.getBoolean(
\r
5297 user.getCompanyId(),
\r
5298 PropsKeys.ADMIN_EMAIL_USER_ADDED_ENABLED)) {
\r
5303 String fromName = PrefsPropsUtil.getString(
\r
5304 user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
\r
5305 String fromAddress = PrefsPropsUtil.getString(
\r
5306 user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
\r
5308 String toName = user.getFullName();
\r
5309 String toAddress = user.getEmailAddress();
\r
5311 String subject = PrefsPropsUtil.getContent(
\r
5312 user.getCompanyId(), PropsKeys.ADMIN_EMAIL_USER_ADDED_SUBJECT);
\r
5314 String body = null;
\r
5316 if (Validator.isNotNull(password)) {
\r
5317 body = PrefsPropsUtil.getContent(
\r
5318 user.getCompanyId(), PropsKeys.ADMIN_EMAIL_USER_ADDED_BODY);
\r
5321 body = PrefsPropsUtil.getContent(
\r
5322 user.getCompanyId(),
\r
5323 PropsKeys.ADMIN_EMAIL_USER_ADDED_NO_PASSWORD_BODY);
\r
5326 SubscriptionSender subscriptionSender = new SubscriptionSender();
\r
5328 subscriptionSender.setBody(body);
\r
5329 subscriptionSender.setCompanyId(user.getCompanyId());
\r
5330 subscriptionSender.setContextAttributes(
\r
5331 "[$USER_ID$]", user.getUserId(), "[$USER_PASSWORD$]", password,
\r
5332 "[$USER_SCREENNAME$]", user.getScreenName());
\r
5333 subscriptionSender.setFrom(fromAddress, fromName);
\r
5334 subscriptionSender.setHtmlFormat(true);
\r
5335 subscriptionSender.setMailId("user", user.getUserId());
\r
5336 subscriptionSender.setServiceContext(serviceContext);
\r
5337 subscriptionSender.setSubject(subject);
\r
5338 subscriptionSender.setUserId(user.getUserId());
\r
5340 subscriptionSender.addRuntimeSubscribers(toAddress, toName);
\r
5342 subscriptionSender.flushNotificationsAsync();
\r
5345 protected void setEmailAddress(
\r
5346 User user, String password, String firstName, String middleName,
\r
5347 String lastName, String emailAddress)
\r
5348 throws PortalException, SystemException {
\r
5350 if (emailAddress.equalsIgnoreCase(user.getEmailAddress())) {
\r
5354 long userId = user.getUserId();
\r
5356 // test@test.com -> test@liferay.com
\r
5358 if (!user.hasCompanyMx() && user.hasCompanyMx(emailAddress) &&
\r
5359 Validator.isNotNull(password)) {
\r
5361 mailService.addUser(
\r
5362 user.getCompanyId(), userId, password, firstName, middleName,
\r
5363 lastName, emailAddress);
\r
5366 // test@liferay.com -> bob@liferay.com
\r
5368 else if (user.hasCompanyMx() && user.hasCompanyMx(emailAddress)) {
\r
5369 mailService.updateEmailAddress(
\r
5370 user.getCompanyId(), userId, emailAddress);
\r
5373 // test@liferay.com -> test@test.com
\r
5375 else if (user.hasCompanyMx() && !user.hasCompanyMx(emailAddress)) {
\r
5376 mailService.deleteEmailAddress(user.getCompanyId(), userId);
\r
5379 user.setEmailAddress(emailAddress);
\r
5380 user.setDigest(StringPool.BLANK);
\r
5383 protected void updateGroups(
\r
5384 long userId, long[] newGroupIds, ServiceContext serviceContext,
\r
5385 boolean indexingEnabled)
\r
5386 throws PortalException, SystemException {
\r
5388 if (newGroupIds == null) {
\r
5392 List<Group> oldGroups = userPersistence.getGroups(userId);
\r
5394 List<Long> oldGroupIds = new ArrayList<Long>(oldGroups.size());
\r
5396 for (Group oldGroup : oldGroups) {
\r
5397 long oldGroupId = oldGroup.getGroupId();
\r
5399 oldGroupIds.add(oldGroupId);
\r
5401 if (!ArrayUtil.contains(newGroupIds, oldGroupId)) {
\r
5403 oldGroupId, new long[] {userId}, serviceContext);
\r
5407 for (long newGroupId : newGroupIds) {
\r
5408 if (!oldGroupIds.contains(newGroupId)) {
\r
5409 addGroupUsers(newGroupId, new long[] {userId});
\r
5413 if (indexingEnabled) {
\r
5414 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
\r
5417 indexer.reindex(new long[] {userId});
\r
5420 PermissionCacheUtil.clearCache();
\r
5423 protected void updateOrganizations(
\r
5424 long userId, long[] newOrganizationIds, boolean indexingEnabled)
\r
5425 throws PortalException, SystemException {
\r
5427 if (newOrganizationIds == null) {
\r
5431 List<Organization> oldOrganizations = userPersistence.getOrganizations(
\r
5434 List<Long> oldOrganizationIds = new ArrayList<Long>(
\r
5435 oldOrganizations.size());
\r
5437 for (Organization oldOrganization : oldOrganizations) {
\r
5438 long oldOrganizationId = oldOrganization.getOrganizationId();
\r
5440 oldOrganizationIds.add(oldOrganizationId);
\r
5442 if (!ArrayUtil.contains(newOrganizationIds, oldOrganizationId)) {
\r
5443 unsetOrganizationUsers(oldOrganizationId, new long[] {userId});
\r
5447 for (long newOrganizationId : newOrganizationIds) {
\r
5448 if (!oldOrganizationIds.contains(newOrganizationId)) {
\r
5449 addOrganizationUsers(newOrganizationId, new long[] {userId});
\r
5453 if (indexingEnabled) {
\r
5454 Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
\r
5457 indexer.reindex(new long[] {userId});
\r
5460 PermissionCacheUtil.clearCache();
\r
5463 protected void updateUserGroupRoles(
\r
5464 User user, long[] groupIds, long[] organizationIds,
\r
5465 List<UserGroupRole> userGroupRoles)
\r
5466 throws PortalException, SystemException {
\r
5468 if (userGroupRoles == null) {
\r
5472 List<UserGroupRole> previousUserGroupRoles =
\r
5473 userGroupRolePersistence.findByUserId(user.getUserId());
\r
5475 for (UserGroupRole userGroupRole : previousUserGroupRoles) {
\r
5476 if (userGroupRoles.contains(userGroupRole)) {
\r
5477 userGroupRoles.remove(userGroupRole);
\r
5480 userGroupRoleLocalService.deleteUserGroupRole(userGroupRole);
\r
5484 long[] validGroupIds = null;
\r
5486 if (groupIds != null) {
\r
5487 validGroupIds = ArrayUtil.clone(groupIds);
\r
5490 validGroupIds = user.getGroupIds();
\r
5493 if (organizationIds == null) {
\r
5494 organizationIds = user.getOrganizationIds();
\r
5497 long[] organizationGroupIds = new long[organizationIds.length];
\r
5499 for (int i = 0; i < organizationIds.length; i++) {
\r
5500 long organizationId = organizationIds[i];
\r
5502 Organization organization =
\r
5503 organizationPersistence.findByPrimaryKey(organizationId);
\r
5505 Group organizationGroup = organization.getGroup();
\r
5507 organizationGroupIds[i] = organizationGroup.getGroupId();
\r
5510 validGroupIds = ArrayUtil.append(validGroupIds, organizationGroupIds);
\r
5512 Arrays.sort(validGroupIds);
\r
5514 for (UserGroupRole userGroupRole : userGroupRoles) {
\r
5515 if (Arrays.binarySearch(
\r
5516 validGroupIds, userGroupRole.getGroupId()) >= 0) {
\r
5518 userGroupRoleLocalService.addUserGroupRole(userGroupRole);
\r
5523 protected void validate(
\r
5524 long companyId, long userId, boolean autoPassword, String password1,
\r
5525 String password2, boolean autoScreenName, String screenName,
\r
5526 String emailAddress, String firstName, String middleName,
\r
5527 String lastName, long[] organizationIds)
\r
5528 throws PortalException, SystemException {
\r
5530 Company company = companyPersistence.findByPrimaryKey(companyId);
\r
5532 if (company.isSystem()) {
\r
5536 if ((company.getMaxUsers() > 0) &&
\r
5537 (company.getMaxUsers() <=
\r
5539 companyId, null, WorkflowConstants.STATUS_APPROVED,
\r
5542 throw new CompanyMaxUsersException();
\r
5545 if (!autoScreenName) {
\r
5546 validateScreenName(companyId, userId, screenName);
\r
5549 if (!autoPassword) {
\r
5550 PasswordPolicy passwordPolicy =
\r
5551 passwordPolicyLocalService.getDefaultPasswordPolicy(companyId);
\r
5553 PwdToolkitUtil.validate(
\r
5554 companyId, 0, password1, password2, passwordPolicy);
\r
5557 validateEmailAddress(companyId, emailAddress);
\r
5559 if (Validator.isNotNull(emailAddress)) {
\r
5560 User user = userPersistence.fetchByC_EA(companyId, emailAddress);
\r
5562 if ((user != null) && (user.getUserId() != userId)) {
\r
5563 throw new DuplicateUserEmailAddressException();
\r
5567 validateFullName(companyId, firstName, middleName, lastName);
\r
5569 if (organizationIds != null) {
\r
5570 for (long organizationId : organizationIds) {
\r
5571 Organization organization =
\r
5572 organizationPersistence.fetchByPrimaryKey(organizationId);
\r
5574 if (organization == null) {
\r
5575 throw new NoSuchOrganizationException();
\r
5581 protected void validate(
\r
5582 long userId, String screenName, String emailAddress,
\r
5583 String firstName, String middleName, String lastName, String smsSn)
\r
5584 throws PortalException, SystemException {
\r
5586 User user = userPersistence.findByPrimaryKey(userId);
\r
5588 if (!user.getScreenName().equalsIgnoreCase(screenName)) {
\r
5589 validateScreenName(user.getCompanyId(), userId, screenName);
\r
5592 validateEmailAddress(user.getCompanyId(), emailAddress);
\r
5594 if (!user.isDefaultUser()) {
\r
5595 if (Validator.isNotNull(emailAddress) &&
\r
5596 !user.getEmailAddress().equalsIgnoreCase(emailAddress)) {
\r
5598 if (userPersistence.fetchByC_EA(
\r
5599 user.getCompanyId(), emailAddress) != null) {
\r
5601 throw new DuplicateUserEmailAddressException();
\r
5606 user.getCompanyId(), firstName, middleName, lastName);
\r
5609 if (Validator.isNotNull(smsSn) && !Validator.isEmailAddress(smsSn)) {
\r
5610 throw new UserSmsException();
\r
5614 protected void validateEmailAddress(long companyId, String emailAddress)
\r
5615 throws PortalException, SystemException {
\r
5617 if (Validator.isNull(emailAddress) &&
\r
5618 !PropsValues.USERS_EMAIL_ADDRESS_REQUIRED) {
\r
5623 EmailAddressValidator emailAddressValidator =
\r
5624 EmailAddressValidatorFactory.getInstance();
\r
5626 if (!emailAddressValidator.validate(companyId, emailAddress)) {
\r
5627 throw new UserEmailAddressException();
\r
5630 String pop3User = PrefsPropsUtil.getString(
\r
5631 PropsKeys.MAIL_SESSION_MAIL_POP3_USER,
\r
5632 PropsValues.MAIL_SESSION_MAIL_POP3_USER);
\r
5634 if (emailAddress.equalsIgnoreCase(pop3User)) {
\r
5635 throw new ReservedUserEmailAddressException();
\r
5638 String[] reservedEmailAddresses = PrefsPropsUtil.getStringArray(
\r
5639 companyId, PropsKeys.ADMIN_RESERVED_EMAIL_ADDRESSES,
\r
5640 StringPool.NEW_LINE, PropsValues.ADMIN_RESERVED_EMAIL_ADDRESSES);
\r
5642 for (String reservedEmailAddress : reservedEmailAddresses) {
\r
5643 if (emailAddress.equalsIgnoreCase(reservedEmailAddress)) {
\r
5644 throw new ReservedUserEmailAddressException();
\r
5649 protected void validateEmailAddress(
\r
5650 User user, String emailAddress1, String emailAddress2)
\r
5651 throws PortalException, SystemException {
\r
5653 if (!emailAddress1.equals(emailAddress2)) {
\r
5654 throw new UserEmailAddressException();
\r
5657 validateEmailAddress(user.getCompanyId(), emailAddress1);
\r
5658 validateEmailAddress(user.getCompanyId(), emailAddress2);
\r
5660 if (!emailAddress1.equalsIgnoreCase(user.getEmailAddress())) {
\r
5661 if (userPersistence.fetchByC_EA(
\r
5662 user.getCompanyId(), emailAddress1) != null) {
\r
5664 throw new DuplicateUserEmailAddressException();
\r
5669 protected void validateFullName(
\r
5670 long companyId, String firstName, String middleName,
\r
5672 throws PortalException, SystemException {
\r
5674 if (Validator.isNull(firstName)) {
\r
5675 throw new ContactFirstNameException();
\r
5677 else if (Validator.isNull(lastName) &&
\r
5678 PrefsPropsUtil.getBoolean(
\r
5679 companyId, PropsKeys.USERS_LAST_NAME_REQUIRED,
\r
5680 PropsValues.USERS_LAST_NAME_REQUIRED)) {
\r
5682 throw new ContactLastNameException();
\r
5685 FullNameValidator fullNameValidator =
\r
5686 FullNameValidatorFactory.getInstance();
\r
5688 if (!fullNameValidator.validate(
\r
5689 companyId, firstName, middleName, lastName)) {
\r
5691 throw new ContactFullNameException();
\r
5695 protected void validatePassword(
\r
5696 long companyId, long userId, String password1, String password2)
\r
5697 throws PortalException, SystemException {
\r
5699 if (Validator.isNull(password1) || Validator.isNull(password2)) {
\r
5700 throw new UserPasswordException(
\r
5701 UserPasswordException.PASSWORD_INVALID);
\r
5704 if (!password1.equals(password2)) {
\r
5705 throw new UserPasswordException(
\r
5706 UserPasswordException.PASSWORDS_DO_NOT_MATCH);
\r
5709 PasswordPolicy passwordPolicy =
\r
5710 passwordPolicyLocalService.getPasswordPolicyByUserId(userId);
\r
5712 PwdToolkitUtil.validate(
\r
5713 companyId, userId, password1, password2, passwordPolicy);
\r
5716 protected void validateReminderQuery(String question, String answer)
\r
5717 throws PortalException {
\r
5719 if (!PropsValues.USERS_REMINDER_QUERIES_ENABLED) {
\r
5723 if (Validator.isNull(question)) {
\r
5724 throw new UserReminderQueryException("Question cannot be null");
\r
5727 if (Validator.isNull(answer)) {
\r
5728 throw new UserReminderQueryException("Answer cannot be null");
\r
5732 protected void validateScreenName(
\r
5733 long companyId, long userId, String screenName)
\r
5734 throws PortalException, SystemException {
\r
5736 if (Validator.isNull(screenName)) {
\r
5737 throw new UserScreenNameException();
\r
5740 ScreenNameValidator screenNameValidator =
\r
5741 ScreenNameValidatorFactory.getInstance();
\r
5743 if (!screenNameValidator.validate(companyId, screenName)) {
\r
5744 throw new UserScreenNameException();
\r
5747 if (Validator.isNumber(screenName)) {
\r
5748 if (!PropsValues.USERS_SCREEN_NAME_ALLOW_NUMERIC) {
\r
5749 throw new UserScreenNameException();
\r
5752 if (!screenName.equals(String.valueOf(userId))) {
\r
5753 Group group = groupPersistence.fetchByPrimaryKey(
\r
5754 GetterUtil.getLong(screenName));
\r
5756 if (group != null) {
\r
5757 throw new UserScreenNameException();
\r
5762 for (char c : screenName.toCharArray()) {
\r
5763 if (!Validator.isChar(c) && !Validator.isDigit(c) &&
\r
5764 (c != CharPool.DASH) && (c != CharPool.PERIOD) &&
\r
5765 (c != CharPool.UNDERLINE)) {
\r
5767 throw new UserScreenNameException();
\r
5771 String[] anonymousNames = BaseServiceImpl.ANONYMOUS_NAMES;
\r
5773 for (String anonymousName : anonymousNames) {
\r
5774 if (screenName.equalsIgnoreCase(anonymousName)) {
\r
5775 throw new UserScreenNameException();
\r
5779 User user = userPersistence.fetchByC_SN(companyId, screenName);
\r
5781 if ((user != null) && (user.getUserId() != userId)) {
\r
5782 throw new DuplicateUserScreenNameException();
\r
5785 String friendlyURL = StringPool.SLASH + screenName;
\r
5787 Group group = groupPersistence.fetchByC_F(companyId, friendlyURL);
\r
5789 if ((group != null) && (group.getClassPK() != userId)) {
\r
5790 throw new GroupFriendlyURLException(
\r
5791 GroupFriendlyURLException.DUPLICATE);
\r
5794 int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);
\r
5796 if (exceptionType != -1) {
\r
5797 throw new UserScreenNameException(
\r
5798 new GroupFriendlyURLException(exceptionType));
\r
5801 String[] reservedScreenNames = PrefsPropsUtil.getStringArray(
\r
5802 companyId, PropsKeys.ADMIN_RESERVED_SCREEN_NAMES,
\r
5803 StringPool.NEW_LINE, PropsValues.ADMIN_RESERVED_SCREEN_NAMES);
\r
5805 for (String reservedScreenName : reservedScreenNames) {
\r
5806 if (screenName.equalsIgnoreCase(reservedScreenName)) {
\r
5807 throw new ReservedUserScreenNameException();
\r
5812 private static Log _log = LogFactoryUtil.getLog(UserLocalServiceImpl.class);
\r
5814 private static Map<Long, User> _defaultUsers =
\r
5815 new ConcurrentHashMap<Long, User>();
\r