Source Code Cross Referenced for ChatAuthenticator.java in  » Net » QuickServer » chatserver » 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 » Net » QuickServer » chatserver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the QuickServer library 
003:         * Copyright (C) 2003-2005 QuickServer.org
004:         *
005:         * Use, modification, copying and distribution of this software is subject to
006:         * the terms and conditions of the GNU Lesser General Public License. 
007:         * You should have received a copy of the GNU LGP License along with this 
008:         * library; if not, you can download a copy from <http://www.quickserver.org/>.
009:         *
010:         * For questions, suggestions, bug-reports, enhancement-requests etc.
011:         * visit http://www.quickserver.org
012:         *
013:         */
014:
015:        package chatserver;
016:
017:        import org.quickserver.net.server.*;
018:        import java.io.*;
019:        import java.util.*;
020:        import org.quickserver.net.*;
021:
022:        /**
023:         *
024:         * @author  Akshathkumar Shetty
025:         */
026:        public class ChatAuthenticator extends QuickAuthenticationHandler {
027:            public AuthStatus askAuthentication(ClientHandler handler)
028:                    throws IOException, AppException {
029:                ChatData data = (ChatData) handler.getClientData();
030:                data.setLastAsked("U");
031:                handler.sendClientMsg("{system.data} Username");
032:                return null;
033:            }
034:
035:            public AuthStatus handleAuthentication(ClientHandler handler,
036:                    String command) throws IOException, AppException {
037:                ChatData data = (ChatData) handler.getClientData();
038:
039:                if (data.getLastAsked().equals("U")) {
040:                    data.setUsername(command);
041:                    data.setLastAsked("P");
042:                    handler.sendClientMsg("{system.data} Password");
043:                    return null;
044:                }
045:
046:                if (data.getLastAsked().equals("P")) {
047:                    data.setPassword(command.getBytes());
048:                    data.setLastAsked("R");
049:                    handler.sendClientMsg("{system.data} Room");
050:                    return null;
051:                }
052:
053:                if (data.getLastAsked().equals("R")) {
054:                    if (data.registerUsername(data.getUsername()) == false) {
055:                        handler
056:                                .sendClientMsg("{system.error} AuthFailed. Username taken!");
057:                        data.setUsername(null);
058:                        return AuthStatus.FAILURE;
059:                    }
060:
061:                    if (validate(handler, data.getUsername(), data
062:                            .getPassword())) {
063:                        data.setRoom(command);
064:                        handler.sendClientMsg("{system.ok} Auth Ok");
065:                        handler
066:                                .sendClientMsg("{system.msg} Current Chat Room: "
067:                                        + data.getRoom());
068:                        data.setPassword(null);
069:
070:                        ChatMessaging.sendInfoMessage2Room(handler, data
071:                                .getRoom(), "LoggedIn");
072:                        ChatMessaging.printHelp(handler, null);
073:
074:                        return AuthStatus.SUCCESS;
075:                    } else {
076:                        handler.sendClientMsg("{system.error} AuthFailed");
077:                        data.deregisterUsername(data.getUsername());
078:                        data.setPassword(null);
079:                        return AuthStatus.FAILURE;
080:                    }
081:                } else {
082:                    throw new AppException("Unknown LastAsked!");
083:                }
084:            }
085:
086:            /**
087:             * This function is used to validate username and password.
088:             * May be overridden to change username and/or password.
089:             */
090:            protected static boolean validate(ClientHandler handler,
091:                    String username, byte[] password) {
092:                return Arrays.equals(password, username.getBytes());
093:            }
094:
095:            /*
096:            //simpler edition of ChatAuthenticator, that would extend QuickAuthenticator 
097:            public boolean askAuthorisation(ClientHandler handler) 
098:            		throws IOException {		
099:            	String username = askStringInput(handler, "{system.data} Username");
100:            	String password = askStringInput(handler, "{system.data} Password");
101:            	String room = askStringInput(handler, "{system.data} Room");
102:
103:            	//no need to check username or username for null : done by QuickAuthenticator
104:            	
105:            	if(username.equals(password)) {
106:            		ChatData cd = (ChatData)handler.getClientData();
107:            		try {
108:            			cd.setUsername(username);
109:            		} catch(IllegalArgumentException iae) {
110:            			sendString(handler, "{system.error} AuthFailed. "+iae.getMessage());
111:            			return false;
112:            		}
113:            		
114:            		if(room.length()==0) room = "home";
115:
116:            		cd.setRoom(room); //"home"
117:
118:            		sendString(handler, "{system.ok} Auth Ok");
119:            		sendString(handler, "{system.msg} Current Chat Room: "+cd.getRoom());
120:
121:            		ChatMessaging.sendInfoMessage2Room(handler, room, "LoggedIn");
122:
123:            		ChatMessaging.printHelp(handler, null);
124:            		
125:            		return true;
126:            	} else {
127:            		sendString(handler, "{system.error} AuthFailed");
128:            		return false;
129:            	}
130:            }
131:             */
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.