Source Code Cross Referenced for AccountProcessor.java in  » J2EE » Enhydra-Demos » golfShop » presentation » xmlc » login » 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 » golfShop.presentation.xmlc.login 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server 
003:         * The Initial Developer of the Original Code is Lutris Technologies Inc. 
004:         * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
005:         * Inc. 
006:         * All Rights Reserved. 
007:         *
008:         * The contents of this file are subject to the Enhydra Public License Version
009:         * 1.0 (the "License"); you may not use this file except in compliance with the
010:         * License. You may obtain a copy of the License at
011:         * http://www.enhydra.org/software/license/epl.html 
012:         *
013:         * Software distributed under the License is distributed on an "AS IS" basis,
014:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing rights and limitations under the
016:         * License. 
017:         *
018:         * 
019:         */
020:
021:        package golfShop.presentation.xmlc.login;
022:
023:        import java.io.*;
024:        import java.net.*;
025:        import com.lutris.util.*;
026:        import com.lutris.http.*;
027:        import golfShop.GolfShop;
028:        import com.lutris.appserver.server.httpPresentation.*;
029:        import com.lutris.appserver.server.user.*;
030:        import golfShop.spec.user.*;
031:        import golfShop.spec.LoginException;
032:
033:        /**
034:         * Presentation Object that processes the new account requests and redirects
035:         * to the appropriate page. It redirects to either the new account page
036:         * or the main page (if sucessfull).
037:         *
038:         * @author Andrew John
039:         * @version $Revision: 1.1 $
040:         */
041:        public class AccountProcessor implements  HttpPresentation {
042:            /**
043:             * State object in session.
044:             */
045:            private LoginState loginState;
046:
047:            private static final String nousername = "You must enter a username for the new account.";
048:            private static final String nopassword = "You must enter the new password twice.";
049:            private static final String badpassword = "Error entering password! Enter the new password twice.";
050:            private static final String badlogin = "Incorrect username or password.";
051:            private static final String unknownhost = "Login failed: Unknown host name.";
052:            private static final String noremotehost = "Login failed: No remote host header.";
053:            private static final String loginfailed = "Account creation failed: Unknown reason!";
054:            private static final String userexists = "Account creation failed: Username is already in use.";
055:            private static final String badusername = "That is not a valid user name.";
056:            private static final String toomanylogins = "Account creation failed: Exceeded maximum number of sessions.";
057:            private static final String permdenied = "Login failed: Permission denied.";
058:            private static final String disabled = "Login failed: Account is disabled.";
059:
060:            /**
061:             * If a string is null, make it into an empty string.
062:             */
063:            private String fixStr(String str) {
064:                if (str == null) {
065:                    str = "";
066:                }
067:                return str;
068:            }
069:
070:            /**
071:             * Entry point for presentation.
072:             */
073:            public void run(HttpPresentationComms comms) throws IOException,
074:                    PageRedirectException, Exception {
075:                loginState = LoginState.get(comms.session);
076:
077:                GolfShop application = (GolfShop) comms.application;
078:                String fail_url = comms.request
079:                        .getAppFileURIPath("login/NewAccount.po");
080:                String success_url = comms.request
081:                        .getAppFileURIPath("main/Main.po");
082:                InetAddress[] inet = new InetAddress[1];
083:
084:                // Get the username and passwords from the html form. 
085:                // These are mandatory fields. Redirect if nothing was entered,
086:                // or no data was sent, or the data is bad.
087:                String username = comms.request.getParameter("username");
088:                if (username == null) {
089:                    myRedirect(fail_url, true, nousername, null, comms);
090:                }
091:                if (username.length() == 0) {
092:                    myRedirect(fail_url, true, badusername, null, comms);
093:                }
094:                String password = comms.request.getParameter("password");
095:                String password2 = comms.request.getParameter("password2");
096:                if ((password == null) || (password2 == null)) {
097:                    myRedirect(fail_url, true, nopassword, username, comms);
098:                }
099:                if (!password.equals(password2)) {
100:                    myRedirect(fail_url, true, badpassword, username, comms);
101:                }
102:                if (password.length() == 0) {
103:                    myRedirect(fail_url, true, badpassword, username, comms);
104:                }
105:
106:                // Now get the optional fields. Most users will leave these
107:                // blank for now, and fill them out at checkout time.
108:                // getParameter() willr return null if there was no html form
109:                // data passed back, so be paranoid.
110:                String address1 = fixStr(comms.request.getParameter("address1"));
111:                if (address1 == null) {
112:                    address1 = "";
113:                }
114:                String address2 = fixStr(comms.request.getParameter("address2"));
115:                if (address2 == null) {
116:                    address2 = "";
117:                }
118:                String city = fixStr(comms.request.getParameter("city"));
119:                String state = fixStr(comms.request.getParameter("state"));
120:                String zip = fixStr(comms.request.getParameter("zip"));
121:                String creditCard = fixStr(comms.request
122:                        .getParameter("creditCard"));
123:                String email = fixStr(comms.request.getParameter("email"));
124:
125:                //
126:                // For this application, future requests are only accepted from
127:                // the same ip address they logged in from.
128:                //
129:                String remoteHost = comms.request.getRemoteHost();
130:                // Be paranoid
131:                if (remoteHost == null) {
132:                    myRedirect(fail_url, true, noremotehost, username, comms);
133:                }
134:                inet[0] = null;
135:                try {
136:                    inet[0] = InetAddress.getByName(remoteHost);
137:                } catch (UnknownHostException uh) {
138:                    // Will deal with below.
139:                }
140:                if (inet[0] == null) {
141:                    myRedirect(fail_url, true, unknownhost, username, comms);
142:                }
143:
144:                try {
145:                    //
146:                    // Actually create the account (and log in). If it works, a new
147:                    // user will be created, then the user manager will create a new 
148:                    // session and add it to the session manager.
149:                    // It returns the session key, which is used to refer to the
150:                    // session. We need to send the key back to the browser in a
151:                    // cookie, so it will be passed back to this application with
152:                    // each future request.
153:                    //
154:                    GolfShopUserManager userManager = application
155:                            .getUserManager();
156:                    userManager.createAccount(username, password, address1,
157:                            address2, city, state, zip, creditCard, email,
158:                            comms.session);
159:                    // We have successfully logged in!
160:                    myRedirect(success_url, false, null, username, comms);
161:                    /*
162:                     * Catch Null pointer exception ( we canot make a instances of classes from business layer  when we run GolfShop_pres ) so
163:                     * we cannot create a new user
164:                     * We need  to allow GolfShop_pres to be functional ,  response
165:                     * will be default HTML page with message
166:                     */
167:
168:                } catch (NullPointerException ex) {
169:
170:                    myRedirect(
171:                            fail_url,
172:                            true,
173:                            "You cannot register user while runing GolfShop_pres",
174:                            username, comms);
175:                } catch (LoginException le) {
176:                    switch (le.reason) {
177:                    case GolfShopUserManager.UNKNOWN_ERROR:
178:                        myRedirect(fail_url, true, loginfailed, username, comms);
179:                        break;
180:                    case GolfShopUserManager.IO_ERROR:
181:                        myRedirect(fail_url, true, badlogin, username, comms);
182:                        break;
183:                    case GolfShopUserManager.AUTH_FAILED:
184:                        myRedirect(fail_url, true, badlogin, username, comms);
185:                        break;
186:                    case GolfShopUserManager.MULTIPLE_LOGIN:
187:                        myRedirect(fail_url, true, toomanylogins, username,
188:                                comms);
189:                        break;
190:                    case GolfShopUserManager.PERMISSION_DENIED:
191:                        myRedirect(fail_url, true, permdenied, username, comms);
192:                        break;
193:                    case GolfShopUserManager.ACCOUNT_DISABLED:
194:                        myRedirect(fail_url, true, disabled, username, comms);
195:                        break;
196:                    case GolfShopUserManager.USERNAME_ALREADY_EXISTS:
197:                        myRedirect(fail_url, true, userexists, username, comms);
198:                        break;
199:                    default:
200:                        myRedirect(fail_url, true, loginfailed, username, comms);
201:                        break;
202:                    }
203:                }
204:            }
205:
206:            /*
207:             * Redirect to a new page. If deny is true, then the denied message and
208:             * username is set in the state object.
209:             */
210:            private void myRedirect(String url, boolean deny, String msg,
211:                    String username, HttpPresentationComms comms)
212:                    throws HttpPresentationException {
213:
214:                ClientPageRedirectException e = new ClientPageRedirectException(
215:                        url);
216:                if (deny) {
217:                    loginState.lastError = msg;
218:                    if ((username != null) && (username.length() > 0)) {
219:                        loginState.userName = username;
220:                    }
221:                }
222:                throw e;
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.