Source Code Cross Referenced for QuickAuthenticator.java in  » Net » QuickServer » org » quickserver » net » server » 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 » org.quickserver.net.server 
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 org.quickserver.net.server;
016:
017:        import java.io.*;
018:        import java.net.SocketTimeoutException;
019:        import org.quickserver.net.AppException;
020:        import org.quickserver.net.ConnectionLostException;
021:        import org.quickserver.util.io.*;
022:
023:        /**
024:         * This class is used to authenticate a client when 
025:         * it connects to QuickServer. Only single instance of this class
026:         * will be used per QuickServer to handle all authentication.
027:         * Should have a default constructor. 
028:         * <p>
029:         * Ex:
030:         * <code><BLOCKQUOTE><pre>
031:         package echoserver;
032:
033:         import org.quickserver.net.server.*;
034:         import java.io.*;
035:
036:         public class EchoServerQuickAuthenticator extends QuickAuthenticator {
037:
038:         public boolean askAuthorisation(ClientHandler clientHandler) 
039:         throws IOException {		
040:         String username = askStringInput(clientHandler, "User Name :");
041:         String password = askStringInput(clientHandler, "Password :");
042:
043:         if(username==null || password ==null)
044:         return false;
045:        
046:         if(username.equals(password)) {
047:         sendString(clientHandler, "Auth OK");
048:         return true;
049:         } else {
050:         sendString(clientHandler, "Auth Failed");
051:         return false;
052:         }
053:         }
054:         }
055:         </pre></BLOCKQUOTE></code></p>
056:         * @author Akshathkumar Shetty
057:         * @since 1.3
058:         */
059:        public abstract class QuickAuthenticator implements  Authenticator {
060:
061:            public abstract boolean askAuthorisation(ClientHandler clientHandler)
062:                    throws IOException, AppException;
063:
064:            /**
065:             * Prints the given message to the client.
066:             * @param msg Message to send.
067:             * If <code>null</code> is passed it will not send any thing.
068:             */
069:            public void sendString(ClientHandler clientHandler, String msg)
070:                    throws IOException {
071:                if (msg != null) {
072:                    if (clientHandler.getDataMode(DataType.OUT) != DataMode.STRING)
073:                        clientHandler
074:                                .setDataMode(DataMode.STRING, DataType.OUT);
075:                    clientHandler.sendClientMsg(msg);
076:                }
077:            }
078:
079:            /**
080:             * Prints the given message to the client and reads a line of input.
081:             * @return the line of input read from the client.
082:             * @param msg Message to send before reading input. If received String is 
083:             * <code>null</code> it will throw {@link ConnectionLostException}.
084:             * If <code>null</code> is passed it will not send any thing.
085:             * @exception IOException if an I/O error occurs
086:             */
087:            public String askStringInput(ClientHandler clientHandler, String msg)
088:                    throws IOException {
089:                if (msg != null) {
090:                    if (clientHandler.getDataMode(DataType.OUT) != DataMode.STRING)
091:                        clientHandler
092:                                .setDataMode(DataMode.STRING, DataType.OUT);
093:                    clientHandler.sendClientMsg(msg);
094:                }
095:                if (clientHandler.getDataMode(DataType.IN) != DataMode.STRING)
096:                    clientHandler.setDataMode(DataMode.STRING, DataType.IN);
097:
098:                String data = null;
099:                if (clientHandler.hasEvent(ClientEvent.RUN_BLOCKING)) {
100:                    data = clientHandler.getBufferedReader().readLine();
101:                } else {
102:                    ByteBufferInputStream bbin = (ByteBufferInputStream) clientHandler
103:                            .getInputStream();
104:                    data = bbin.readLine();
105:                }
106:
107:                if (data != null)
108:                    return data;
109:                else
110:                    throw new ConnectionLostException();
111:            }
112:
113:            /**
114:             * Sends the given object to the client.
115:             * @param msg Message to send.
116:             * If <code>null</code> is passed it will not send any thing.
117:             */
118:            public void sendObject(ClientHandler clientHandler, Object msg)
119:                    throws IOException {
120:                if (msg != null) {
121:                    if (clientHandler.getDataMode(DataType.OUT) != DataMode.OBJECT)
122:                        clientHandler
123:                                .setDataMode(DataMode.OBJECT, DataType.OUT);
124:                    clientHandler.sendClientObject(msg);
125:                }
126:            }
127:
128:            /**
129:             * Prints the given message to the client and reads a Object from input.
130:             * @return the Object from input read from the client. If received Object is 
131:             * <code>null</code> it will throw {@link ConnectionLostException}.
132:             * @param msg Message to send before reading input.
133:             * If <code>null</code> is passed it will not send any thing.
134:             * @exception IOException if an I/O error occurs
135:             */
136:            public Object askObjectInput(ClientHandler clientHandler, Object msg)
137:                    throws IOException, ClassNotFoundException {
138:                if (msg != null) {
139:                    if (clientHandler.getDataMode(DataType.OUT) != DataMode.OBJECT)
140:                        clientHandler
141:                                .setDataMode(DataMode.OBJECT, DataType.OUT);
142:                    clientHandler.sendClientObject(msg);
143:                }
144:                if (clientHandler.getDataMode(DataType.IN) != DataMode.OBJECT)
145:                    clientHandler.setDataMode(DataMode.OBJECT, DataType.IN);
146:                Object data = clientHandler.getObjectInputStream().readObject();
147:                if (data != null)
148:                    return data;
149:                else
150:                    throw new ConnectionLostException();
151:            }
152:
153:            /**
154:             * Prints the given message to the client.
155:             * @param msg Message to send.
156:             * If <code>null</code> is passed it will not send any thing.
157:             * @since 1.3.2
158:             */
159:            public void sendByte(ClientHandler clientHandler, String msg)
160:                    throws IOException {
161:                if (msg != null) {
162:                    if (clientHandler.getDataMode(DataType.OUT) != DataMode.BYTE)
163:                        clientHandler.setDataMode(DataMode.BYTE, DataType.OUT);
164:                    clientHandler.sendClientBytes(msg);
165:                }
166:            }
167:
168:            /**
169:             * Prints the given message to the client and reads a line of input.
170:             * @return the line of input read from the client. If received byte is 
171:             * <code>null</code> it will throw {@link ConnectionLostException}.
172:             * @param msg Message to send before reading input.
173:             * If <code>null</code> is passed it will not send any thing.
174:             * @exception IOException if an I/O error occurs
175:             * @since 1.3.2
176:             */
177:            public String askByteInput(ClientHandler clientHandler, String msg)
178:                    throws IOException {
179:                if (msg != null) {
180:                    if (clientHandler.getDataMode(DataType.OUT) != DataMode.BYTE)
181:                        clientHandler.setDataMode(DataMode.BYTE, DataType.OUT);
182:                    clientHandler.sendClientBytes(msg);
183:                }
184:                if (clientHandler.getDataMode(DataType.IN) != DataMode.BYTE)
185:                    clientHandler.setDataMode(DataMode.BYTE, DataType.IN);
186:                String data = clientHandler.readBytes();
187:                if (data != null)
188:                    return data;
189:                else
190:                    throw new ConnectionLostException();
191:            }
192:
193:            /**
194:             * Sends the given binary data to the client.
195:             * @param msg binary data to send.
196:             * If <code>null</code> is passed it will not send any thing.
197:             * @since 1.4
198:             */
199:            public void sendBinary(ClientHandler clientHandler, byte msg[])
200:                    throws IOException {
201:                if (msg != null) {
202:                    if (clientHandler.getDataMode(DataType.OUT) != DataMode.BINARY)
203:                        clientHandler
204:                                .setDataMode(DataMode.BINARY, DataType.OUT);
205:                    clientHandler.sendClientBinary(msg);
206:                }
207:            }
208:
209:            /**
210:             * Sends the given binary data to the client and reads binary data input.
211:             * @return the binary data input read from the client. If received byte is 
212:             * <code>null</code> it will throw {@link ConnectionLostException}.
213:             * @param msg binary data to send before reading input.
214:             * If <code>null</code> is passed it will not send any thing.
215:             * @exception IOException if an I/O error occurs
216:             * @since 1.4
217:             */
218:            public byte[] askBinaryInput(ClientHandler clientHandler,
219:                    byte msg[]) throws IOException {
220:                if (msg != null) {
221:                    if (clientHandler.getDataMode(DataType.OUT) != DataMode.BINARY)
222:                        clientHandler
223:                                .setDataMode(DataMode.BINARY, DataType.OUT);
224:                    clientHandler.sendClientBinary(msg);
225:                }
226:                if (clientHandler.getDataMode(DataType.IN) != DataMode.BINARY)
227:                    clientHandler.setDataMode(DataMode.BINARY, DataType.IN);
228:                byte[] data = clientHandler.readBinary();
229:                if (data != null)
230:                    return data;
231:                else
232:                    throw new ConnectionLostException();
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.