001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.kernel.bean.AutoEscape;
018    import com.liferay.portal.kernel.dao.orm.QueryUtil;
019    import com.liferay.portal.kernel.dao.shard.ShardUtil;
020    import com.liferay.portal.kernel.exception.PortalException;
021    import com.liferay.portal.kernel.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    import com.liferay.portal.kernel.util.Digester;
024    import com.liferay.portal.kernel.util.DigesterUtil;
025    import com.liferay.portal.kernel.util.HtmlUtil;
026    import com.liferay.portal.kernel.util.LocaleUtil;
027    import com.liferay.portal.kernel.util.PropsKeys;
028    import com.liferay.portal.kernel.util.RemotePreference;
029    import com.liferay.portal.kernel.util.SetUtil;
030    import com.liferay.portal.kernel.util.SilentPrefsPropsUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.TimeZoneUtil;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.kernel.workflow.WorkflowConstants;
037    import com.liferay.portal.model.Address;
038    import com.liferay.portal.model.Company;
039    import com.liferay.portal.model.CompanyConstants;
040    import com.liferay.portal.model.Contact;
041    import com.liferay.portal.model.EmailAddress;
042    import com.liferay.portal.model.Group;
043    import com.liferay.portal.model.Organization;
044    import com.liferay.portal.model.PasswordPolicy;
045    import com.liferay.portal.model.Phone;
046    import com.liferay.portal.model.Role;
047    import com.liferay.portal.model.Team;
048    import com.liferay.portal.model.UserConstants;
049    import com.liferay.portal.model.UserGroup;
050    import com.liferay.portal.model.Website;
051    import com.liferay.portal.security.auth.EmailAddressGenerator;
052    import com.liferay.portal.security.auth.EmailAddressGeneratorFactory;
053    import com.liferay.portal.security.auth.FullNameGenerator;
054    import com.liferay.portal.security.auth.FullNameGeneratorFactory;
055    import com.liferay.portal.service.AddressLocalServiceUtil;
056    import com.liferay.portal.service.CompanyLocalServiceUtil;
057    import com.liferay.portal.service.ContactLocalServiceUtil;
058    import com.liferay.portal.service.EmailAddressLocalServiceUtil;
059    import com.liferay.portal.service.GroupLocalServiceUtil;
060    import com.liferay.portal.service.GroupServiceUtil;
061    import com.liferay.portal.service.LayoutLocalServiceUtil;
062    import com.liferay.portal.service.OrganizationLocalServiceUtil;
063    import com.liferay.portal.service.PasswordPolicyLocalServiceUtil;
064    import com.liferay.portal.service.PhoneLocalServiceUtil;
065    import com.liferay.portal.service.RoleLocalServiceUtil;
066    import com.liferay.portal.service.TeamLocalServiceUtil;
067    import com.liferay.portal.service.UserGroupLocalServiceUtil;
068    import com.liferay.portal.service.UserLocalServiceUtil;
069    import com.liferay.portal.service.WebsiteLocalServiceUtil;
070    import com.liferay.portal.theme.ThemeDisplay;
071    import com.liferay.portal.util.Portal;
072    import com.liferay.portal.util.PortalUtil;
073    import com.liferay.portal.util.PropsUtil;
074    import com.liferay.portal.util.PropsValues;
075    
076    import java.util.Collection;
077    import java.util.Collections;
078    import java.util.Date;
079    import java.util.HashMap;
080    import java.util.List;
081    import java.util.Locale;
082    import java.util.Map;
083    import java.util.Set;
084    import java.util.TimeZone;
085    import java.util.TreeSet;
086    
087    /**
088     * Represents a portal user, providing access to the user's contact information,
089     * groups, organizations, teams, user groups, roles, locale, timezone, and more.
090     *
091     * @author Brian Wing Shun Chan
092     * @author Jorge Ferrer
093     * @author Wesley Gong
094     */
095    public class UserImpl extends UserBaseImpl {
096    
097            @Override
098            public void addRemotePreference(RemotePreference remotePreference) {
099                    _remotePreferences.put(remotePreference.getName(), remotePreference);
100            }
101    
102            @Override
103            public Contact fetchContact() {
104                    try {
105                            ShardUtil.pushCompanyService(getCompanyId());
106    
107                            return ContactLocalServiceUtil.fetchContact(getContactId());
108                    }
109                    finally {
110                            ShardUtil.popCompanyService();
111                    }
112            }
113    
114            /**
115             * Returns the user's addresses.
116             *
117             * @return the user's addresses
118             */
119            @Override
120            public List<Address> getAddresses() {
121                    return AddressLocalServiceUtil.getAddresses(
122                            getCompanyId(), Contact.class.getName(), getContactId());
123            }
124    
125            /**
126             * Returns the user's birth date.
127             *
128             * @return the user's birth date
129             * @throws PortalException if a portal exception occurred
130             */
131            @Override
132            public Date getBirthday() throws PortalException {
133                    return getContact().getBirthday();
134            }
135    
136            /**
137             * Returns the user's company's mail domain.
138             *
139             * @return the user's company's mail domain
140             * @throws PortalException if a portal exception occurred
141             */
142            @Override
143            public String getCompanyMx() throws PortalException {
144                    Company company = CompanyLocalServiceUtil.getCompanyById(
145                            getCompanyId());
146    
147                    return company.getMx();
148            }
149    
150            /**
151             * Returns the user's associated contact.
152             *
153             * @return the user's associated contact
154             * @throws PortalException if a portal exception occurred
155             * @see    Contact
156             */
157            @Override
158            public Contact getContact() throws PortalException {
159                    try {
160                            ShardUtil.pushCompanyService(getCompanyId());
161    
162                            return ContactLocalServiceUtil.getContact(getContactId());
163                    }
164                    finally {
165                            ShardUtil.popCompanyService();
166                    }
167            }
168    
169            /**
170             * Returns the user's digest.
171             *
172             * @return the user's digest
173             */
174            @Override
175            public String getDigest() {
176                    String digest = super.getDigest();
177    
178                    if (Validator.isNull(digest) && !isPasswordEncrypted()) {
179                            digest = getDigest(getPassword());
180                    }
181    
182                    return digest;
183            }
184    
185            /**
186             * Returns a digest for the user, incorporating the password.
187             *
188             * @param  password a password to incorporate with the digest
189             * @return a digest for the user, incorporating the password
190             */
191            @Override
192            public String getDigest(String password) {
193                    if (Validator.isNull(getScreenName())) {
194                            throw new IllegalStateException("Screen name is null");
195                    }
196                    else if (Validator.isNull(getEmailAddress())) {
197                            throw new IllegalStateException("Email address is null");
198                    }
199    
200                    StringBundler sb = new StringBundler(5);
201    
202                    String digest1 = DigesterUtil.digestHex(
203                            Digester.MD5, getEmailAddress(), Portal.PORTAL_REALM, password);
204    
205                    sb.append(digest1);
206                    sb.append(StringPool.COMMA);
207    
208                    String digest2 = DigesterUtil.digestHex(
209                            Digester.MD5, getScreenName(), Portal.PORTAL_REALM, password);
210    
211                    sb.append(digest2);
212                    sb.append(StringPool.COMMA);
213    
214                    String digest3 = DigesterUtil.digestHex(
215                            Digester.MD5, String.valueOf(getUserId()), Portal.PORTAL_REALM,
216                            password);
217    
218                    sb.append(digest3);
219    
220                    return sb.toString();
221            }
222    
223            /**
224             * Returns the user's primary email address, or a blank string if the
225             * address is fake.
226             *
227             * @return the user's primary email address, or a blank string if the
228             *         address is fake
229             */
230            @Override
231            public String getDisplayEmailAddress() {
232                    String emailAddress = super.getEmailAddress();
233    
234                    EmailAddressGenerator emailAddressGenerator =
235                            EmailAddressGeneratorFactory.getInstance();
236    
237                    if (emailAddressGenerator.isFake(emailAddress)) {
238                            emailAddress = StringPool.BLANK;
239                    }
240    
241                    return emailAddress;
242            }
243    
244            /**
245             * Returns the user's display URL, discounting the URL of the user's default
246             * intranet site home page.
247             *
248             * <p>
249             * The logic for the display URL to return is as follows:
250             * </p>
251             *
252             * <ol>
253             * <li>
254             * If the user is the guest user, return an empty string.
255             * </li>
256             * <li>
257             * Else, if a friendly URL is available for the user's profile, return that
258             * friendly URL.
259             * </li>
260             * <li>
261             * Otherwise, return the URL of the user's default extranet site home page.
262             * </li>
263             * </ol>
264             *
265             * @param      portalURL the portal's URL
266             * @param      mainPath the main path
267             * @return     the user's display URL
268             * @throws     PortalException if a portal exception occurred
269             * @deprecated As of 7.0.0, replaced by {@link #getDisplayURL(ThemeDisplay)}
270             */
271            @Deprecated
272            @Override
273            public String getDisplayURL(String portalURL, String mainPath)
274                    throws PortalException {
275    
276                    return getDisplayURL(portalURL, mainPath, false);
277            }
278    
279            /**
280             * Returns the user's display URL.
281             *
282             * <p>
283             * The logic for the display URL to return is as follows:
284             * </p>
285             *
286             * <ol>
287             * <li>
288             * If the user is the guest user, return an empty string.
289             * </li>
290             * <li>
291             * Else, if a friendly URL is available for the user's profile, return that
292             * friendly URL.
293             * </li>
294             * <li>
295             * Else, if <code>privateLayout</code> is <code>true</code>, return the URL
296             * of the user's default intranet site home page.
297             * </li>
298             * <li>
299             * Otherwise, return the URL of the user's default extranet site home page.
300             * </li>
301             * </ol>
302             *
303             * @param      portalURL the portal's URL
304             * @param      mainPath the main path
305             * @param      privateLayout whether to use the URL of the user's default
306             *             intranet(versus extranet)  site home page, if no friendly URL
307             *             is available for the user's profile
308             * @return     the user's display URL
309             * @throws     PortalException if a portal exception occurred
310             * @deprecated As of 7.0.0, replaced by {@link #getDisplayURL(ThemeDisplay)}
311             */
312            @Deprecated
313            @Override
314            public String getDisplayURL(
315                            String portalURL, String mainPath, boolean privateLayout)
316                    throws PortalException {
317    
318                    if (isDefaultUser()) {
319                            return StringPool.BLANK;
320                    }
321    
322                    String profileFriendlyURL = getProfileFriendlyURL();
323    
324                    if (Validator.isNotNull(profileFriendlyURL)) {
325                            return portalURL.concat(PortalUtil.getPathContext()).concat(
326                                    profileFriendlyURL);
327                    }
328    
329                    return StringPool.BLANK;
330            }
331    
332            /**
333             * Returns the user's display URL based on the theme display, discounting
334             * the URL of the user's default intranet site home page.
335             *
336             * <p>
337             * The logic for the display URL to return is as follows:
338             * </p>
339             *
340             * <ol>
341             * <li>
342             * If the user is the guest user, return an empty string.
343             * </li>
344             * <li>
345             * Else, if a friendly URL is available for the user's profile, return that
346             * friendly URL.
347             * </li>
348             * <li>
349             * Otherwise, return the URL of the user's default extranet site home page.
350             * </li>
351             * </ol>
352             *
353             * @param  themeDisplay the theme display
354             * @return the user's display URL
355             * @throws PortalException if a portal exception occurred
356             */
357            @Override
358            public String getDisplayURL(ThemeDisplay themeDisplay)
359                    throws PortalException {
360    
361                    return getDisplayURL(themeDisplay, false);
362            }
363    
364            /**
365             * Returns the user's display URL based on the theme display.
366             *
367             * <p>
368             * The logic for the display URL to return is as follows:
369             * </p>
370             *
371             * <ol>
372             * <li>
373             * If the user is the guest user, return an empty string.
374             * </li>
375             * <li>
376             * Else, if a friendly URL is available for the user's profile, return that
377             * friendly URL.
378             * </li>
379             * <li>
380             * Else, if <code>privateLayout</code> is <code>true</code>, return the URL
381             * of the user's default intranet site home page.
382             * </li>
383             * <li>
384             * Otherwise, return the URL of the user's default extranet site home page.
385             * </li>
386             * </ol>
387             *
388             * @param  themeDisplay the theme display
389             * @param  privateLayout whether to use the URL of the user's default
390             *         intranet (versus extranet) site home page, if no friendly URL is
391             *         available for the user's profile
392             * @return the user's display URL
393             * @throws PortalException if a portal exception occurred
394             */
395            @Override
396            public String getDisplayURL(
397                            ThemeDisplay themeDisplay, boolean privateLayout)
398                    throws PortalException {
399    
400                    if (isDefaultUser()) {
401                            return StringPool.BLANK;
402                    }
403    
404                    String portalURL = themeDisplay.getPortalURL();
405    
406                    String profileFriendlyURL = getProfileFriendlyURL();
407    
408                    if (Validator.isNotNull(profileFriendlyURL)) {
409                            return PortalUtil.addPreservedParameters(
410                                    themeDisplay,
411                                    portalURL.concat(
412                                            PortalUtil.getPathContext()).concat(profileFriendlyURL));
413                    }
414    
415                    Group group = getGroup();
416    
417                    return group.getDisplayURL(themeDisplay, privateLayout);
418            }
419    
420            /**
421             * Returns the user's email addresses.
422             *
423             * @return the user's email addresses
424             */
425            @Override
426            public List<EmailAddress> getEmailAddresses() {
427                    return EmailAddressLocalServiceUtil.getEmailAddresses(
428                            getCompanyId(), Contact.class.getName(), getContactId());
429            }
430    
431            /**
432             * Returns <code>true</code> if the user is female.
433             *
434             * @return <code>true</code> if the user is female; <code>false</code>
435             *         otherwise
436             * @throws PortalException if a portal exception occurred
437             */
438            @Override
439            public boolean getFemale() throws PortalException {
440                    return !getMale();
441            }
442    
443            /**
444             * Returns the user's full name.
445             *
446             * @return the user's full name
447             */
448            @AutoEscape
449            @Override
450            public String getFullName() {
451                    return getFullName(false, false);
452            }
453    
454            /**
455             * Returns the user's full name.
456             *
457             * @return the user's full name
458             */
459            @AutoEscape
460            @Override
461            public String getFullName(boolean usePrefix, boolean useSuffix) {
462                    FullNameGenerator fullNameGenerator =
463                            FullNameGeneratorFactory.getInstance();
464    
465                    long prefixId = 0;
466    
467                    if (usePrefix) {
468                            Contact contact = fetchContact();
469    
470                            if (contact != null) {
471                                    prefixId = contact.getPrefixId();
472                            }
473                    }
474    
475                    long suffixId = 0;
476    
477                    if (useSuffix) {
478                            Contact contact = fetchContact();
479    
480                            if (contact != null) {
481                                    suffixId = contact.getSuffixId();
482                            }
483                    }
484    
485                    return fullNameGenerator.getLocalizedFullName(
486                            getFirstName(), getMiddleName(), getLastName(), getLocale(),
487                            prefixId, suffixId);
488            }
489    
490            @Override
491            public Group getGroup() {
492                    return GroupLocalServiceUtil.fetchUserGroup(
493                            getCompanyId(), getUserId());
494            }
495    
496            @Override
497            public long getGroupId() {
498                    Group group = getGroup();
499    
500                    return group.getGroupId();
501            }
502    
503            @Override
504            public long[] getGroupIds() {
505                    return UserLocalServiceUtil.getGroupPrimaryKeys(getUserId());
506            }
507    
508            @Override
509            public List<Group> getGroups() {
510                    return GroupLocalServiceUtil.getUserGroups(getUserId());
511            }
512    
513            @Override
514            public Locale getLocale() {
515                    return _locale;
516            }
517    
518            @Override
519            public String getLogin() throws PortalException {
520                    String login = null;
521    
522                    Company company = CompanyLocalServiceUtil.getCompanyById(
523                            getCompanyId());
524    
525                    if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_EA)) {
526                            login = getEmailAddress();
527                    }
528                    else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_SN)) {
529                            login = getScreenName();
530                    }
531                    else if (company.getAuthType().equals(CompanyConstants.AUTH_TYPE_ID)) {
532                            login = String.valueOf(getUserId());
533                    }
534    
535                    return login;
536            }
537    
538            /**
539             * Returns <code>true</code> if the user is male.
540             *
541             * @return <code>true</code> if the user is male; <code>false</code>
542             *         otherwise
543             * @throws PortalException if a portal exception occurred
544             */
545            @Override
546            public boolean getMale() throws PortalException {
547                    return getContact().getMale();
548            }
549    
550            @Override
551            public List<Group> getMySiteGroups() throws PortalException {
552                    return getMySiteGroups(null, false, QueryUtil.ALL_POS);
553            }
554    
555            @Override
556            public List<Group> getMySiteGroups(boolean includeControlPanel, int max)
557                    throws PortalException {
558    
559                    return getMySiteGroups(null, includeControlPanel, max);
560            }
561    
562            @Override
563            public List<Group> getMySiteGroups(int max) throws PortalException {
564                    return getMySiteGroups(null, false, max);
565            }
566    
567            @Override
568            public List<Group> getMySiteGroups(
569                            String[] classNames, boolean includeControlPanel, int max)
570                    throws PortalException {
571    
572                    return GroupServiceUtil.getUserSitesGroups(
573                            getUserId(), classNames, includeControlPanel, max);
574            }
575    
576            @Override
577            public List<Group> getMySiteGroups(String[] classNames, int max)
578                    throws PortalException {
579    
580                    return getMySiteGroups(classNames, false, max);
581            }
582    
583            /**
584             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups}
585             */
586            @Deprecated
587            @Override
588            public List<Group> getMySites() throws PortalException {
589                    return getMySiteGroups();
590            }
591    
592            /**
593             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(boolean,
594             *             int)}
595             */
596            @Deprecated
597            @Override
598            public List<Group> getMySites(boolean includeControlPanel, int max)
599                    throws PortalException {
600    
601                    return getMySiteGroups(includeControlPanel, max);
602            }
603    
604            /**
605             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(int)}
606             */
607            @Deprecated
608            @Override
609            public List<Group> getMySites(int max) throws PortalException {
610                    return getMySiteGroups(max);
611            }
612    
613            /**
614             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(String[],
615             *             boolean, int)}
616             */
617            @Deprecated
618            @Override
619            public List<Group> getMySites(
620                            String[] classNames, boolean includeControlPanel, int max)
621                    throws PortalException {
622    
623                    return getMySiteGroups(classNames, includeControlPanel, max);
624            }
625    
626            /**
627             * @deprecated As of 6.2.0, replaced by {@link #getMySiteGroups(String[],
628             *             int)}
629             */
630            @Deprecated
631            @Override
632            public List<Group> getMySites(String[] classNames, int max)
633                    throws PortalException {
634    
635                    return getMySiteGroups(classNames, max);
636            }
637    
638            @Override
639            public long[] getOrganizationIds() throws PortalException {
640                    return getOrganizationIds(false);
641            }
642    
643            @Override
644            public long[] getOrganizationIds(boolean includeAdministrative)
645                    throws PortalException {
646    
647                    return OrganizationLocalServiceUtil.getUserOrganizationIds(
648                            getUserId(), includeAdministrative);
649            }
650    
651            @Override
652            public List<Organization> getOrganizations() throws PortalException {
653                    return getOrganizations(false);
654            }
655    
656            @Override
657            public List<Organization> getOrganizations(boolean includeAdministrative)
658                    throws PortalException {
659    
660                    return OrganizationLocalServiceUtil.getUserOrganizations(
661                            getUserId(), includeAdministrative);
662            }
663    
664            @Override
665            public String getOriginalEmailAddress() {
666                    return super.getOriginalEmailAddress();
667            }
668    
669            @Override
670            public boolean getPasswordModified() {
671                    return _passwordModified;
672            }
673    
674            @Override
675            public PasswordPolicy getPasswordPolicy() throws PortalException {
676                    if (_passwordPolicy == null) {
677                            _passwordPolicy =
678                                    PasswordPolicyLocalServiceUtil.getPasswordPolicyByUserId(
679                                            getUserId());
680                    }
681    
682                    return _passwordPolicy;
683            }
684    
685            @Override
686            public String getPasswordUnencrypted() {
687                    return _passwordUnencrypted;
688            }
689    
690            @Override
691            public List<Phone> getPhones() {
692                    return PhoneLocalServiceUtil.getPhones(
693                            getCompanyId(), Contact.class.getName(), getContactId());
694            }
695    
696            @Override
697            public String getPortraitURL(ThemeDisplay themeDisplay)
698                    throws PortalException {
699    
700                    return UserConstants.getPortraitURL(
701                            themeDisplay.getPathImage(), isMale(), getPortraitId(),
702                            getUserUuid());
703            }
704    
705            @Override
706            public int getPrivateLayoutsPageCount() throws PortalException {
707                    return LayoutLocalServiceUtil.getLayoutsCount(this, true);
708            }
709    
710            @Override
711            public int getPublicLayoutsPageCount() throws PortalException {
712                    return LayoutLocalServiceUtil.getLayoutsCount(this, false);
713            }
714    
715            @Override
716            public Set<String> getReminderQueryQuestions() throws PortalException {
717                    Set<String> questions = new TreeSet<>();
718    
719                    List<Organization> organizations =
720                            OrganizationLocalServiceUtil.getUserOrganizations(getUserId());
721    
722                    for (Organization organization : organizations) {
723                            Set<String> organizationQuestions =
724                                    organization.getReminderQueryQuestions(getLanguageId());
725    
726                            if (organizationQuestions.isEmpty()) {
727                                    Organization parentOrganization =
728                                            organization.getParentOrganization();
729    
730                                    while (organizationQuestions.isEmpty() &&
731                                               (parentOrganization != null)) {
732    
733                                            organizationQuestions =
734                                                    parentOrganization.getReminderQueryQuestions(
735                                                            getLanguageId());
736    
737                                            parentOrganization =
738                                                    parentOrganization.getParentOrganization();
739                                    }
740                            }
741    
742                            questions.addAll(organizationQuestions);
743                    }
744    
745                    if (questions.isEmpty()) {
746                            Set<String> defaultQuestions = SetUtil.fromArray(
747                                    PropsUtil.getArray(PropsKeys.USERS_REMINDER_QUERIES_QUESTIONS));
748    
749                            questions.addAll(defaultQuestions);
750                    }
751    
752                    return questions;
753            }
754    
755            @Override
756            public RemotePreference getRemotePreference(String name) {
757                    return _remotePreferences.get(name);
758            }
759    
760            @Override
761            public Iterable<RemotePreference> getRemotePreferences() {
762                    Collection<RemotePreference> values = _remotePreferences.values();
763    
764                    return Collections.unmodifiableCollection(values);
765            }
766    
767            @Override
768            public long[] getRoleIds() {
769                    return UserLocalServiceUtil.getRolePrimaryKeys(getUserId());
770            }
771    
772            @Override
773            public List<Role> getRoles() {
774                    return RoleLocalServiceUtil.getUserRoles(getUserId());
775            }
776    
777            @Override
778            public List<Group> getSiteGroups() throws PortalException {
779                    return getSiteGroups(false);
780            }
781    
782            @Override
783            public List<Group> getSiteGroups(boolean includeAdministrative)
784                    throws PortalException {
785    
786                    return GroupLocalServiceUtil.getUserSitesGroups(
787                            getUserId(), includeAdministrative);
788            }
789    
790            @Override
791            public long[] getTeamIds() {
792                    return UserLocalServiceUtil.getTeamPrimaryKeys(getUserId());
793            }
794    
795            @Override
796            public List<Team> getTeams() {
797                    return TeamLocalServiceUtil.getUserTeams(getUserId());
798            }
799    
800            @Override
801            public TimeZone getTimeZone() {
802                    return _timeZone;
803            }
804    
805            @Override
806            public Date getUnlockDate() throws PortalException {
807                    return getUnlockDate(getPasswordPolicy());
808            }
809    
810            @Override
811            public Date getUnlockDate(PasswordPolicy passwordPolicy) {
812                    Date lockoutDate = getLockoutDate();
813    
814                    return new Date(
815                            lockoutDate.getTime() +
816                                    (passwordPolicy.getLockoutDuration() * 1000));
817            }
818    
819            @Override
820            public long[] getUserGroupIds() {
821                    return UserLocalServiceUtil.getUserGroupPrimaryKeys(getUserId());
822            }
823    
824            @Override
825            public List<UserGroup> getUserGroups() {
826                    return UserGroupLocalServiceUtil.getUserUserGroups(getUserId());
827            }
828    
829            @Override
830            public List<Website> getWebsites() {
831                    return WebsiteLocalServiceUtil.getWebsites(
832                            getCompanyId(), Contact.class.getName(), getContactId());
833            }
834    
835            @Override
836            public boolean hasCompanyMx() throws PortalException {
837                    return hasCompanyMx(getEmailAddress());
838            }
839    
840            @Override
841            public boolean hasCompanyMx(String emailAddress) throws PortalException {
842                    if (Validator.isNull(emailAddress)) {
843                            return false;
844                    }
845    
846                    Company company = CompanyLocalServiceUtil.getCompanyById(
847                            getCompanyId());
848    
849                    return company.hasCompanyMx(emailAddress);
850            }
851    
852            @Override
853            public boolean hasMySites() throws PortalException {
854                    if (isDefaultUser()) {
855                            return false;
856                    }
857    
858                    int max = PropsValues.MY_SITES_MAX_ELEMENTS;
859    
860                    if (max == 1) {
861    
862                            // Increment so that we return more than just the Control Panel
863                            // group
864    
865                            max++;
866                    }
867    
868                    List<Group> groups = getMySiteGroups(true, max);
869    
870                    return !groups.isEmpty();
871            }
872    
873            @Override
874            public boolean hasOrganization() {
875                    return OrganizationLocalServiceUtil.hasUserOrganizations(getUserId());
876            }
877    
878            @Override
879            public boolean hasPrivateLayouts() throws PortalException {
880                    return LayoutLocalServiceUtil.hasLayouts(this, true);
881            }
882    
883            @Override
884            public boolean hasPublicLayouts() throws PortalException {
885                    return LayoutLocalServiceUtil.hasLayouts(this, false);
886            }
887    
888            @Override
889            public boolean hasReminderQuery() {
890                    if (Validator.isNotNull(getReminderQueryQuestion()) &&
891                            Validator.isNotNull(getReminderQueryAnswer())) {
892    
893                            return true;
894                    }
895                    else {
896                            return false;
897                    }
898            }
899    
900            @Override
901            public boolean isActive() {
902                    if (getStatus() == WorkflowConstants.STATUS_APPROVED) {
903                            return true;
904                    }
905                    else {
906                            return false;
907                    }
908            }
909    
910            @Override
911            public boolean isEmailAddressComplete() {
912                    if (Validator.isNull(getEmailAddress()) ||
913                            (PropsValues.USERS_EMAIL_ADDRESS_REQUIRED &&
914                             Validator.isNull(getDisplayEmailAddress()))) {
915    
916                            return false;
917                    }
918    
919                    return true;
920            }
921    
922            @Override
923            public boolean isEmailAddressVerificationComplete() {
924                    boolean emailAddressVerificationRequired = false;
925    
926                    try {
927                            Company company = CompanyLocalServiceUtil.getCompany(
928                                    getCompanyId());
929    
930                            emailAddressVerificationRequired = company.isStrangersVerify();
931                    }
932                    catch (PortalException pe) {
933                            _log.error(pe, pe);
934                    }
935    
936                    if (emailAddressVerificationRequired) {
937                            return super.isEmailAddressVerified();
938                    }
939    
940                    return true;
941            }
942    
943            @Override
944            public boolean isFemale() throws PortalException {
945                    return getFemale();
946            }
947    
948            @Override
949            public boolean isMale() throws PortalException {
950                    return getMale();
951            }
952    
953            @Override
954            public boolean isPasswordModified() {
955                    return _passwordModified;
956            }
957    
958            @Override
959            public boolean isReminderQueryComplete() {
960                    if (PropsValues.USERS_REMINDER_QUERIES_ENABLED) {
961                            if (Validator.isNull(getReminderQueryQuestion()) ||
962                                    Validator.isNull(getReminderQueryAnswer())) {
963    
964                                    return false;
965                            }
966                    }
967    
968                    return true;
969            }
970    
971            @Override
972            public boolean isSetupComplete() {
973                    if (isEmailAddressComplete() && isEmailAddressVerificationComplete() &&
974                            !isPasswordReset() && isReminderQueryComplete() &&
975                            isTermsOfUseComplete()) {
976    
977                            return true;
978                    }
979    
980                    return false;
981            }
982    
983            @Override
984            public boolean isTermsOfUseComplete() {
985                    boolean termsOfUseRequired = SilentPrefsPropsUtil.getBoolean(
986                            getCompanyId(), PropsKeys.TERMS_OF_USE_REQUIRED,
987                            PropsValues.TERMS_OF_USE_REQUIRED);
988    
989                    if (termsOfUseRequired) {
990                            return super.isAgreedToTermsOfUse();
991                    }
992    
993                    return true;
994            }
995    
996            @Override
997            public void setLanguageId(String languageId) {
998                    _locale = LocaleUtil.fromLanguageId(languageId);
999    
1000                    super.setLanguageId(LocaleUtil.toLanguageId(_locale));
1001            }
1002    
1003            @Override
1004            public void setPasswordModified(boolean passwordModified) {
1005                    _passwordModified = passwordModified;
1006            }
1007    
1008            @Override
1009            public void setPasswordUnencrypted(String passwordUnencrypted) {
1010                    _passwordUnencrypted = passwordUnencrypted;
1011            }
1012    
1013            @Override
1014            public void setTimeZoneId(String timeZoneId) {
1015                    if (Validator.isNull(timeZoneId)) {
1016                            timeZoneId = TimeZoneUtil.getDefault().getID();
1017                    }
1018    
1019                    _timeZone = TimeZoneUtil.getTimeZone(timeZoneId);
1020    
1021                    super.setTimeZoneId(timeZoneId);
1022            }
1023    
1024            protected String getProfileFriendlyURL() {
1025                    if (Validator.isNull(PropsValues.USERS_PROFILE_FRIENDLY_URL)) {
1026                            return null;
1027                    }
1028    
1029                    return StringUtil.replace(
1030                            PropsValues.USERS_PROFILE_FRIENDLY_URL,
1031                            new String[] {"${liferay:screenName}", "${liferay:userId}"},
1032                            new String[] {
1033                                    HtmlUtil.escapeURL(getScreenName()), String.valueOf(getUserId())
1034                            });
1035            }
1036    
1037            private static final Log _log = LogFactoryUtil.getLog(UserImpl.class);
1038    
1039            private Locale _locale;
1040            private boolean _passwordModified;
1041            private PasswordPolicy _passwordPolicy;
1042            private String _passwordUnencrypted;
1043            private final transient Map<String, RemotePreference> _remotePreferences =
1044                    new HashMap<>();
1045            private TimeZone _timeZone;
1046    
1047    }