Source Code Cross Referenced for UserManagerImpl.java in  » J2EE » Enhydra-Demos » org » enhydra » dm » business » 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 » J2EE » Enhydra Demos » org.enhydra.dm.business 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.dm.business;
002:
003:        import java.sql.SQLException;
004:        import java.util.Properties;
005:
006:        import org.enhydra.dm.api.AppUser;
007:        import org.enhydra.dm.api.UserManager;
008:        import org.enhydra.dm.api.exceptions.BaseException;
009:        import org.enhydra.dm.api.loggers.Log;
010:        import org.enhydra.dm.business.exceptions.DatabaseException;
011:        import org.enhydra.dm.data.AppUserDO;
012:        import org.enhydra.dm.data.AppUserQuery;
013:
014:        import com.lutris.appserver.server.sql.DBRowUpdateException;
015:        import com.lutris.appserver.server.sql.DatabaseManagerException;
016:        import com.lutris.dods.builder.generator.query.DataObjectException;
017:        import com.lutris.dods.builder.generator.query.NonUniqueQueryException;
018:        import com.lutris.dods.builder.generator.query.QueryException;
019:        import com.lutris.dods.builder.generator.query.RefAssertionException;
020:
021:        /**
022:         * Default implementation of UserManager interface. Used for FORM authentication.
023:         * 
024:         * @author Svjetlana Milidrag
025:         */
026:
027:        public class UserManagerImpl implements  UserManager {
028:
029:            private Log logger = null;
030:
031:            private final String DEFAULT_ROLE = "admin";
032:
033:            public UserManagerImpl() {
034:
035:            }
036:
037:            /**
038:             * Check if username already exists.
039:             * 
040:             * @param username
041:             * @return
042:             * @throws BaseException
043:             */
044:            private boolean usernameAlreadyExists(String username)
045:                    throws BaseException {
046:                if (null != logger) {
047:                    logger.log(Log.DEBUG, "Check for username " + username
048:                            + " existing! ");
049:                }
050:                try {
051:                    AppUserQuery query = new AppUserQuery();
052:                    query.setQueryUSERNAME(username);
053:
054:                    AppUserDO userDO = query.getNextDO();
055:                    if (null != userDO) {
056:                        return true;
057:                    }
058:
059:                } catch (DataObjectException e) {
060:                    throw new DatabaseException(e);
061:                } catch (QueryException e) {
062:                    throw new DatabaseException(e);
063:                } catch (NonUniqueQueryException e) {
064:                    throw new DatabaseException(e);
065:                }
066:                return false;
067:            }
068:
069:            /*
070:             * (non-Javadoc)
071:             * 
072:             * @see org.enhydra.dm.api.UserManager#getUserByUsername(java.lang.String)
073:             */
074:            public AppUser getUserByUsername(String username)
075:                    throws BaseException {
076:                if (null != logger) {
077:                    logger.log(Log.DEBUG, "Searching for user by username ! ",
078:                            username);
079:                }
080:                try {
081:                    AppUserQuery query = new AppUserQuery();
082:                    query.setQueryUSERNAME(username);
083:
084:                    AppUserDO userDO = query.getNextDO();
085:                    if (null != userDO) {
086:
087:                        return new AppUserImpl(userDO);
088:                    } else {
089:                        throw new DatabaseException("User " + username
090:                                + " doesn't exist in database!");
091:                    }
092:
093:                } catch (DataObjectException e) {
094:                    throw new DatabaseException(e);
095:                } catch (QueryException e) {
096:                    throw new DatabaseException(e);
097:                } catch (NonUniqueQueryException e) {
098:                    throw new DatabaseException(e);
099:                }
100:
101:            }
102:
103:            /*
104:             * (non-Javadoc)
105:             * 
106:             * @see org.enhydra.dm.api.UserManager#getUserById(java.lang.String)
107:             */
108:            public AppUser getUserById(String id) throws BaseException {
109:                if (null != logger) {
110:                    logger.log(Log.DEBUG, "Searching for user by id ! ", id);
111:                }
112:                try {
113:                    AppUserDO userDO = AppUserDO.createExisting(id);
114:
115:                    if (null != userDO) {
116:                        AppUser user = new AppUserImpl(userDO);
117:                        return user;
118:                    } else {
119:                        throw new DatabaseException(
120:                                "User doesn't exist for id: " + id + ";");
121:                    }
122:                } catch (Exception ex) {
123:                    throw new DatabaseException(ex.getMessage());
124:                }
125:            }
126:
127:            /*
128:             * (non-Javadoc)
129:             * 
130:             * @see org.enhydra.dm.api.UserManager#createUser(java.lang.String, java.lang.String,
131:             *      java.lang.String, java.lang.String)
132:             */
133:            public boolean createUser(String firstname, String lastname,
134:                    String username, String password) throws BaseException {
135:
136:                if (null != logger) {
137:                    logger.log(Log.DEBUG, "User name: " + firstname + " : "
138:                            + lastname + " with username: " + username
139:                            + " creation ! ");
140:                }
141:                if (usernameAlreadyExists(username)) {
142:                    return false;
143:                }
144:                AppUser user = new AppUserImpl();
145:                user.setFirstname(firstname);
146:                user.setLastname(lastname);
147:                user.setUsername(username);
148:                user.setPassword(password);
149:                user.setRole(DEFAULT_ROLE);
150:
151:                try {
152:                    user.createDO().save();
153:                    return true;
154:                } catch (DatabaseManagerException e) {
155:                    throw new DatabaseException(e);
156:                } catch (DataObjectException e) {
157:                    throw new DatabaseException(e);
158:                } catch (RefAssertionException e) {
159:                    throw new DatabaseException(e);
160:                } catch (DBRowUpdateException e) {
161:                    throw new DatabaseException(e);
162:                } catch (QueryException e) {
163:                    throw new DatabaseException(e);
164:                } catch (SQLException e) {
165:                    throw new DatabaseException(e);
166:                }
167:            }
168:
169:            /*
170:             * (non-Javadoc)
171:             * 
172:             * @see org.enhydra.dm.api.UserManager#configure(java.util.Properties)
173:             */
174:            public void configure(Properties properties) throws BaseException {
175:
176:            }
177:
178:            /*
179:             * (non-Javadoc)
180:             * 
181:             * @see org.enhydra.dm.api.UserManager#getLogger()
182:             */
183:            public Log getLogger() {
184:                return logger;
185:            }
186:
187:            /*
188:             * (non-Javadoc)
189:             * 
190:             * @see org.enhydra.dm.api.UserManager#setLogger(org.enhydra.dm.api.loggers.Log)
191:             */
192:            public void setLogger(Log logger) {
193:                this.logger = logger;
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.