Source Code Cross Referenced for UserServiceImpl.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portal » service » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portal.service.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003:         *
004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
005:         * of this software and associated documentation files (the "Software"), to deal
006:         * in the Software without restriction, including without limitation the rights
007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008:         * copies of the Software, and to permit persons to whom the Software is
009:         * furnished to do so, subject to the following conditions:
010:         *
011:         * The above copyright notice and this permission notice shall be included in
012:         * all copies or substantial portions of the Software.
013:         *
014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020:         * SOFTWARE.
021:         */package com.liferay.portal.service.impl;
022:
023:        import com.liferay.portal.PortalException;
024:        import com.liferay.portal.RequiredUserException;
025:        import com.liferay.portal.ReservedUserEmailAddressException;
026:        import com.liferay.portal.SystemException;
027:        import com.liferay.portal.kernel.security.permission.ActionKeys;
028:        import com.liferay.portal.kernel.util.StringPool;
029:        import com.liferay.portal.model.Company;
030:        import com.liferay.portal.model.Group;
031:        import com.liferay.portal.model.User;
032:        import com.liferay.portal.model.impl.GroupImpl;
033:        import com.liferay.portal.security.auth.PrincipalException;
034:        import com.liferay.portal.service.base.UserServiceBaseImpl;
035:        import com.liferay.portal.service.permission.GroupPermissionUtil;
036:        import com.liferay.portal.service.permission.OrganizationPermissionUtil;
037:        import com.liferay.portal.service.permission.PasswordPolicyPermissionUtil;
038:        import com.liferay.portal.service.permission.RolePermissionUtil;
039:        import com.liferay.portal.service.permission.UserGroupPermissionUtil;
040:        import com.liferay.portal.service.permission.UserPermissionUtil;
041:
042:        import java.util.List;
043:        import java.util.Locale;
044:
045:        /**
046:         * <a href="UserServiceImpl.java.html"><b><i>View Source</i></b></a>
047:         *
048:         * @author Brian Wing Shun Chan
049:         * @author Brian Myunghun Kim
050:         * @author Scott Lee
051:         * @author Jorge Ferrer
052:         *
053:         */
054:        public class UserServiceImpl extends UserServiceBaseImpl {
055:
056:            public void addGroupUsers(long groupId, long[] userIds)
057:                    throws PortalException, SystemException {
058:
059:                try {
060:                    GroupPermissionUtil.check(getPermissionChecker(), groupId,
061:                            ActionKeys.ASSIGN_MEMBERS);
062:                } catch (PrincipalException pe) {
063:
064:                    // Allow any user to join open communities
065:
066:                    boolean hasPermission = false;
067:
068:                    if (userIds.length == 0) {
069:                        hasPermission = true;
070:                    } else if (userIds.length == 1) {
071:                        User user = getUser();
072:
073:                        if (user.getUserId() == userIds[0]) {
074:                            Group group = groupPersistence
075:                                    .findByPrimaryKey(groupId);
076:
077:                            if (user.getCompanyId() == group.getCompanyId()) {
078:                                int type = group.getType();
079:
080:                                if (type == GroupImpl.TYPE_COMMUNITY_OPEN) {
081:                                    hasPermission = true;
082:                                }
083:                            }
084:                        }
085:                    }
086:
087:                    if (!hasPermission) {
088:                        throw new PrincipalException();
089:                    }
090:                }
091:
092:                userLocalService.addGroupUsers(groupId, userIds);
093:            }
094:
095:            public void addOrganizationUsers(long organizationId, long[] userIds)
096:                    throws PortalException, SystemException {
097:
098:                OrganizationPermissionUtil.check(getPermissionChecker(),
099:                        organizationId, ActionKeys.ASSIGN_MEMBERS);
100:
101:                userLocalService.addOrganizationUsers(organizationId, userIds);
102:            }
103:
104:            public void addPasswordPolicyUsers(long passwordPolicyId,
105:                    long[] userIds) throws PortalException, SystemException {
106:
107:                PasswordPolicyPermissionUtil.check(getPermissionChecker(),
108:                        passwordPolicyId, ActionKeys.ASSIGN_MEMBERS);
109:
110:                userLocalService.addPasswordPolicyUsers(passwordPolicyId,
111:                        userIds);
112:            }
113:
114:            public void addRoleUsers(long roleId, long[] userIds)
115:                    throws PortalException, SystemException {
116:
117:                RolePermissionUtil.check(getPermissionChecker(), roleId,
118:                        ActionKeys.ASSIGN_MEMBERS);
119:
120:                userLocalService.addRoleUsers(roleId, userIds);
121:            }
122:
123:            public void addUserGroupUsers(long userGroupId, long[] userIds)
124:                    throws PortalException, SystemException {
125:
126:                UserGroupPermissionUtil.check(getPermissionChecker(),
127:                        userGroupId, ActionKeys.ASSIGN_MEMBERS);
128:
129:                userLocalService.addUserGroupUsers(userGroupId, userIds);
130:            }
131:
132:            public User addUser(long companyId, boolean autoPassword,
133:                    String password1, String password2, boolean autoScreenName,
134:                    String screenName, String emailAddress, Locale locale,
135:                    String firstName, String middleName, String lastName,
136:                    int prefixId, int suffixId, boolean male,
137:                    int birthdayMonth, int birthdayDay, int birthdayYear,
138:                    String jobTitle, long[] organizationIds, boolean sendEmail)
139:                    throws PortalException, SystemException {
140:
141:                Company company = companyPersistence
142:                        .findByPrimaryKey(companyId);
143:
144:                if (!company.isStrangers()) {
145:                    checkPermission(0, organizationIds, ActionKeys.ADD_USER);
146:                }
147:
148:                long creatorUserId = 0;
149:
150:                try {
151:                    creatorUserId = getUserId();
152:                } catch (PrincipalException pe) {
153:                }
154:
155:                if (creatorUserId == 0) {
156:                    if (!company.isStrangersWithMx()
157:                            && company.hasCompanyMx(emailAddress)) {
158:
159:                        throw new ReservedUserEmailAddressException();
160:                    }
161:                }
162:
163:                return userLocalService.addUser(creatorUserId, companyId,
164:                        autoPassword, password1, password2, autoScreenName,
165:                        screenName, emailAddress, locale, firstName,
166:                        middleName, lastName, prefixId, suffixId, male,
167:                        birthdayMonth, birthdayDay, birthdayYear, jobTitle,
168:                        organizationIds, sendEmail);
169:            }
170:
171:            public void deleteRoleUser(long roleId, long userId)
172:                    throws PortalException, SystemException {
173:
174:                RolePermissionUtil.check(getPermissionChecker(), roleId,
175:                        ActionKeys.ASSIGN_MEMBERS);
176:
177:                userLocalService.deleteRoleUser(roleId, userId);
178:            }
179:
180:            public void deleteUser(long userId) throws PortalException,
181:                    SystemException {
182:
183:                if (getUserId() == userId) {
184:                    throw new RequiredUserException();
185:                }
186:
187:                checkPermission(userId, ActionKeys.DELETE);
188:
189:                userLocalService.deleteUser(userId);
190:            }
191:
192:            public long getDefaultUserId(long companyId)
193:                    throws PortalException, SystemException {
194:
195:                return userLocalService.getDefaultUserId(companyId);
196:            }
197:
198:            public List getGroupUsers(long groupId) throws PortalException,
199:                    SystemException {
200:
201:                return userLocalService.getGroupUsers(groupId);
202:            }
203:
204:            public List getRoleUsers(long roleId) throws PortalException,
205:                    SystemException {
206:
207:                return userLocalService.getRoleUsers(roleId);
208:            }
209:
210:            public User getUserByEmailAddress(long companyId,
211:                    String emailAddress) throws PortalException,
212:                    SystemException {
213:
214:                User user = userLocalService.getUserByEmailAddress(companyId,
215:                        emailAddress);
216:
217:                checkPermission(user.getUserId(), ActionKeys.VIEW);
218:
219:                return user;
220:            }
221:
222:            public User getUserById(long userId) throws PortalException,
223:                    SystemException {
224:
225:                User user = userLocalService.getUserById(userId);
226:
227:                checkPermission(user.getUserId(), ActionKeys.VIEW);
228:
229:                return user;
230:            }
231:
232:            public User getUserByScreenName(long companyId, String screenName)
233:                    throws PortalException, SystemException {
234:
235:                User user = userLocalService.getUserByScreenName(companyId,
236:                        screenName);
237:
238:                checkPermission(user.getUserId(), ActionKeys.VIEW);
239:
240:                return user;
241:            }
242:
243:            public long getUserIdByEmailAddress(long companyId,
244:                    String emailAddress) throws PortalException,
245:                    SystemException {
246:
247:                User user = getUserByEmailAddress(companyId, emailAddress);
248:
249:                return user.getUserId();
250:            }
251:
252:            public long getUserIdByScreenName(long companyId, String screenName)
253:                    throws PortalException, SystemException {
254:
255:                User user = getUserByScreenName(companyId, screenName);
256:
257:                return user.getUserId();
258:            }
259:
260:            public boolean hasGroupUser(long groupId, long userId)
261:                    throws PortalException, SystemException {
262:
263:                return userLocalService.hasGroupUser(groupId, userId);
264:            }
265:
266:            public boolean hasRoleUser(long roleId, long userId)
267:                    throws PortalException, SystemException {
268:
269:                return userLocalService.hasRoleUser(roleId, userId);
270:            }
271:
272:            public void setRoleUsers(long roleId, long[] userIds)
273:                    throws PortalException, SystemException {
274:
275:                RolePermissionUtil.check(getPermissionChecker(), roleId,
276:                        ActionKeys.ASSIGN_MEMBERS);
277:
278:                userLocalService.setRoleUsers(roleId, userIds);
279:            }
280:
281:            public void setUserGroupUsers(long userGroupId, long[] userIds)
282:                    throws PortalException, SystemException {
283:
284:                UserGroupPermissionUtil.check(getPermissionChecker(),
285:                        userGroupId, ActionKeys.ASSIGN_MEMBERS);
286:
287:                userLocalService.setUserGroupUsers(userGroupId, userIds);
288:            }
289:
290:            public void unsetGroupUsers(long groupId, long[] userIds)
291:                    throws PortalException, SystemException {
292:
293:                try {
294:                    GroupPermissionUtil.check(getPermissionChecker(), groupId,
295:                            ActionKeys.ASSIGN_MEMBERS);
296:                } catch (PrincipalException pe) {
297:
298:                    // Allow any user to leave open and restricted communities
299:
300:                    boolean hasPermission = false;
301:
302:                    if (userIds.length == 0) {
303:                        hasPermission = true;
304:                    } else if (userIds.length == 1) {
305:                        User user = getUser();
306:
307:                        if (user.getUserId() == userIds[0]) {
308:                            Group group = groupPersistence
309:                                    .findByPrimaryKey(groupId);
310:
311:                            if (user.getCompanyId() == group.getCompanyId()) {
312:                                int type = group.getType();
313:
314:                                if ((type == GroupImpl.TYPE_COMMUNITY_OPEN)
315:                                        || (type == GroupImpl.TYPE_COMMUNITY_RESTRICTED)) {
316:
317:                                    hasPermission = true;
318:                                }
319:                            }
320:                        }
321:                    }
322:
323:                    if (!hasPermission) {
324:                        throw new PrincipalException();
325:                    }
326:                }
327:
328:                userLocalService.unsetGroupUsers(groupId, userIds);
329:            }
330:
331:            public void unsetOrganizationUsers(long organizationId,
332:                    long[] userIds) throws PortalException, SystemException {
333:
334:                OrganizationPermissionUtil.check(getPermissionChecker(),
335:                        organizationId, ActionKeys.ASSIGN_MEMBERS);
336:
337:                userLocalService
338:                        .unsetOrganizationUsers(organizationId, userIds);
339:            }
340:
341:            public void unsetPasswordPolicyUsers(long passwordPolicyId,
342:                    long[] userIds) throws PortalException, SystemException {
343:
344:                PasswordPolicyPermissionUtil.check(getPermissionChecker(),
345:                        passwordPolicyId, ActionKeys.ASSIGN_MEMBERS);
346:
347:                userLocalService.unsetPasswordPolicyUsers(passwordPolicyId,
348:                        userIds);
349:            }
350:
351:            public void unsetRoleUsers(long roleId, long[] userIds)
352:                    throws PortalException, SystemException {
353:
354:                RolePermissionUtil.check(getPermissionChecker(), roleId,
355:                        ActionKeys.ASSIGN_MEMBERS);
356:
357:                userLocalService.unsetRoleUsers(roleId, userIds);
358:            }
359:
360:            public void unsetUserGroupUsers(long userGroupId, long[] userIds)
361:                    throws PortalException, SystemException {
362:
363:                UserGroupPermissionUtil.check(getPermissionChecker(),
364:                        userGroupId, ActionKeys.ASSIGN_MEMBERS);
365:
366:                userLocalService.unsetUserGroupUsers(userGroupId, userIds);
367:            }
368:
369:            public User updateActive(long userId, boolean active)
370:                    throws PortalException, SystemException {
371:
372:                if ((getUserId() == userId) && !active) {
373:                    throw new RequiredUserException();
374:                }
375:
376:                checkPermission(userId, ActionKeys.DELETE);
377:
378:                return userLocalService.updateActive(userId, active);
379:            }
380:
381:            public User updateAgreedToTermsOfUse(long userId,
382:                    boolean agreedToTermsOfUse) throws PortalException,
383:                    SystemException {
384:
385:                checkPermission(userId, ActionKeys.UPDATE);
386:
387:                return userLocalService.updateAgreedToTermsOfUse(userId,
388:                        agreedToTermsOfUse);
389:            }
390:
391:            public User updateLockout(long userId, boolean lockout)
392:                    throws PortalException, SystemException {
393:
394:                checkPermission(userId, ActionKeys.DELETE);
395:
396:                return userLocalService.updateLockoutById(userId, lockout);
397:            }
398:
399:            public void updateOrganizations(long userId, long[] organizationIds)
400:                    throws PortalException, SystemException {
401:
402:                checkPermission(userId, ActionKeys.UPDATE);
403:
404:                userLocalService.updateOrganizations(userId, organizationIds);
405:            }
406:
407:            public User updatePassword(long userId, String password1,
408:                    String password2, boolean passwordReset)
409:                    throws PortalException, SystemException {
410:
411:                checkPermission(userId, ActionKeys.UPDATE);
412:
413:                return userLocalService.updatePassword(userId, password1,
414:                        password2, passwordReset);
415:            }
416:
417:            public void updatePortrait(long userId, byte[] bytes)
418:                    throws PortalException, SystemException {
419:
420:                checkPermission(userId, ActionKeys.UPDATE);
421:
422:                userLocalService.updatePortrait(userId, bytes);
423:            }
424:
425:            public User updateUser(long userId, String oldPassword,
426:                    boolean passwordReset, String screenName,
427:                    String emailAddress, String languageId, String timeZoneId,
428:                    String greeting, String comments, String firstName,
429:                    String middleName, String lastName, int prefixId,
430:                    int suffixId, boolean male, int birthdayMonth,
431:                    int birthdayDay, int birthdayYear, String smsSn,
432:                    String aimSn, String icqSn, String jabberSn, String msnSn,
433:                    String skypeSn, String ymSn, String jobTitle,
434:                    long[] organizationIds) throws PortalException,
435:                    SystemException {
436:
437:                String newPassword1 = StringPool.BLANK;
438:                String newPassword2 = StringPool.BLANK;
439:
440:                return updateUser(userId, oldPassword, newPassword1,
441:                        newPassword2, passwordReset, screenName, emailAddress,
442:                        languageId, timeZoneId, greeting, comments, firstName,
443:                        middleName, lastName, prefixId, suffixId, male,
444:                        birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn,
445:                        icqSn, jabberSn, msnSn, skypeSn, ymSn, jobTitle,
446:                        organizationIds);
447:            }
448:
449:            public User updateUser(long userId, String oldPassword,
450:                    String newPassword1, String newPassword2,
451:                    boolean passwordReset, String screenName,
452:                    String emailAddress, String languageId, String timeZoneId,
453:                    String greeting, String comments, String firstName,
454:                    String middleName, String lastName, int prefixId,
455:                    int suffixId, boolean male, int birthdayMonth,
456:                    int birthdayDay, int birthdayYear, String smsSn,
457:                    String aimSn, String icqSn, String jabberSn, String msnSn,
458:                    String skypeSn, String ymSn, String jobTitle,
459:                    long[] organizationIds) throws PortalException,
460:                    SystemException {
461:
462:                checkPermission(userId, organizationIds, ActionKeys.UPDATE);
463:
464:                long curUserId = getUserId();
465:
466:                if (curUserId == userId) {
467:                    emailAddress = emailAddress.trim().toLowerCase();
468:
469:                    User user = userPersistence.findByPrimaryKey(userId);
470:
471:                    if (!emailAddress.equalsIgnoreCase(user.getEmailAddress())) {
472:                        if (!user.hasCompanyMx()
473:                                && user.hasCompanyMx(emailAddress)) {
474:                            Company company = companyPersistence
475:                                    .findByPrimaryKey(user.getCompanyId());
476:
477:                            if (!company.isStrangersWithMx()) {
478:                                throw new ReservedUserEmailAddressException();
479:                            }
480:                        }
481:                    }
482:                }
483:
484:                return userLocalService.updateUser(userId, oldPassword,
485:                        newPassword1, newPassword2, passwordReset, screenName,
486:                        emailAddress, languageId, timeZoneId, greeting,
487:                        comments, firstName, middleName, lastName, prefixId,
488:                        suffixId, male, birthdayMonth, birthdayDay,
489:                        birthdayYear, smsSn, aimSn, icqSn, jabberSn, msnSn,
490:                        skypeSn, ymSn, jobTitle, organizationIds);
491:            }
492:
493:            protected void checkPermission(long userId, String actionId)
494:                    throws PortalException, SystemException {
495:
496:                User user = userPersistence.findByPrimaryKey(userId);
497:
498:                checkPermission(userId, user.getOrganizationIds(), actionId);
499:            }
500:
501:            protected void checkPermission(long userId, long[] organizationIds,
502:                    String actionId) throws PortalException, SystemException {
503:
504:                UserPermissionUtil.check(getPermissionChecker(), userId,
505:                        organizationIds, actionId);
506:            }
507:
508:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.