Source Code Cross Referenced for LoginProcessor.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 java.util.*;
026:        import com.lutris.http.*;
027:        import com.lutris.appserver.server.httpPresentation.*;
028:        import com.lutris.appserver.server.user.*;
029:        import com.lutris.util.*;
030:        import golfShop.GolfShop;
031:        import golfShop.spec.user.*;
032:        import com.lutris.appserver.server.session.*;
033:        import golfShop.spec.LoginException;
034:
035:        /**
036:         * Presentation Object that processes the login request and redirects
037:         * to the appropriate page.
038:         *
039:         * @author Shawn McMurdo
040:         * @version $Revision: 1.1 $
041:         */
042:        public class LoginProcessor implements  HttpPresentation {
043:            /**
044:             * State object in session.
045:             */
046:            private LoginState loginState;
047:
048:            private static final String nousername = "You must specify a username and password to login.";
049:            private static final String badlogin = "Incorrect username or password.";
050:            private static final String unknownhost = "Login failed: Unknown host name.";
051:            private static final String noremotehost = "Login failed: No remote host header.";
052:            private static final String loginfailed = "Login failed for an unknown reason!";
053:            private static final String toomanylogins = "Login failed: You are already logged in! "
054:                    + "Logout or wait for the session to expire.";
055:            private static final String permdenied = "Login failed: Permission denied.";
056:            private static final String disabled = "Login failed: Account is disabled.";
057:            private static final String nopassword = "Login failed: You must enter a valid password to login.";
058:            private static final String badpassword = "Login failed: You must enter a valid password to login.";
059:            private static final String badusername = "Login failed: Invalid user name.";
060:
061:            /**
062:             * Entry point for presentation.
063:             */
064:            public void run(HttpPresentationComms comms) throws IOException,
065:                    PageRedirectException, Exception {
066:
067:                GolfShop application = (GolfShop) comms.application;
068:                String fail_url = comms.request
069:                        .getAppFileURIPath("login/Login.po");
070:                String success_url = comms.request
071:                        .getAppFileURIPath("main/Main.po");
072:
073:                loginState = LoginState.get(comms.session);
074:
075:                //
076:                // Get the username and password from the html form.
077:                // These are mandatory fields. Redirect if nothing was entered,
078:                // or no data was sent, or the data is bad.
079:                //
080:                String username = comms.request.getParameter("username");
081:                if (username == null) {
082:                    myRedirect(fail_url, true, nousername, null, comms);
083:                }
084:                if (username.length() == 0) {
085:                    myRedirect(fail_url, true, badusername, null, comms);
086:                }
087:                String password = comms.request.getParameter("password");
088:                if (password == null) {
089:                    myRedirect(fail_url, true, nopassword, username, comms);
090:                }
091:                if (password.length() == 0) {
092:                    myRedirect(fail_url, true, badpassword, username, comms);
093:                }
094:
095:                try {
096:                    //
097:                    // Do the actual login. The LBS will have created a session
098:                    // object and assigned a cookie already. If the login is
099:                    // sucessfull, the user manager will locate the user data 
100:                    // object that represents the user and set it into the session
101:                    // object. 
102:                    //
103:                    GolfShopUserManager userManager = application
104:                            .getUserManager();
105:
106:                    try {
107:                        userManager.login(username, password, comms.session);
108:                    } catch (NullPointerException e) {
109:                    }
110:                    // We have successfully logged in!
111:                    myRedirect(success_url, false, null, username, comms);
112:
113:                } catch (LoginException le) {
114:                    switch (le.reason) {
115:                    case GolfShopUserManager.UNKNOWN_ERROR:
116:                        myRedirect(fail_url, true, loginfailed, username, comms);
117:                        break;
118:                    case GolfShopUserManager.IO_ERROR:
119:                        myRedirect(fail_url, true, badlogin, username, comms);
120:                        break;
121:                    case GolfShopUserManager.AUTH_FAILED:
122:                        myRedirect(fail_url, true, badlogin, username, comms);
123:                        break;
124:                    case GolfShopUserManager.MULTIPLE_LOGIN:
125:                        myRedirect(fail_url, true, toomanylogins, username,
126:                                comms);
127:                        break;
128:                    case GolfShopUserManager.PERMISSION_DENIED:
129:                        myRedirect(fail_url, true, permdenied, username, comms);
130:                        break;
131:                    case GolfShopUserManager.ACCOUNT_DISABLED:
132:                        myRedirect(fail_url, true, disabled, username, comms);
133:                        break;
134:                    default:
135:                        myRedirect(fail_url, true, loginfailed, username, comms);
136:                        break;
137:                    }
138:                }
139:            }
140:
141:            /*
142:             * Redirect to a new page. If deny is true, then the denied message and
143:             * username is set in the state object.
144:             */
145:            private void myRedirect(String url, boolean deny, String msg,
146:                    String username, HttpPresentationComms comms)
147:                    throws HttpPresentationException {
148:                ClientPageRedirectException e = new ClientPageRedirectException(
149:                        url);
150:                if (deny) {
151:                    loginState.lastError = msg;
152:                    if ((username != null) && (username.length() > 0)) {
153:                        loginState.userName = username;
154:                    }
155:                }
156:                throw e;
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.