Source Code Cross Referenced for IdentityUserManagementServiceImpl.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » core » identity » services » 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 » jboss portal 2.6.4 » org.jboss.portal.core.identity.services.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.core.identity.services.impl;
023:
024:        import java.util.ArrayList;
025:        import java.util.HashSet;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import java.util.Map;
029:        import java.util.Set;
030:
031:        import org.jboss.portal.core.identity.services.IdentityConstants;
032:        import org.jboss.portal.core.identity.services.IdentityUserManagementService;
033:        import org.jboss.portal.core.identity.services.metadata.IdentityUIConfigurationService;
034:        import org.jboss.portal.identity.IdentityContext;
035:        import org.jboss.portal.identity.IdentityException;
036:        import org.jboss.portal.identity.IdentityServiceController;
037:        import org.jboss.portal.identity.MembershipModule;
038:        import org.jboss.portal.identity.Role;
039:        import org.jboss.portal.identity.RoleModule;
040:        import org.jboss.portal.identity.User;
041:        import org.jboss.portal.identity.UserModule;
042:        import org.jboss.portal.identity.UserProfileModule;
043:        import org.jboss.portal.jems.as.JNDI;
044:        import org.jboss.portal.jems.as.system.AbstractJBossService;
045:
046:        /**
047:         * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
048:         * @version $Revision$
049:         */
050:        public class IdentityUserManagementServiceImpl extends
051:                AbstractJBossService implements  IdentityUserManagementService {
052:            /** The identity user module */
053:            private UserModule userModule;
054:
055:            /** The identity role module */
056:            private RoleModule roleModule;
057:
058:            /** The identity user profile module */
059:            private UserProfileModule userProfileModule;
060:
061:            /** The identity membership module */
062:            private MembershipModule membershipModule;
063:
064:            /** The identity service controller */
065:            private IdentityServiceController identityServiceController;
066:
067:            /** The core-identity configuration service */
068:            private IdentityUIConfigurationService identityUIConfigurationService;
069:
070:            /** The JNDI binding */
071:            private JNDI.Binding jndiBinding;
072:
073:            /** The jndi name */
074:            private String jndiName = null;
075:
076:            public void startService() throws Exception {
077:                super .startService();
078:
079:                try {
080:                    // Loading required modules
081:                    userModule = (UserModule) identityServiceController
082:                            .getIdentityContext().getObject(
083:                                    IdentityContext.TYPE_USER_MODULE);
084:                    roleModule = (RoleModule) identityServiceController
085:                            .getIdentityContext().getObject(
086:                                    IdentityContext.TYPE_ROLE_MODULE);
087:                    userProfileModule = (UserProfileModule) identityServiceController
088:                            .getIdentityContext().getObject(
089:                                    IdentityContext.TYPE_USER_PROFILE_MODULE);
090:                    membershipModule = (MembershipModule) identityServiceController
091:                            .getIdentityContext().getObject(
092:                                    IdentityContext.TYPE_MEMBERSHIP_MODULE);
093:                } catch (IdentityException e) {
094:                    super .stopService();
095:                    throw new RuntimeException(e);
096:                }
097:
098:                if (this .jndiName != null) {
099:                    jndiBinding = new JNDI.Binding(jndiName, this );
100:                    jndiBinding.bind();
101:                }
102:            }
103:
104:            public void stopService() throws Exception {
105:                super .stopService();
106:
107:                if (jndiBinding != null) {
108:                    jndiBinding.unbind();
109:                    jndiBinding = null;
110:                }
111:            }
112:
113:            public String getJNDIName() {
114:                return this .jndiName;
115:            }
116:
117:            public void setJNDIName(String jndiName) {
118:                this .jndiName = jndiName;
119:            }
120:
121:            public IdentityServiceController getIdentityServiceController() {
122:                return identityServiceController;
123:            }
124:
125:            public void setIdentityServiceController(
126:                    IdentityServiceController identityServiceController) {
127:                this .identityServiceController = identityServiceController;
128:            }
129:
130:            public UserModule getUserModule() {
131:                return userModule;
132:            }
133:
134:            public void setUserModule(UserModule userModule) {
135:                this .userModule = userModule;
136:            }
137:
138:            public RoleModule getRoleModule() {
139:                return roleModule;
140:            }
141:
142:            public void setRoleModule(RoleModule roleModule) {
143:                this .roleModule = roleModule;
144:            }
145:
146:            public UserProfileModule getUserProfileModule() {
147:                return userProfileModule;
148:            }
149:
150:            public void setUserProfileModule(UserProfileModule userProfileModule) {
151:                this .userProfileModule = userProfileModule;
152:            }
153:
154:            public MembershipModule getMembershipModule() {
155:                return membershipModule;
156:            }
157:
158:            public void setMembershipModule(MembershipModule membershipModule) {
159:                this .membershipModule = membershipModule;
160:            }
161:
162:            public IdentityUIConfigurationService getIdentityUIConfigurationService() {
163:                return identityUIConfigurationService;
164:            }
165:
166:            public void setIdentityUIConfigurationService(
167:                    IdentityUIConfigurationService identityUIConfigurationService) {
168:                this .identityUIConfigurationService = identityUIConfigurationService;
169:            }
170:
171:            public boolean createUser(String username, String password,
172:                    Map profileMap, List roles) {
173:                try {
174:                    User user = this .getUserModule().createUser(username,
175:                            password);
176:                    Set roleSet = this .checkRoles(roles);
177:
178:                    // Enable the user
179:                    profileMap.put(User.INFO_USER_ENABLED, Boolean.TRUE);
180:
181:                    Iterator i = profileMap.keySet().iterator();
182:                    while (i.hasNext()) {
183:                        String key = (String) i.next();
184:                        Object value = profileMap.get(key);
185:                        this .getUserProfileModule().setProperty(user, key,
186:                                value);
187:                    }
188:
189:                    this .getMembershipModule().assignRoles(user, roleSet);
190:                    return true;
191:                } catch (Exception e) {
192:                    log.error("Error when creating user", e);
193:                }
194:
195:                return false;
196:            }
197:
198:            public String getCurrentEmail(String username) {
199:                try {
200:                    User user = this .getUserModule().findUserByUserName(
201:                            username);
202:                    return (String) this .getUserProfileModule().getProperty(
203:                            user, User.INFO_USER_EMAIL_REAL);
204:                } catch (Exception e) {
205:                    log.error("failed to retrieve current email address", e);
206:                }
207:                return null;
208:            }
209:
210:            public boolean updateEmail(String username, String email) {
211:                try {
212:                    User user = this .getUserModule().findUserByUserName(
213:                            username);
214:                    this .getUserProfileModule().setProperty(user,
215:                            User.INFO_USER_EMAIL_REAL, email);
216:                    return true;
217:                } catch (Exception e) {
218:                    log.error("failed to update email", e);
219:                }
220:                return false;
221:            }
222:
223:            private Set checkRoles(List roles) throws IllegalArgumentException,
224:                    IdentityException {
225:                Set roleSet = new HashSet();
226:                // Set default roles if required
227:                if (roles == null || (roles != null && roles.size() == 0)) {
228:                    roles = this .identityUIConfigurationService
229:                            .getConfiguration().getDefaultRoles();
230:                }
231:                // If roles are still not available 
232:                if (roles == null || (roles != null && roles.size() == 0)) {
233:                    roles = new ArrayList();
234:                    roles.add(IdentityConstants.DEFAULT_ROLE);
235:                    log
236:                            .error("no default roles spezified - please check your configuration");
237:                }
238:
239:                if (roles != null && roles.size() > 0) { // Checking existing roles
240:                    Iterator i = roles.iterator();
241:
242:                    while (i.hasNext()) {
243:                        String roleName = (String) i.next();
244:                        Role role = this .getRoleModule().findRoleByName(
245:                                roleName);
246:
247:                        if (role == null) {
248:                            // Create new role ?
249:                        } else {
250:                            roleSet.add(role);
251:                        }
252:                    }
253:                }
254:                return roleSet;
255:            }
256:
257:        }
ww_w._ja_v__a_2__s_.__com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.